Skip to content

Commit 465fe7e

Browse files
committed
src/goLanguageServer.ts: prompt to update instead of silent update
Prompt users before installing gopls. Change-Id: I58cc39f424dd71d84844fb0a69c43634f2690600 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/286532 Trust: Suzy Mueller <[email protected]> Run-TryBot: Suzy Mueller <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 607cebe commit 465fe7e

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/goInstallTools.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,11 @@ Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
318318
}
319319
}
320320

321-
export async function promptForUpdatingTool(toolName: string, newVersion?: SemVer, crashed?: boolean) {
321+
export async function promptForUpdatingTool(
322+
toolName: string,
323+
newVersion?: SemVer,
324+
crashed?: boolean,
325+
message?: string) {
322326
const tool = getTool(toolName);
323327
const toolVersion = { ...tool, version: newVersion }; // ToolWithVersion
324328

@@ -329,7 +333,9 @@ export async function promptForUpdatingTool(toolName: string, newVersion?: SemVe
329333

330334
// Adjust the prompt if it occurred because the tool crashed.
331335
let updateMsg: string;
332-
if (crashed === true) {
336+
if (message) {
337+
updateMsg = message;
338+
} else if (crashed === true) {
333339
updateMsg = `${tool.name} has crashed, but you are using an outdated version. Please update to the latest version of ${tool.name}.`;
334340
} else if (newVersion) {
335341
updateMsg = `A new version of ${tool.name} (v${newVersion}) is available. Please update for an improved experience.`;

src/goLanguageServer.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import {
6161
getBinPath,
6262
getCheckForToolsUpdatesConfig,
6363
getCurrentGoPath,
64-
getGoVersion,
6564
getWorkspaceFolderPath,
6665
removeDuplicateDiagnostics
6766
} from './util';
@@ -138,11 +137,7 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
138137
// If the language server is turned on because it is enabled by default,
139138
// make sure that the user is using a new enough version.
140139
if (cfg.enabled && languageServerUsingDefault(goConfig)) {
141-
const updated = await forceUpdateGopls(tool, cfg);
142-
if (updated) {
143-
// restartLanguageServer will be called when the new version of gopls was installed.
144-
return;
145-
}
140+
suggestUpdateGopls(tool, cfg);
146141
}
147142
}
148143
}
@@ -878,7 +873,7 @@ export async function shouldUpdateLanguageServer(
878873
* configuration.
879874
* @returns true if the tool was updated
880875
*/
881-
async function forceUpdateGopls(
876+
async function suggestUpdateGopls(
882877
tool: Tool,
883878
cfg: LanguageServerConfig,
884879
): Promise<boolean> {
@@ -896,21 +891,11 @@ async function forceUpdateGopls(
896891

897892
if (!latestVersion) {
898893
// The user is using a new enough version
899-
return false;
900-
}
901-
902-
const toolVersion = { ...tool, version: latestVersion }; // ToolWithVersion
903-
const goVersion = await getGoVersion();
904-
const failures = await installTools([toolVersion], goVersion);
905-
906-
// We successfully updated to the latest version.
907-
if (failures.length === 0) {
908-
return true;
894+
return;
909895
}
910896

911-
// Failed to install the new version of gopls, warn the user.
912-
vscode.window.showWarningMessage(`'gopls' is now enabled by default and you are using an old version. Please [update 'gopls'](https://github.com/golang/tools/blob/master/gopls/doc/user.md#installation) and restart the language server for the best experience.`);
913-
return false;
897+
const updateMsg = `'gopls' is now enabled by default and you are using an old version. Please [update 'gopls'](https://github.com/golang/tools/blob/master/gopls/README.md#installation) for the best experience.`;
898+
promptForUpdatingTool(tool.name, latestVersion, false, updateMsg);
914899
}
915900

916901
// Copied from src/cmd/go/internal/modfetch.go.

0 commit comments

Comments
 (0)