Skip to content

Commit 03274ad

Browse files
committed
src/goStatus: present error icon if gopls couldn't be found
We wanted the missing gopls error notification to be more visible, but for some reason, sometimes it's auto-collapsed and only visible only if user clicks the bell in the right bottom corner. Even though there should be the "Analysis tools missing" error, it may be difficult for users to miss that. Add another icon next to the go version string in the Go status bar item. When the user clicks the Go status bar item, the quickpick menu includes an option to install gopls. We also promoted the missing tool notification to 'error' level - missing tool is an error. Change-Id: Ice121a186f7b23ec94663579087aa737e93df792 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/286672 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 465fe7e commit 03274ad

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

src/goInstallTools.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export async function promptForMissingTool(toolName: string) {
302302
}
303303
const msg = `The "${tool.name}" command is not available.
304304
Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
305-
const selected = await vscode.window.showInformationMessage(msg, ...installOptions);
305+
const selected = await vscode.window.showErrorMessage(msg, ...installOptions);
306306
switch (selected) {
307307
case 'Install':
308308
await installTools([tool], goVersion);
@@ -527,8 +527,8 @@ let suggestedDownloadGo = false;
527527

528528
async function suggestDownloadGo() {
529529
const msg = `Failed to find the "go" binary in either GOROOT(${getCurrentGoRoot()}) or PATH(${envPath}).` +
530-
`Check PATH, or Install Go and reload the window. ` +
531-
`If PATH isn't what you expected, see https://github.com/golang/vscode-go/issues/971`;
530+
`Check PATH, or Install Go and reload the window. ` +
531+
`If PATH isn't what you expected, see https://github.com/golang/vscode-go/issues/971`;
532532
if (suggestedDownloadGo) {
533533
vscode.window.showErrorMessage(msg);
534534
return;

src/goLanguageServer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
168168
// We already created various notification - e.g. missing gopls, ...
169169
// So, just leave a log message here instead of issuing one more notification.
170170
outputChannel.appendLine(
171-
`Failed to start the language server (${cfg.serverName}). Falling back to default language providers...`);
171+
`Failed to start the language server (gopls). Falling back to default language providers...`);
172+
outputChannel.show();
172173
}
173174
// If the server has been disabled, or failed to start,
174175
// fall back to the default providers, while making sure not to
@@ -179,7 +180,7 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
179180

180181
if (disposable) { disposable.dispose(); }
181182
languageServerIsRunning = started;
182-
updateLanguageServerIconGoStatusBar(started, cfg.serverName);
183+
updateLanguageServerIconGoStatusBar(started, goConfig['useLanguageServer']);
183184
languageServerStartInProgress = false;
184185
});
185186
}

src/goStatus.ts

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { formatGoVersion, GoEnvironmentOption, terminalCreationListener } from '
1313
import { buildLanguageServerConfig, getLocalGoplsVersion, languageServerIsRunning, serverOutputChannel } from './goLanguageServer';
1414
import { isGoFile } from './goMode';
1515
import { getModFolderPath, isModSupported } from './goModules';
16+
import { allToolsInformation } from './goTools';
1617
import { getGoVersion } from './util';
1718

1819
export let outputChannel = vscode.window.createOutputChannel('Go');
@@ -24,6 +25,7 @@ export let goEnvStatusbarItem: vscode.StatusBarItem;
2425

2526
let modulePath: string;
2627
export const languageServerIcon = '$(zap)';
28+
export const languageServerErrorIcon = '$(warning)';
2729

2830
export function updateGoStatusBar(editor: vscode.TextEditor) {
2931
// Only update the module path if we are in a Go file.
@@ -47,11 +49,17 @@ export async function expandGoStatusBar() {
4749
];
4850

4951
// Get the gopls configuration
50-
const cfg = buildLanguageServerConfig(getGoConfig());
52+
const goConfig = getGoConfig();
53+
const cfg = buildLanguageServerConfig(goConfig);
5154
if (languageServerIsRunning && cfg.serverName === 'gopls') {
5255
const goplsVersion = await getLocalGoplsVersion(cfg);
5356
options.push({label: `${languageServerIcon}Open 'gopls' trace`, description: `${goplsVersion}`});
5457
}
58+
if (!languageServerIsRunning && !cfg.serverName && goConfig['useLanguageServer']) {
59+
options.push({
60+
label: `Install Go Language Server`,
61+
description: `${languageServerErrorIcon}'gopls' is required but missing`});
62+
}
5563

5664
// If modules is enabled, add link to mod file
5765
if (!!modulePath) {
@@ -72,6 +80,9 @@ export async function expandGoStatusBar() {
7280
serverOutputChannel.show();
7381
}
7482
break;
83+
case `Install Go Language Server`:
84+
vscode.commands.executeCommand('go.tools.install', [allToolsInformation['gopls']]);
85+
break;
7586
case `Open 'go.mod'`:
7687
const openPath = vscode.Uri.file(item.description);
7788
vscode.workspace.openTextDocument(openPath).then((doc) => {
@@ -101,27 +112,37 @@ export async function initGoStatusBar() {
101112
// Add an icon to indicate that the 'gopls' server is running.
102113
// Assume if it is configured it is already running, since the
103114
// icon will be updated on an attempt to start.
104-
const cfg = buildLanguageServerConfig(getGoConfig());
105-
updateLanguageServerIconGoStatusBar(languageServerIsRunning, cfg.serverName);
115+
const goConfig = getGoConfig();
116+
const cfg = buildLanguageServerConfig(goConfig);
117+
updateLanguageServerIconGoStatusBar(languageServerIsRunning, goConfig['useLanguageServer']);
106118

107119
showGoStatusBar();
108120
}
109121

110-
export async function updateLanguageServerIconGoStatusBar(started: boolean, server: string) {
122+
export function updateLanguageServerIconGoStatusBar(started: boolean, enabled: boolean) {
111123
if (!goEnvStatusbarItem) {
112124
return;
113125
}
114126

115-
const text = goEnvStatusbarItem.text;
116-
if (started && server === 'gopls') {
117-
if (!text.endsWith(languageServerIcon)) {
118-
goEnvStatusbarItem.text = text + languageServerIcon;
119-
}
120-
} else {
121-
if (text.endsWith(languageServerIcon)) {
122-
goEnvStatusbarItem.text = text.substring(0, text.length - languageServerIcon.length);
123-
}
127+
// Split the existing goEnvStatusbarItem.text into the version string part and
128+
// the gopls icon part.
129+
let text = goEnvStatusbarItem.text;
130+
let icon = '';
131+
if (text.endsWith(languageServerIcon)) {
132+
icon = languageServerIcon;
133+
text = text.substring(0, text.length - languageServerIcon.length);
134+
} else if (text.endsWith(languageServerErrorIcon)) {
135+
icon = languageServerErrorIcon;
136+
text = text.substring(0, text.length - languageServerErrorIcon.length);
124137
}
138+
139+
if (started && enabled) {
140+
icon = languageServerIcon;
141+
} else if (!started && enabled) {
142+
icon = languageServerErrorIcon;
143+
}
144+
145+
goEnvStatusbarItem.text = text + icon;
125146
}
126147

127148
/**

0 commit comments

Comments
 (0)