Skip to content

Commit cc3fbad

Browse files
committed
Send progress-end messages before shutting down
This is required because the IDE does not correctly clean up resources once the language server is shutdown.
1 parent d3def8a commit cc3fbad

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: ls/ls.go

+6
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,13 @@ func (ls *INOLanguageServer) InitializeReqFromIDE(ctx context.Context, logger js
363363
}
364364

365365
func (ls *INOLanguageServer) ShutdownReqFromIDE(ctx context.Context, logger jsonrpc.FunctionLogger) *jsonrpc.ResponseError {
366+
done := make(chan bool)
367+
go func() {
368+
ls.progressHandler.Shutdown()
369+
close(done)
370+
}()
366371
_, _ = ls.Clangd.conn.Shutdown(context.Background())
372+
<-done
367373
return nil
368374
}
369375

Diff for: ls/progress.go

+24
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,27 @@ func (p *ProgressProxyHandler) End(id string, req *lsp.WorkDoneProgressEnd) {
196196
proxy.requiredStatus = progressProxyEnd
197197
p.actionRequiredCond.Broadcast()
198198
}
199+
200+
func (p *ProgressProxyHandler) Shutdown() {
201+
p.mux.Lock()
202+
defer p.mux.Unlock()
203+
204+
for id, proxy := range p.proxies {
205+
err := p.conn.Progress(&lsp.ProgressParams{
206+
Token: lsp.EncodeMessage(id),
207+
Value: lsp.EncodeMessage(&lsp.WorkDoneProgressEnd{
208+
Message: "Shutdown",
209+
}),
210+
})
211+
212+
proxy.endReq = nil
213+
if err != nil {
214+
log.Printf("ProgressHandler: error sending begin req token %s: %v", id, err)
215+
} else {
216+
proxy.currentStatus = progressProxyEnd
217+
proxy.requiredStatus = progressProxyEnd
218+
}
219+
}
220+
221+
p.actionRequiredCond.Broadcast()
222+
}

0 commit comments

Comments
 (0)