Skip to content

Commit 95c38f7

Browse files
committed
restart language server automatically instead of asking user to reload
1 parent 533668b commit 95c38f7

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

src/goInstallTools.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { getLanguageServerToolPath } from './goLanguageServer';
1313
import { envPath, getToolFromToolPath } from './goPath';
1414
import { hideGoStatus, outputChannel, showGoStatus } from './goStatus';
1515
import {
16-
containsString,
1716
containsTool,
1817
disableModulesForWildcard,
1918
getConfiguredTools,
@@ -205,6 +204,10 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
205204
resolve([...sofar, failureReason]);
206205
} else {
207206
outputChannel.appendLine('Installing ' + getImportPath(tool, goVersion) + ' SUCCEEDED');
207+
// If a new version of gopls has been installed, restart the language server.
208+
if (tool.name === 'gopls') {
209+
vscode.commands.executeCommand('go.languageserver.restart');
210+
}
208211
resolve([...sofar, null]);
209212
}
210213
};
@@ -271,9 +274,6 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
271274
outputChannel.appendLine(''); // Blank line for spacing
272275
const failures = res.filter((x) => x != null);
273276
if (failures.length === 0) {
274-
if (containsString(missing, 'go-langserver') || containsString(missing, 'gopls')) {
275-
outputChannel.appendLine('Reload VS Code window to use the Go language server');
276-
}
277277
outputChannel.appendLine('All tools successfully installed. You are ready to Go :).');
278278
return;
279279
}

src/goLanguageServer.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,31 @@ function watchLanguageServerConfiguration(e: vscode.ConfigurationChangeEvent) {
234234
}
235235

236236
const config = parseLanguageServerConfig();
237+
let shouldRestartServer: boolean;
237238
let reloadMessage: string;
238239

239-
// If the user has disabled or enabled the language server.
240+
// If the user enabled the language server, we just need to start it.
240241
if (e.affectsConfiguration('go.useLanguageServer')) {
241242
if (config.enabled) {
242-
reloadMessage = 'Reload VS Code window to enable the use of language server';
243+
shouldRestartServer = true;
243244
} else {
244-
reloadMessage = 'Reload VS Code window to disable the use of language server';
245+
// If the user has disabled the language server, we will need to
246+
// reactivate the extension to register the correct providers,
247+
// so suggest a full VS Code reload.
248+
reloadMessage = 'Reload VS Code window to disable the use of language server.';
245249
}
246250
}
247251

248-
if (
249-
e.affectsConfiguration('go.languageServerFlags') ||
250-
e.affectsConfiguration('go.languageServerExperimentalFeatures')
251-
) {
252-
reloadMessage = 'Reload VS Code window for the changes in language server settings to take effect';
252+
// If the flags to the language server have changed,
253+
// all that's necessary is a server restart.
254+
if (e.affectsConfiguration('go.languageServerFlags')) {
255+
// TODO(rstambler): This should be doable by creating a new client.
256+
reloadMessage = 'Reload VS Code window for changes in the language server flags to take effect.';
257+
}
258+
// If the features provided by the language server have changed,
259+
// the extensions requires a full reactivation.
260+
if (e.affectsConfiguration('go.languageServerExperimentalFeatures')) {
261+
reloadMessage = 'Reload VS Code window for the changes in language server features to take effect.';
253262
}
254263

255264
// If there was a change in the configuration of the language server,
@@ -260,6 +269,8 @@ function watchLanguageServerConfiguration(e: vscode.ConfigurationChangeEvent) {
260269
vscode.commands.executeCommand('workbench.action.reloadWindow');
261270
}
262271
});
272+
} else if (shouldRestartServer) {
273+
vscode.commands.executeCommand('go.languageserver.restart');
263274
}
264275
}
265276

@@ -329,13 +340,12 @@ export function getLanguageServerToolPath(): string {
329340
// Only gopls and go-langserver are supported.
330341
if (languageServerOfChoice !== 'gopls' && languageServerOfChoice !== 'go-langserver') {
331342
vscode.window.showErrorMessage(
332-
`Cannot find the language server ${languageServerOfChoice}. Please install it and reload this VS Code window`
343+
`Cannot find the language server ${languageServerOfChoice}. Please install it.`
333344
);
334345
return;
335346
}
336347
// Otherwise, prompt the user to install the language server.
337348
promptForMissingTool(languageServerOfChoice);
338-
vscode.window.showInformationMessage('Reload VS Code window after installing the Go language server.');
339349
}
340350

341351
function allFoldersHaveSameGopath(): boolean {

src/goModules.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ export async function promptToUpdateToolForModules(
135135
if (goConfig.inspect('useLanguageServer').workspaceFolderValue === false) {
136136
goConfig.update('useLanguageServer', true, vscode.ConfigurationTarget.WorkspaceFolder);
137137
}
138-
const reloadMsg = 'Reload VS Code window to enable the use of Go language server';
139-
vscode.window.showInformationMessage(reloadMsg, 'Reload').then((selectedForReload) => {
140-
if (selectedForReload === 'Reload') {
141-
vscode.commands.executeCommand('workbench.action.reloadWindow');
142-
}
143-
});
144138
}
145139
});
146140
}

0 commit comments

Comments
 (0)