src/goModules.ts: prompt format tool switch conditionally
Instead of offering multiple prompts at the same time,
trigger the format tool switch prompt only if the user
declines the use of language server.
format tool choice is irrelevant when using the language
server, and multiple prompts are distracting.
Updates golang/vscode-go#192
Change-Id: Ib6cd19ca00ba685ded016524ec8693cb1f07dfa4
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/244542
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/src/goModules.ts b/src/goModules.ts
index 9406850..82077ed 100644
--- a/src/goModules.ts
+++ b/src/goModules.ts
@@ -62,7 +62,6 @@
let goModEnvResult = await runGoModEnv(pkgPath);
if (goModEnvResult) {
- logModuleUsage();
goModEnvResult = path.dirname(goModEnvResult);
const goConfig = getGoConfig(fileuri);
@@ -73,32 +72,23 @@
);
}
- // TODO(rstambler): This will offer multiple prompts to the user, but
- // it's still better than waiting for user input. Ideally, this should
- // be combined into one prompt.
if (goConfig['useLanguageServer'] === false) {
const promptMsg =
'For better performance using Go modules, you can try the experimental Go language server, gopls.';
- promptToUpdateToolForModules('gopls', promptMsg, goConfig);
-
- if (goConfig['formatTool'] === 'goreturns') {
- const promptMsgForFormatTool = `The goreturns tool does not support Go modules. Please update the "formatTool" setting to goimports.`;
- promptToUpdateToolForModules('switchFormatToolToGoimports', promptMsgForFormatTool, goConfig);
- }
+ promptToUpdateToolForModules('gopls', promptMsg, goConfig)
+ .then((choseToUpdate) => {
+ if (choseToUpdate || goConfig['formatTool'] !== 'goreturns') {
+ return;
+ }
+ const promptFormatToolMsg = `The goreturns tool does not support Go modules. Please update the "formatTool" setting to "goimports".`;
+ promptToUpdateToolForModules('switchFormatToolToGoimports', promptFormatToolMsg, goConfig);
+ });
}
}
packagePathToGoModPathMap[pkgPath] = goModEnvResult;
return goModEnvResult;
}
-let moduleUsageLogged = false;
-function logModuleUsage() {
- if (moduleUsageLogged) {
- return;
- }
- moduleUsageLogged = true;
-}
-
const promptedToolsForCurrentSession = new Set<string>();
export async function promptToUpdateToolForModules(
tool: string,