diff --git a/internal/jsonrpc2/serve.go b/internal/jsonrpc2/serve.go index ff9a7a394b..9a7a33c7ba 100644 --- a/internal/jsonrpc2/serve.go +++ b/internal/jsonrpc2/serve.go @@ -8,6 +8,7 @@ import ( "context" "log" "net" + "os" ) // NOTE: This file provides an experimental API for serving multiple remote @@ -47,6 +48,9 @@ func ListenAndServe(ctx context.Context, network, addr string, server StreamServ if err != nil { return err } + if network == "unix" { + defer os.Remove(addr) + } return Serve(ctx, ln, server) } diff --git a/internal/lsp/fake/editor.go b/internal/lsp/fake/editor.go index 9f0224aed5..e248609e9e 100644 --- a/internal/lsp/fake/editor.go +++ b/internal/lsp/fake/editor.go @@ -70,12 +70,19 @@ func NewEditor(ws *Workspace) *Editor { } } -// ShutdownAndExit shuts down the client and issues the editor exit. -func (e *Editor) ShutdownAndExit(ctx context.Context) error { +// Shutdown issues the 'shutdown' LSP notification. +func (e *Editor) Shutdown(ctx context.Context) error { if e.server != nil { if err := e.server.Shutdown(ctx); err != nil { return fmt.Errorf("Shutdown: %v", err) } + } + return nil +} + +// Exit issues the 'exit' LSP notification. +func (e *Editor) Exit(ctx context.Context) error { + if e.server != nil { // Not all LSP clients issue the exit RPC, but we do so here to ensure that // we gracefully handle it on multi-session servers. if err := e.server.Exit(ctx); err != nil { diff --git a/internal/lsp/regtest/env.go b/internal/lsp/regtest/env.go index cb5808618d..b350ee4da3 100644 --- a/internal/lsp/regtest/env.go +++ b/internal/lsp/regtest/env.go @@ -173,6 +173,11 @@ func (r *Runner) RunInMode(modes EnvMode, t *testing.T, filedata string, test fu ts, cleanup := tc.getConnector(ctx, t) defer cleanup() env := NewEnv(ctx, t, ws, ts) + defer func() { + if err := env.E.Shutdown(ctx); err != nil { + panic(err) + } + }() test(ctx, t, env) }) } @@ -326,7 +331,10 @@ func (e *Env) onDiagnostics(_ context.Context, d *protocol.PublishDiagnosticsPar // CloseEditor shuts down the editor, calling t.Fatal on any error. func (e *Env) CloseEditor() { e.t.Helper() - if err := e.E.ShutdownAndExit(e.ctx); err != nil { + if err := e.E.Shutdown(e.ctx); err != nil { + e.t.Fatal(err) + } + if err := e.E.Exit(e.ctx); err != nil { e.t.Fatal(err) } }