Skip to content

Send progress-end messages before shutting down #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ls/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,13 @@ func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger js
}

func (ls *INOLanguageServer) ShutdownReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger) *jsonrpc.ResponseError {
done := make(chan bool)
go func() {
ls.progressHandler.Shutdown()
close(done)
}()
_, _ = ls.Clangd.conn.Shutdown(context.Background())
<-done
return nil
}

Expand Down
28 changes: 26 additions & 2 deletions ls/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (p *ProgressProxyHandler) handleProxy(id string, proxy *progressProxy) {

proxy.reportReq = nil
if err != nil {
log.Printf("ProgressHandler: error sending begin req token %s: %v", id, err)
log.Printf("ProgressHandler: error sending report req token %s: %v", id, err)
} else {
proxy.requiredStatus = progressProxyBegin
}
Expand All @@ -122,7 +122,7 @@ func (p *ProgressProxyHandler) handleProxy(id string, proxy *progressProxy) {

proxy.endReq = nil
if err != nil {
log.Printf("ProgressHandler: error sending begin req token %s: %v", id, err)
log.Printf("ProgressHandler: error sending end req token %s: %v", id, err)
} else {
proxy.currentStatus = progressProxyEnd
}
Expand Down Expand Up @@ -196,3 +196,27 @@ func (p *ProgressProxyHandler) End(id string, req *lsp.WorkDoneProgressEnd) {
proxy.requiredStatus = progressProxyEnd
p.actionRequiredCond.Broadcast()
}

func (p *ProgressProxyHandler) Shutdown() {
p.mux.Lock()
defer p.mux.Unlock()

for id, proxy := range p.proxies {
err := p.conn.Progress(&lsp.ProgressParams{
Token: lsp.EncodeMessage(id),
Value: lsp.EncodeMessage(&lsp.WorkDoneProgressEnd{
Message: "Shutdown",
}),
})

proxy.endReq = nil
if err != nil {
log.Printf("ProgressHandler: error sending end req token %s: %v", id, err)
} else {
proxy.currentStatus = progressProxyEnd
proxy.requiredStatus = progressProxyEnd
}
}

p.actionRequiredCond.Broadcast()
}