Skip to content

Commit 99f2a10

Browse files
stamblerrehyangah
authored andcommitted
[release] src/goLanguageServer: suggest updating gopls before filing an issue
We're getting a lot of crash issue reports with people using outdated gopls versions. We can just suggest an update to them instead of filing an issue. Also, update the hardcoded latest gopls version and clean up the installing message which used to print "[email protected]@0.5.3". Some formatting changes seem to have snuck in--I have format on save set for TypeScript with the TSLint extension. Should I change something? Change-Id: I3aca9e47f42e1e9951b1f6ad99944e36afac766f Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/272209 Trust: Rebecca Stambler <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> (cherry picked from commit dd08b76) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/272966 Trust: Robert Findley <[email protected]>
1 parent bad9dbb commit 99f2a10

File tree

2 files changed

+41
-25
lines changed

2 files changed

+41
-25
lines changed

src/goInstallTools.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,6 @@ export async function installTool(
226226
}
227227
args.push(importPath);
228228

229-
const toolImportPath = tool.version ? importPath + '@' + tool.version : importPath;
230-
231229
let output: string;
232230
let result: string = '';
233231
try {
@@ -253,10 +251,10 @@ export async function installTool(
253251
await execFile(goBinary, ['build', '-o', outputFile, importPath], opts);
254252
}
255253
const toolInstallPath = getBinPath(tool.name);
256-
outputChannel.appendLine(`Installing ${toolImportPath} (${toolInstallPath}) SUCCEEDED`);
254+
outputChannel.appendLine(`Installing ${importPath} (${toolInstallPath}) SUCCEEDED`);
257255
} catch (e) {
258-
outputChannel.appendLine(`Installing ${toolImportPath} FAILED`);
259-
result = `failed to install ${tool.name}(${toolImportPath}): ${e} ${output} `;
256+
outputChannel.appendLine(`Installing ${importPath} FAILED`);
257+
result = `failed to install ${tool.name}(${importPath}): ${e} ${output} `;
260258
}
261259

262260
// Delete the temporary installation directory.
@@ -316,29 +314,36 @@ Run "go get -v ${getImportPath(tool, goVersion)}" to install.`;
316314
}
317315
}
318316

319-
export async function promptForUpdatingTool(toolName: string, newVersion?: SemVer) {
317+
export async function promptForUpdatingTool(toolName: string, newVersion?: SemVer, crashed?: boolean) {
320318
const tool = getTool(toolName);
321319
const toolVersion = { ...tool, version: newVersion }; // ToolWithVersion
322320

323321
// If user has declined to update, then don't prompt.
324322
if (containsTool(declinedUpdates, tool)) {
325323
return;
326324
}
327-
const goVersion = await getGoVersion();
328-
let updateMsg = `Your version of ${tool.name} appears to be out of date. Please update for an improved experience.`;
325+
326+
// Adjust the prompt if it occurred because the tool crashed.
327+
let updateMsg: string;
328+
if (crashed === true) {
329+
updateMsg = `${tool.name} has crashed, but you are using an outdated version. Please update to the latest version of ${tool.name}.`;
330+
} else if (newVersion) {
331+
updateMsg = `A new version of ${tool.name} (v${newVersion}) is available. Please update for an improved experience.`;
332+
} else {
333+
updateMsg = `Your version of ${tool.name} appears to be out of date. Please update for an improved experience.`;
334+
}
335+
329336
let choices: string[] = ['Update'];
330337
if (toolName === `gopls`) {
331338
choices.push('Release Notes');
332339
}
333-
if (newVersion) {
334-
updateMsg = `A new version of ${tool.name} (v${newVersion}) is available. Please update for an improved experience.`;
335-
}
336340

337341
while (choices.length > 0) {
338342
const selected = await vscode.window.showInformationMessage(updateMsg, ...choices);
339343
switch (selected) {
340344
case 'Update':
341345
choices = [];
346+
const goVersion = await getGoVersion();
342347
await installTools([toolVersion], goVersion);
343348
break;
344349
case 'Release Notes':

src/goLanguageServer.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,19 +215,19 @@ export interface BuildLanguageClientOption extends LanguageServerConfig {
215215
// used in building a new LanguageClient instance. Options specified
216216
// in LanguageServerConfig
217217
function buildLanguageClientOption(cfg: LanguageServerConfig): BuildLanguageClientOption {
218-
// Reuse the same output channel for each instance of the server.
219-
if (cfg.enabled) {
220-
if (!serverOutputChannel) {
221-
serverOutputChannel = vscode.window.createOutputChannel(cfg.serverName + ' (server)');
222-
}
223-
if (!serverTraceChannel) {
224-
serverTraceChannel = vscode.window.createOutputChannel(cfg.serverName);
225-
}
218+
// Reuse the same output channel for each instance of the server.
219+
if (cfg.enabled) {
220+
if (!serverOutputChannel) {
221+
serverOutputChannel = vscode.window.createOutputChannel(cfg.serverName + ' (server)');
222+
}
223+
if (!serverTraceChannel) {
224+
serverTraceChannel = vscode.window.createOutputChannel(cfg.serverName);
226225
}
227-
return Object.assign({
228-
outputChannel: serverOutputChannel,
229-
traceOutputChannel: serverTraceChannel
230-
}, cfg);
226+
}
227+
return Object.assign({
228+
outputChannel: serverOutputChannel,
229+
traceOutputChannel: serverTraceChannel
230+
}, cfg);
231231
}
232232

233233
// buildLanguageClient returns a language client built using the given language server config.
@@ -1128,6 +1128,17 @@ async function suggestGoplsIssueReport(msg: string, reason: errorKind) {
11281128
return;
11291129
}
11301130

1131+
// The user may have an outdated version of gopls, in which case we should
1132+
// just prompt them to update, not file an issue.
1133+
const tool = getTool('gopls');
1134+
if (tool) {
1135+
const versionToUpdate = await shouldUpdateLanguageServer(tool, latestConfig);
1136+
if (versionToUpdate) {
1137+
promptForUpdatingTool(tool.name, versionToUpdate, true);
1138+
return;
1139+
}
1140+
}
1141+
11311142
// Show the user the output channel content to alert them to the issue.
11321143
serverOutputChannel.show();
11331144

@@ -1165,8 +1176,8 @@ You will be asked to provide additional information and logs, so PLEASE READ THE
11651176
errKind = 'initialization';
11661177
break;
11671178
}
1179+
// Get the user's version in case the update prompt above failed.
11681180
const usersGoplsVersion = await getLocalGoplsVersion(latestConfig);
1169-
// TODO(hakim): If gopls version is too old, ask users to update it.
11701181
const settings = latestConfig.flags.join(' ');
11711182
const title = `gopls: automated issue report (${errKind})`;
11721183
const sanitizedLog = collectGoplsLog();
@@ -1258,7 +1269,7 @@ export function showServerOutputChannel() {
12581269
}
12591270
found = doc;
12601271
// .log, as some decoration is better than none
1261-
vscode.workspace.openTextDocument({language: 'log', content: contents});
1272+
vscode.workspace.openTextDocument({ language: 'log', content: contents });
12621273
}
12631274
}
12641275
if (found === undefined) {

0 commit comments

Comments
 (0)