From c15d43f83c60ee510117bcef717b6f6ae93bbe05 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Mon, 20 Apr 2020 15:26:07 -0400 Subject: [PATCH] src/goLanguageServer: fix missing gopls detection logic Also, update getMissingTools to check the tool's existence by simply checking whether the resolved tool path is absolute. getBinPath already ran the existence check before returning the absolute path for the tool. Fixes microsoft/vscode-go#3194 --- src/goInstallTools.ts | 5 ++--- src/goLanguageServer.ts | 5 ++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index bcec6e539..8302377a2 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -346,6 +346,7 @@ export async function promptForMissingTool(toolName: string) { const installOptions = ['Install']; let missing = await getMissingTools(goVersion); if (!containsTool(missing, tool)) { + console.log(`not containsTool ${missing}, ${tool}, ${goVersion}`); return; } missing = missing.filter((x) => x === tool || tool.isImportant); @@ -544,9 +545,7 @@ function getMissingTools(goVersion: GoVersion): Promise { (tool) => new Promise((resolve, reject) => { const toolPath = getBinPath(tool.name); - fs.exists(toolPath, (exists) => { - resolve(exists ? null : tool); - }); + resolve(path.isAbsolute(toolPath) ? null : tool); }) ) ).then((res) => { diff --git a/src/goLanguageServer.ts b/src/goLanguageServer.ts index 37764a69b..a8a25dfbf 100644 --- a/src/goLanguageServer.ts +++ b/src/goLanguageServer.ts @@ -284,6 +284,7 @@ export function getLanguageServerToolPath(): string { } const alternateTools = goConfig['alternateTools']; if (alternateTools) { + console.log('alternateTools ' + JSON.stringify(alternateTools, null, 2)); // The user's alternate language server was not found. const goplsAlternate = alternateTools['gopls']; if (goplsAlternate) { @@ -298,9 +299,11 @@ Please install it and reload this VS Code window.` if (alternateTools['go-langserver']) { vscode.window.showErrorMessage(`Support for "go-langserver" has been deprecated. The recommended language server is gopls. Delete the alternate tool setting for "go-langserver" to use gopls, or change "go-langserver" to "gopls" in your settings.json and reload the VS Code window.`); + return; } - return; } + + console.log('promptForMissingTools(gopls)'); // Prompt the user to install gopls. promptForMissingTool('gopls'); }