From 95c38f754dfbbb687aa461abe3598aac4389356b Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Tue, 28 Jan 2020 23:12:38 -0500 Subject: [PATCH] restart language server automatically instead of asking user to reload --- src/goInstallTools.ts | 8 ++++---- src/goLanguageServer.ts | 30 ++++++++++++++++++++---------- src/goModules.ts | 6 ------ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index 93b42e9a17..48a660a901 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -13,7 +13,6 @@ import { getLanguageServerToolPath } from './goLanguageServer'; import { envPath, getToolFromToolPath } from './goPath'; import { hideGoStatus, outputChannel, showGoStatus } from './goStatus'; import { - containsString, containsTool, disableModulesForWildcard, getConfiguredTools, @@ -205,6 +204,10 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise x != null); if (failures.length === 0) { - if (containsString(missing, 'go-langserver') || containsString(missing, 'gopls')) { - outputChannel.appendLine('Reload VS Code window to use the Go language server'); - } outputChannel.appendLine('All tools successfully installed. You are ready to Go :).'); return; } diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts index e7e7b4530a..a8a15bdf12 100644 --- a/src/goLanguageServer.ts +++ b/src/goLanguageServer.ts @@ -234,22 +234,31 @@ function watchLanguageServerConfiguration(e: vscode.ConfigurationChangeEvent) { } const config = parseLanguageServerConfig(); + let shouldRestartServer: boolean; let reloadMessage: string; - // If the user has disabled or enabled the language server. + // If the user enabled the language server, we just need to start it. if (e.affectsConfiguration('go.useLanguageServer')) { if (config.enabled) { - reloadMessage = 'Reload VS Code window to enable the use of language server'; + shouldRestartServer = true; } else { - reloadMessage = 'Reload VS Code window to disable the use of language server'; + // If the user has disabled the language server, we will need to + // reactivate the extension to register the correct providers, + // so suggest a full VS Code reload. + reloadMessage = 'Reload VS Code window to disable the use of language server.'; } } - if ( - e.affectsConfiguration('go.languageServerFlags') || - e.affectsConfiguration('go.languageServerExperimentalFeatures') - ) { - reloadMessage = 'Reload VS Code window for the changes in language server settings to take effect'; + // If the flags to the language server have changed, + // all that's necessary is a server restart. + if (e.affectsConfiguration('go.languageServerFlags')) { + // TODO(rstambler): This should be doable by creating a new client. + reloadMessage = 'Reload VS Code window for changes in the language server flags to take effect.'; + } + // If the features provided by the language server have changed, + // the extensions requires a full reactivation. + if (e.affectsConfiguration('go.languageServerExperimentalFeatures')) { + reloadMessage = 'Reload VS Code window for the changes in language server features to take effect.'; } // If there was a change in the configuration of the language server, @@ -260,6 +269,8 @@ function watchLanguageServerConfiguration(e: vscode.ConfigurationChangeEvent) { vscode.commands.executeCommand('workbench.action.reloadWindow'); } }); + } else if (shouldRestartServer) { + vscode.commands.executeCommand('go.languageserver.restart'); } } @@ -329,13 +340,12 @@ export function getLanguageServerToolPath(): string { // Only gopls and go-langserver are supported. if (languageServerOfChoice !== 'gopls' && languageServerOfChoice !== 'go-langserver') { vscode.window.showErrorMessage( - `Cannot find the language server ${languageServerOfChoice}. Please install it and reload this VS Code window` + `Cannot find the language server ${languageServerOfChoice}. Please install it.` ); return; } // Otherwise, prompt the user to install the language server. promptForMissingTool(languageServerOfChoice); - vscode.window.showInformationMessage('Reload VS Code window after installing the Go language server.'); } function allFoldersHaveSameGopath(): boolean { diff --git a/src/goModules.ts b/src/goModules.ts index d50e75a10f..163dfacc50 100644 --- a/src/goModules.ts +++ b/src/goModules.ts @@ -135,12 +135,6 @@ export async function promptToUpdateToolForModules( if (goConfig.inspect('useLanguageServer').workspaceFolderValue === false) { goConfig.update('useLanguageServer', true, vscode.ConfigurationTarget.WorkspaceFolder); } - const reloadMsg = 'Reload VS Code window to enable the use of Go language server'; - vscode.window.showInformationMessage(reloadMsg, 'Reload').then((selectedForReload) => { - if (selectedForReload === 'Reload') { - vscode.commands.executeCommand('workbench.action.reloadWindow'); - } - }); } }); }