diff --git a/package.json b/package.json index 72d54b319..d1ab56286 100644 --- a/package.json +++ b/package.json @@ -300,6 +300,11 @@ "command": "go.godoctor.var", "title": "Go: Extract to variable", "description": "Extract to variable using godoctor." + }, + { + "command": "go.languageserver.restart", + "title": "Go: Restart Language Server", + "description": "Restart the running instance of the language server" } ], "debuggers": [ diff --git a/src/goMain.ts b/src/goMain.ts index cb2f578ab..e322bce7e 100644 --- a/src/goMain.ts +++ b/src/goMain.ts @@ -287,7 +287,15 @@ export function activate(ctx: vscode.ExtensionContext): void { }); - ctx.subscriptions.push(c.start()); + let languageServerDisposable = c.start(); + ctx.subscriptions.push(languageServerDisposable); + + ctx.subscriptions.push(vscode.commands.registerCommand('go.languageserver.restart', async () => { + await c.stop(); + languageServerDisposable.dispose(); + languageServerDisposable = c.start(); + ctx.subscriptions.push(languageServerDisposable); + })); if (languageServerTool !== 'gopls' || !languageServerExperimentalFeatures['diagnostics']) { vscode.workspace.onDidChangeTextDocument(parseLiveFile, null, ctx.subscriptions);