Skip to content

Commit c21ee59

Browse files
committed
extension: recognize IDX as a web ide and auto-install gopls
If important tools (gopls, linter) are missing, try to install them during activation. Originally, we wanted to install only gopls this way, but learned that the extension does not prompt for missing linter tools, but silently omits it from check. Report the status of missing, important tools and the new Go version release using the language status bar items. And, remove dlv and vscgo from the important tools list. vscgo is not yet critical for the extension's functionality. The extension will ask the user to install dlv when needed. Change-Id: I1b76a7b18c004b870b95a89659ee34594acbcf14 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/559895 Reviewed-by: Suzy Mueller <[email protected]> Commit-Queue: Hyang-Ah Hana Kim <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent 8d10f63 commit c21ee59

File tree

11 files changed

+294
-136
lines changed

11 files changed

+294
-136
lines changed

extension/src/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class ExtensionInfo {
4646
this.isPreview = !!packageJSON?.preview;
4747
this.isInCloudIDE =
4848
process.env.CLOUD_SHELL === 'true' ||
49+
process.env.MONOSPACE_ENV === 'true' ||
4950
process.env.CODESPACES === 'true' ||
5051
!!process.env.GITPOD_WORKSPACE_ID;
5152
}

extension/src/goDebugConfiguration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
322322
const toolsManagementConfig = getGoConfig()['toolsManagement'];
323323
if (toolsManagementConfig && toolsManagementConfig['autoUpdate'] === true) {
324324
const goVersion = await getGoVersion();
325-
await installTools([tool], goVersion, true);
325+
await installTools([tool], goVersion, { silent: true });
326326
} else {
327327
await promptForUpdatingTool(tool.name);
328328
}

extension/src/goEnvironmentStatus.ts

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,13 @@ export async function getLatestGoVersions(): Promise<GoEnvironmentOption[]> {
520520
return results;
521521
}
522522

523-
const STATUS_BAR_ITEM_NAME = 'Go Notification';
523+
const STATUS_BAR_ITEM_NAME = 'Go Update Notification';
524524
const dismissedGoVersionUpdatesKey = 'dismissedGoVersionUpdates';
525525

526-
export async function offerToInstallLatestGoVersion() {
526+
export async function offerToInstallLatestGoVersion(ctx: Pick<vscode.ExtensionContext, 'subscriptions'>) {
527527
if (extensionInfo.isInCloudIDE) {
528+
// TODO: As we use the language status bar, the notification is less visible
529+
// and we can consider to remove this condition check.
528530
return;
529531
}
530532
const goConfig = getGoConfig();
@@ -551,59 +553,66 @@ export async function offerToInstallLatestGoVersion() {
551553

552554
// notify user that there is a newer version of Go available
553555
if (options.length > 0) {
554-
addGoStatus(
555-
STATUS_BAR_ITEM_NAME,
556-
'Go Update Available',
557-
'go.promptforgoinstall',
558-
'A newer version of Go is available'
559-
);
560-
vscode.commands.registerCommand('go.promptforgoinstall', () => {
561-
const download = {
562-
title: 'Download',
563-
async command() {
564-
await vscode.env.openExternal(vscode.Uri.parse('https://go.dev/dl/'));
565-
}
566-
};
567-
568-
const neverAgain = {
569-
title: "Don't Show Again",
570-
async command() {
571-
// mark these versions as seen
572-
dismissedOptions = await getFromGlobalState(dismissedGoVersionUpdatesKey);
573-
if (!dismissedOptions) {
574-
dismissedOptions = [];
556+
const versionsText = options.map((x) => x.label).join(', ');
557+
const statusBarItem = addGoStatus(STATUS_BAR_ITEM_NAME);
558+
statusBarItem.name = STATUS_BAR_ITEM_NAME;
559+
statusBarItem.text = 'New Go version is available';
560+
statusBarItem.detail = versionsText;
561+
statusBarItem.command = {
562+
title: 'Upgrade',
563+
command: 'go.promptforgoinstall',
564+
arguments: [options],
565+
tooltip: 'Upgrade or silence notification'
566+
};
567+
// TODO: Error level is more visible. Consider to make it configurable?
568+
statusBarItem.severity = vscode.LanguageStatusSeverity.Warning;
569+
570+
ctx.subscriptions.push(
571+
vscode.commands.registerCommand('go.promptforgoinstall', () => {
572+
const download = {
573+
title: 'Download',
574+
async command() {
575+
await vscode.env.openExternal(vscode.Uri.parse('https://go.dev/dl/'));
575576
}
576-
options.forEach((version) => {
577-
dismissedOptions.push(version);
578-
});
579-
await updateGlobalState(dismissedGoVersionUpdatesKey, dismissedOptions);
577+
};
578+
579+
const neverAgain = {
580+
title: "Don't Show Again",
581+
async command() {
582+
// mark these versions as seen
583+
dismissedOptions = await getFromGlobalState(dismissedGoVersionUpdatesKey);
584+
if (!dismissedOptions) {
585+
dismissedOptions = [];
586+
}
587+
options.forEach((version) => {
588+
dismissedOptions.push(version);
589+
});
590+
await updateGlobalState(dismissedGoVersionUpdatesKey, dismissedOptions);
591+
}
592+
};
593+
594+
let versionsText: string;
595+
if (options.length > 1) {
596+
versionsText = `${options
597+
.map((x) => x.label)
598+
.reduce((prev, next) => {
599+
return prev + ' and ' + next;
600+
})} are available`;
601+
} else {
602+
versionsText = `${options[0].label} is available`;
580603
}
581-
};
582-
583-
let versionsText: string;
584-
if (options.length > 1) {
585-
versionsText = `${options
586-
.map((x) => x.label)
587-
.reduce((prev, next) => {
588-
return prev + ' and ' + next;
589-
})} are available`;
590-
} else {
591-
versionsText = `${options[0].label} is available`;
592-
}
593604

594-
vscode.window
595-
.showInformationMessage(
596-
`${versionsText}. You are currently using ${formatGoVersion(currentVersion)}.`,
597-
download,
598-
neverAgain
599-
)
600-
.then((selection) => {
601-
// TODO: should we removeGoStatus if user has closed the notification
602-
// without any action? It's kind of a feature now - without selecting
603-
// neverAgain, user can hide this statusbar item.
604-
removeGoStatus(STATUS_BAR_ITEM_NAME);
605-
selection?.command();
606-
});
607-
});
605+
vscode.window
606+
.showInformationMessage(
607+
`${versionsText}. You are currently using ${formatGoVersion(currentVersion)}.`,
608+
download,
609+
neverAgain
610+
)
611+
.then((selection) => {
612+
selection?.command();
613+
removeGoStatus(STATUS_BAR_ITEM_NAME);
614+
});
615+
})
616+
);
608617
}
609618
}

0 commit comments

Comments
 (0)