From 28821439950f8a37467417151d9a9da4b460e373 Mon Sep 17 00:00:00 2001 From: Hongxiang Jiang Date: Mon, 10 Feb 2025 16:56:26 -0500 Subject: [PATCH] extension/src: skip tool existence check if replaced by gopls When gopls is running, format tools it replaces are ineffective. This change prevents VS Code Go from prompting for their installation when gopls is active. For golang/vscode-go#3677 Change-Id: Ic1fabf0687b6c9b3687dbc59e2099859b90d2250 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/648415 kokoro-CI: kokoro LUCI-TryBot-Result: Go LUCI Reviewed-by: Madeline Kalil --- extension/src/goMain.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extension/src/goMain.ts b/extension/src/goMain.ts index 91a2b45bc8..45f22daf1a 100644 --- a/extension/src/goMain.ts +++ b/extension/src/goMain.ts @@ -75,6 +75,7 @@ import { toggleVulncheckCommandFactory } from './goVulncheck'; import { GoTaskProvider } from './goTaskProvider'; import { setTelemetryEnvVars, telemetryReporter } from './goTelemetry'; import { experiments } from './experimental'; +import { allToolsInformation } from './goToolsInformation'; const goCtx: GoExtensionContext = {}; @@ -300,7 +301,16 @@ function addOnDidChangeConfigListeners(ctx: vscode.ExtensionContext) { } if (e.affectsConfiguration('go.formatTool')) { - checkToolExists(getFormatTool(updatedGoConfig)); + const tool = getFormatTool(updatedGoConfig); + // When language server gopls is active (by default), existence + // checks are skipped only for tools that gopls replaces. Other + // tools are still checked. + if ( + updatedGoConfig['useLanguageServer'] === false || + !new Set(['gofmt', 'goimports', 'goformat']).has(tool) + ) { + checkToolExists(tool); + } } if (e.affectsConfiguration('go.lintTool')) { checkToolExists(updatedGoConfig['lintTool']);