Skip to content

Commit

Permalink
restart language server automatically instead of asking user to reload
Browse files Browse the repository at this point in the history
  • Loading branch information
stamblerre committed Jan 29, 2020
1 parent 533668b commit 95c38f7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getLanguageServerToolPath } from './goLanguageServer';
import { envPath, getToolFromToolPath } from './goPath';
import { hideGoStatus, outputChannel, showGoStatus } from './goStatus';
import {
containsString,
containsTool,
disableModulesForWildcard,
getConfiguredTools,
Expand Down Expand Up @@ -205,6 +204,10 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
resolve([...sofar, failureReason]);
} else {
outputChannel.appendLine('Installing ' + getImportPath(tool, goVersion) + ' SUCCEEDED');
// If a new version of gopls has been installed, restart the language server.
if (tool.name === 'gopls') {
vscode.commands.executeCommand('go.languageserver.restart');
}
resolve([...sofar, null]);
}
};
Expand Down Expand Up @@ -271,9 +274,6 @@ export function installTools(missing: Tool[], goVersion: GoVersion): Promise<voi
outputChannel.appendLine(''); // Blank line for spacing
const failures = res.filter((x) => 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;
}
Expand Down
30 changes: 20 additions & 10 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -260,6 +269,8 @@ function watchLanguageServerConfiguration(e: vscode.ConfigurationChangeEvent) {
vscode.commands.executeCommand('workbench.action.reloadWindow');
}
});
} else if (shouldRestartServer) {
vscode.commands.executeCommand('go.languageserver.restart');
}
}

Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions src/goModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
}
});
}
Expand Down

0 comments on commit 95c38f7

Please sign in to comment.