Skip to content

Commit ad4fc9d

Browse files
committed
[release] all: merge master@d04d4cf
d04d4cf README.md: correct tools installation command name 03274ad src/goStatus: present error icon if gopls couldn't be found 465fe7e src/goLanguageServer.ts: prompt to update instead of silent update 607cebe src/welcome: add note about removing go.useLanguageServer setting Change-Id: I43ff57a9698097b9e05e8e705082912cd41ac3d6
2 parents 3c71ee9 + d04d4cf commit ad4fc9d

File tree

5 files changed

+65
-43
lines changed

5 files changed

+65
-43
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ In order to locate these command-line tools, the extension searches
9090
not found, the extension will prompt you to install the missing tools and show
9191
the "⚠️ Analysis Tools Missing" warning in the bottom right corner. Please
9292
install them by responding to the warning notification, or by manually running
93-
the [`Go: Install/Update Go Tools` command].
93+
the [`Go: Install/Update Tools` command].
9494

9595
## Setting up your workspace
9696

@@ -177,6 +177,6 @@ conduct-related issue, please mail [email protected].
177177
[debugging]: #debugging
178178
[full feature breakdown]: https://github.com/golang/vscode-go/blob/master/docs/features.md
179179
[workspace documentation]: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md
180-
[`Go: Install/Update Go Tools` command]: https://github.com/golang/vscode-go/blob/master/docs/commands.md#go-installupdate-tools
180+
[`Go: Install/Update Tools` command]: https://github.com/golang/vscode-go/blob/master/docs/commands.md#go-installupdate-tools
181181
[documentation about supported workspace layouts]: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md
182182
[Workspace Folders]: https://code.visualstudio.com/docs/editor/multi-root-workspaces

src/goInstallTools.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export async function promptForMissingTool(toolName: string) {
303303
}
304304
const msg = `The "${tool.name}" command is not available.
305305
Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
306-
const selected = await vscode.window.showInformationMessage(msg, ...installOptions);
306+
const selected = await vscode.window.showErrorMessage(msg, ...installOptions);
307307
switch (selected) {
308308
case 'Install':
309309
await installTools([tool], goVersion);
@@ -319,7 +319,11 @@ Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
319319
}
320320
}
321321

322-
export async function promptForUpdatingTool(toolName: string, newVersion?: SemVer, crashed?: boolean) {
322+
export async function promptForUpdatingTool(
323+
toolName: string,
324+
newVersion?: SemVer,
325+
crashed?: boolean,
326+
message?: string) {
323327
const tool = getTool(toolName);
324328
const toolVersion = { ...tool, version: newVersion }; // ToolWithVersion
325329

@@ -330,7 +334,9 @@ export async function promptForUpdatingTool(toolName: string, newVersion?: SemVe
330334

331335
// Adjust the prompt if it occurred because the tool crashed.
332336
let updateMsg: string;
333-
if (crashed === true) {
337+
if (message) {
338+
updateMsg = message;
339+
} else if (crashed === true) {
334340
updateMsg = `${tool.name} has crashed, but you are using an outdated version. Please update to the latest version of ${tool.name}.`;
335341
} else if (newVersion) {
336342
updateMsg = `A new version of ${tool.name} (v${newVersion}) is available. Please update for an improved experience.`;
@@ -522,8 +528,8 @@ let suggestedDownloadGo = false;
522528

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

src/goLanguageServer.ts

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ import {
6161
getBinPath,
6262
getCheckForToolsUpdatesConfig,
6363
getCurrentGoPath,
64-
getGoVersion,
6564
getWorkspaceFolderPath,
6665
removeDuplicateDiagnostics
6766
} from './util';
@@ -138,11 +137,7 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
138137
// If the language server is turned on because it is enabled by default,
139138
// make sure that the user is using a new enough version.
140139
if (cfg.enabled && languageServerUsingDefault(goConfig)) {
141-
const updated = await forceUpdateGopls(tool, cfg);
142-
if (updated) {
143-
// restartLanguageServer will be called when the new version of gopls was installed.
144-
return;
145-
}
140+
suggestUpdateGopls(tool, cfg);
146141
}
147142
}
148143
}
@@ -173,7 +168,8 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
173168
// We already created various notification - e.g. missing gopls, ...
174169
// So, just leave a log message here instead of issuing one more notification.
175170
outputChannel.appendLine(
176-
`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();
177173
}
178174
// If the server has been disabled, or failed to start,
179175
// fall back to the default providers, while making sure not to
@@ -184,7 +180,7 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
184180

185181
if (disposable) { disposable.dispose(); }
186182
languageServerIsRunning = started;
187-
updateLanguageServerIconGoStatusBar(started, cfg.serverName);
183+
updateLanguageServerIconGoStatusBar(started, goConfig['useLanguageServer']);
188184
languageServerStartInProgress = false;
189185
});
190186
}
@@ -878,7 +874,7 @@ export async function shouldUpdateLanguageServer(
878874
* configuration.
879875
* @returns true if the tool was updated
880876
*/
881-
async function forceUpdateGopls(
877+
async function suggestUpdateGopls(
882878
tool: Tool,
883879
cfg: LanguageServerConfig,
884880
): Promise<boolean> {
@@ -896,21 +892,11 @@ async function forceUpdateGopls(
896892

897893
if (!latestVersion) {
898894
// The user is using a new enough version
899-
return false;
900-
}
901-
902-
const toolVersion = { ...tool, version: latestVersion }; // ToolWithVersion
903-
const goVersion = await getGoVersion();
904-
const failures = await installTools([toolVersion], goVersion);
905-
906-
// We successfully updated to the latest version.
907-
if (failures.length === 0) {
908-
return true;
895+
return;
909896
}
910897

911-
// Failed to install the new version of gopls, warn the user.
912-
vscode.window.showWarningMessage(`'gopls' is now enabled by default and you are using an old version. Please [update 'gopls'](https://github.com/golang/tools/blob/master/gopls/doc/user.md#installation) and restart the language server for the best experience.`);
913-
return false;
898+
const updateMsg = `'gopls' is now enabled by default and you are using an old version. Please [update 'gopls'](https://github.com/golang/tools/blob/master/gopls/README.md#installation) for the best experience.`;
899+
promptForUpdatingTool(tool.name, latestVersion, false, updateMsg);
914900
}
915901

916902
// Copied from src/cmd/go/internal/modfetch.go.

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
/**

src/welcome.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// https://github.com/microsoft/vscode-extension-samples/tree/master/webview-sample
88

99
import vscode = require('vscode');
10+
import { getGoConfig } from './config';
1011
import { extensionId } from './const';
1112

1213
export class WelcomePanel {
@@ -123,6 +124,14 @@ export class WelcomePanel {
123124
// Use a nonce to only allow specific scripts to be run
124125
const nonce = getNonce();
125126

127+
// Add an extra note if the user has already disabled gopls, asking
128+
// them to enable it.
129+
let alreadyDisabledGopls = '';
130+
if (getGoConfig()?.get('useLanguageServer') === false) {
131+
alreadyDisabledGopls = `If you previously disabled gopls through the "go.useLanguageServer"
132+
setting, we recommend removing that setting now.`;
133+
}
134+
126135
return `<!DOCTYPE html>
127136
<html lang="en">
128137
<head>
@@ -161,7 +170,7 @@ export class WelcomePanel {
161170
Heads up! Gopls, the official Go language server, is now enabled in VS Code by default.
162171
Gopls replaces several legacy tools to provide IDE features while editing Go code.
163172
See <a href="https://github.com/golang/vscode-go/issues/1037">issue 1037</a> for more
164-
information.
173+
information. ${alreadyDisabledGopls}
165174
</p>
166175
</div>
167176

0 commit comments

Comments
 (0)