Skip to content

Commit

Permalink
[release] all: merge master@d04d4cf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hyangah committed Jan 26, 2021
2 parents 3c71ee9 + d04d4cf commit ad4fc9d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ In order to locate these command-line tools, the extension searches
not found, the extension will prompt you to install the missing tools and show
the "⚠️ Analysis Tools Missing" warning in the bottom right corner. Please
install them by responding to the warning notification, or by manually running
the [`Go: Install/Update Go Tools` command].
the [`Go: Install/Update Tools` command].

## Setting up your workspace

Expand Down Expand Up @@ -177,6 +177,6 @@ conduct-related issue, please mail [email protected].
[debugging]: #debugging
[full feature breakdown]: https://github.com/golang/vscode-go/blob/master/docs/features.md
[workspace documentation]: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md
[`Go: Install/Update Go Tools` command]: https://github.com/golang/vscode-go/blob/master/docs/commands.md#go-installupdate-tools
[`Go: Install/Update Tools` command]: https://github.com/golang/vscode-go/blob/master/docs/commands.md#go-installupdate-tools
[documentation about supported workspace layouts]: https://github.com/golang/tools/blob/master/gopls/doc/workspace.md
[Workspace Folders]: https://code.visualstudio.com/docs/editor/multi-root-workspaces
16 changes: 11 additions & 5 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export async function promptForMissingTool(toolName: string) {
}
const msg = `The "${tool.name}" command is not available.
Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
const selected = await vscode.window.showInformationMessage(msg, ...installOptions);
const selected = await vscode.window.showErrorMessage(msg, ...installOptions);
switch (selected) {
case 'Install':
await installTools([tool], goVersion);
Expand All @@ -319,7 +319,11 @@ Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
}
}

export async function promptForUpdatingTool(toolName: string, newVersion?: SemVer, crashed?: boolean) {
export async function promptForUpdatingTool(
toolName: string,
newVersion?: SemVer,
crashed?: boolean,
message?: string) {
const tool = getTool(toolName);
const toolVersion = { ...tool, version: newVersion }; // ToolWithVersion

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

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

async function suggestDownloadGo() {
const msg = `Failed to find the "go" binary in either GOROOT(${getCurrentGoRoot()}) or PATH(${envPath}).` +
`Check PATH, or Install Go and reload the window. ` +
`If PATH isn't what you expected, see https://github.com/golang/vscode-go/issues/971`;
`Check PATH, or Install Go and reload the window. ` +
`If PATH isn't what you expected, see https://github.com/golang/vscode-go/issues/971`;
if (suggestedDownloadGo) {
vscode.window.showErrorMessage(msg);
return;
Expand Down
30 changes: 8 additions & 22 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
getBinPath,
getCheckForToolsUpdatesConfig,
getCurrentGoPath,
getGoVersion,
getWorkspaceFolderPath,
removeDuplicateDiagnostics
} from './util';
Expand Down Expand Up @@ -138,11 +137,7 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
// If the language server is turned on because it is enabled by default,
// make sure that the user is using a new enough version.
if (cfg.enabled && languageServerUsingDefault(goConfig)) {
const updated = await forceUpdateGopls(tool, cfg);
if (updated) {
// restartLanguageServer will be called when the new version of gopls was installed.
return;
}
suggestUpdateGopls(tool, cfg);
}
}
}
Expand Down Expand Up @@ -173,7 +168,8 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte
// We already created various notification - e.g. missing gopls, ...
// So, just leave a log message here instead of issuing one more notification.
outputChannel.appendLine(
`Failed to start the language server (${cfg.serverName}). Falling back to default language providers...`);
`Failed to start the language server (gopls). Falling back to default language providers...`);
outputChannel.show();
}
// If the server has been disabled, or failed to start,
// fall back to the default providers, while making sure not to
Expand All @@ -184,7 +180,7 @@ export async function startLanguageServerWithFallback(ctx: vscode.ExtensionConte

if (disposable) { disposable.dispose(); }
languageServerIsRunning = started;
updateLanguageServerIconGoStatusBar(started, cfg.serverName);
updateLanguageServerIconGoStatusBar(started, goConfig['useLanguageServer']);
languageServerStartInProgress = false;
});
}
Expand Down Expand Up @@ -878,7 +874,7 @@ export async function shouldUpdateLanguageServer(
* configuration.
* @returns true if the tool was updated
*/
async function forceUpdateGopls(
async function suggestUpdateGopls(
tool: Tool,
cfg: LanguageServerConfig,
): Promise<boolean> {
Expand All @@ -896,21 +892,11 @@ async function forceUpdateGopls(

if (!latestVersion) {
// The user is using a new enough version
return false;
}

const toolVersion = { ...tool, version: latestVersion }; // ToolWithVersion
const goVersion = await getGoVersion();
const failures = await installTools([toolVersion], goVersion);

// We successfully updated to the latest version.
if (failures.length === 0) {
return true;
return;
}

// Failed to install the new version of gopls, warn the user.
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.`);
return false;
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.`;
promptForUpdatingTool(tool.name, latestVersion, false, updateMsg);
}

// Copied from src/cmd/go/internal/modfetch.go.
Expand Down
47 changes: 34 additions & 13 deletions src/goStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { formatGoVersion, GoEnvironmentOption, terminalCreationListener } from '
import { buildLanguageServerConfig, getLocalGoplsVersion, languageServerIsRunning, serverOutputChannel } from './goLanguageServer';
import { isGoFile } from './goMode';
import { getModFolderPath, isModSupported } from './goModules';
import { allToolsInformation } from './goTools';
import { getGoVersion } from './util';

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

let modulePath: string;
export const languageServerIcon = '$(zap)';
export const languageServerErrorIcon = '$(warning)';

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

// Get the gopls configuration
const cfg = buildLanguageServerConfig(getGoConfig());
const goConfig = getGoConfig();
const cfg = buildLanguageServerConfig(goConfig);
if (languageServerIsRunning && cfg.serverName === 'gopls') {
const goplsVersion = await getLocalGoplsVersion(cfg);
options.push({label: `${languageServerIcon}Open 'gopls' trace`, description: `${goplsVersion}`});
}
if (!languageServerIsRunning && !cfg.serverName && goConfig['useLanguageServer']) {
options.push({
label: `Install Go Language Server`,
description: `${languageServerErrorIcon}'gopls' is required but missing`});
}

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

showGoStatusBar();
}

export async function updateLanguageServerIconGoStatusBar(started: boolean, server: string) {
export function updateLanguageServerIconGoStatusBar(started: boolean, enabled: boolean) {
if (!goEnvStatusbarItem) {
return;
}

const text = goEnvStatusbarItem.text;
if (started && server === 'gopls') {
if (!text.endsWith(languageServerIcon)) {
goEnvStatusbarItem.text = text + languageServerIcon;
}
} else {
if (text.endsWith(languageServerIcon)) {
goEnvStatusbarItem.text = text.substring(0, text.length - languageServerIcon.length);
}
// Split the existing goEnvStatusbarItem.text into the version string part and
// the gopls icon part.
let text = goEnvStatusbarItem.text;
let icon = '';
if (text.endsWith(languageServerIcon)) {
icon = languageServerIcon;
text = text.substring(0, text.length - languageServerIcon.length);
} else if (text.endsWith(languageServerErrorIcon)) {
icon = languageServerErrorIcon;
text = text.substring(0, text.length - languageServerErrorIcon.length);
}

if (started && enabled) {
icon = languageServerIcon;
} else if (!started && enabled) {
icon = languageServerErrorIcon;
}

goEnvStatusbarItem.text = text + icon;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion src/welcome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// https://github.com/microsoft/vscode-extension-samples/tree/master/webview-sample

import vscode = require('vscode');
import { getGoConfig } from './config';
import { extensionId } from './const';

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

// Add an extra note if the user has already disabled gopls, asking
// them to enable it.
let alreadyDisabledGopls = '';
if (getGoConfig()?.get('useLanguageServer') === false) {
alreadyDisabledGopls = `If you previously disabled gopls through the "go.useLanguageServer"
setting, we recommend removing that setting now.`;
}

return `<!DOCTYPE html>
<html lang="en">
<head>
Expand Down Expand Up @@ -161,7 +170,7 @@ export class WelcomePanel {
Heads up! Gopls, the official Go language server, is now enabled in VS Code by default.
Gopls replaces several legacy tools to provide IDE features while editing Go code.
See <a href="https://github.com/golang/vscode-go/issues/1037">issue 1037</a> for more
information.
information. ${alreadyDisabledGopls}
</p>
</div>
Expand Down

0 comments on commit ad4fc9d

Please sign in to comment.