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 <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts
index 97fd0e2..d63334a 100644
--- a/src/goInstallTools.ts
+++ b/src/goInstallTools.ts
@@ -318,7 +318,11 @@
}
}
-export async function promptForUpdatingTool(toolName: string, newVersion?: SemVer, crashed?: boolean) {
+export async function promptForUpdatingTool(
+ toolName: string,
+ newVersion?: SemVer,
+ crashed?: boolean,
+ message?: string) {
const tool = getTool(toolName);
const toolVersion = { ...tool, version: newVersion }; // ToolWithVersion
@@ -329,7 +333,9 @@
// Adjust the prompt if it occurred because the tool crashed.
let updateMsg: string;
- if (crashed === true) {
+ if (message) {
+ updateMsg = message;
+ } else if (crashed === true) {
updateMsg = `${tool.name} has crashed, but you are using an outdated version. Please update to the latest version of ${tool.name}.`;
} else if (newVersion) {
updateMsg = `A new version of ${tool.name} (v${newVersion}) is available. Please update for an improved experience.`;
diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts
index 67dbd33..c2a70a3 100644
--- a/src/goLanguageServer.ts
+++ b/src/goLanguageServer.ts
@@ -61,7 +61,6 @@
getBinPath,
getCheckForToolsUpdatesConfig,
getCurrentGoPath,
- getGoVersion,
getWorkspaceFolderPath,
removeDuplicateDiagnostics
} from './util';
@@ -138,11 +137,7 @@
// If the language server is turned on because it is enabled by default,
// make sure that the user is using a new enough version.
if (cfg.enabled && languageServerUsingDefault(goConfig)) {
- const updated = await forceUpdateGopls(tool, cfg);
- if (updated) {
- // restartLanguageServer will be called when the new version of gopls was installed.
- return;
- }
+ suggestUpdateGopls(tool, cfg);
}
}
}
@@ -878,7 +873,7 @@
* configuration.
* @returns true if the tool was updated
*/
-async function forceUpdateGopls(
+async function suggestUpdateGopls(
tool: Tool,
cfg: LanguageServerConfig,
): Promise<boolean> {
@@ -896,21 +891,11 @@
if (!latestVersion) {
// The user is using a new enough version
- return false;
+ return;
}
- const toolVersion = { ...tool, version: latestVersion }; // ToolWithVersion
- const goVersion = await getGoVersion();
- const failures = await installTools([toolVersion], goVersion);
-
- // We successfully updated to the latest version.
- if (failures.length === 0) {
- return true;
- }
-
- // Failed to install the new version of gopls, warn the user.
- 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.`);
- return false;
+ 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.`;
+ promptForUpdatingTool(tool.name, latestVersion, false, updateMsg);
}
// Copied from src/cmd/go/internal/modfetch.go.