Skip to content

Commit

Permalink
src/goInstallTools: handle unknown tools
Browse files Browse the repository at this point in the history
For example, when the extension detects that the specified custom formatting
tool does not exist, it will attempt to install or prompt the user for installing
the missing tool. However, it's likely the tool is not known to our extension,
so getTool won't be able to return a valid Tool. Handle this case by checking
the return value of getTool.

I expect there are still many corner cases and UX bugs in handling custom
formatter errors. But, assuming use of custom formatters is rare, polishing
the custom formatter UX is a low priority.

For #1238

Change-Id: If6deedf9285c6d070ad4d960f78c5430be54afd5
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/446299
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
  • Loading branch information
hyangah committed Nov 10, 2022
1 parent 8f81613 commit 28f7c07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,12 @@ export function declinedToolInstall(toolName: string) {

export async function promptForMissingTool(toolName: string) {
const tool = getTool(toolName);
if (!tool) {
vscode.window.showWarningMessage(
`${toolName} is not found. Please make sure it is installed and available in the PATH ${envPath}`
);
return;
}

// If user has declined to install this tool, don't prompt for it.
if (declinedToolInstall(toolName)) {
Expand Down Expand Up @@ -444,6 +450,9 @@ export async function promptForUpdatingTool(
message?: string
) {
const tool = getTool(toolName);
if (!tool) {
return; // not a tool known to us.
}
const toolVersion = { ...tool, version: newVersion }; // ToolWithVersion

// If user has declined to update, then don't prompt.
Expand Down Expand Up @@ -737,9 +746,9 @@ async function defaultInspectGoToolVersion(
dep github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
if the binary was built with a dev version of go, in module mode.
/Users/hakim/go/bin/gopls: devel go1.18-41f485b9a7 Mon Jan 31 13:43:52 2022 +0000
/Users/hakim/go/bin/gopls: devel go1.18-41f485b9a7 Mon Jan 31 13:43:52 2022 +0000
path golang.org/x/tools/gopls
mod golang.org/x/tools/gopls v0.8.0-pre.1 h1:6iHi9bCJ8XndQtBEFFG/DX+eTJrf2lKFv4GI3zLeDOo=
mod golang.org/x/tools/gopls v0.8.0-pre.1 h1:6iHi9bCJ8XndQtBEFFG/DX+eTJrf2lKFv4GI3zLeDOo=
...
*/
const lines = stdout.split('\n', 3);
Expand Down
4 changes: 2 additions & 2 deletions src/goTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ export function getConfiguredTools(
break;
}

// Only add format tools if the language server is disabled and the
// Only add format tools if the language server is disabled or the
// format tool is known to us.
if (goConfig['useLanguageServer'] === false && !usingCustomFormatTool(goConfig)) {
if (goConfig['useLanguageServer'] === false || usingCustomFormatTool(goConfig)) {
maybeAddTool(getFormatTool(goConfig));
}

Expand Down

0 comments on commit 28f7c07

Please sign in to comment.