Skip to content

Commit 8fbc56a

Browse files
authored
Notify users if there's a pre-release version available. (#11569)
* Notify users if there's a pre-release version available
1 parent fecfc08 commit 8fbc56a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Extension/src/LanguageServer/extension.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as path from 'path';
1111
import * as vscode from 'vscode';
1212
import { Range } from 'vscode-languageclient';
1313
import * as nls from 'vscode-nls';
14+
import { TargetPopulation } from 'vscode-tas-client';
1415
import { logAndReturn } from '../Utility/Async/returns';
1516
import * as util from '../common';
1617
import { PlatformInformation } from '../platform';
@@ -1162,3 +1163,36 @@ export function UpdateInsidersAccess(): void {
11621163
void vscode.commands.executeCommand("workbench.extensions.installExtension", "ms-vscode.cpptools", { installPreReleaseVersion: true }).then(undefined, logAndReturn.undefined);
11631164
}
11641165
}
1166+
1167+
export async function preReleaseCheck(): Promise<void> {
1168+
const displayedPreReleasePrompt: PersistentState<boolean> = new PersistentState<boolean>("CPP.displayedPreReleasePrompt", false);
1169+
1170+
// First we need to make sure the user isn't already on a pre-release version and hasn't dismissed this prompt before.
1171+
if (!displayedPreReleasePrompt.Value && util.getCppToolsTargetPopulation() === TargetPopulation.Public) {
1172+
// Get the info on the latest version from the marketplace to check if there is a pre-release version available.
1173+
const response = await fetch('https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery', {
1174+
method: 'POST',
1175+
headers: {
1176+
Accept : 'application/json; api-version=3.0-preview',
1177+
'Content-Type' : 'application/json'
1178+
},
1179+
body: '{"filters": [{"criteria": [{"filterType": 7, "value": "ms-vscode.cpptools"}]}], "flags": 529}'
1180+
});
1181+
1182+
const data = await response.json();
1183+
const preReleaseAvailable = data.results[0].extensions[0].versions[0].properties.some((e: object) => Object.values(e).includes("Microsoft.VisualStudio.Code.PreRelease"));
1184+
1185+
// If the user isn't on the pre-release version, but one is available, prompt them to install it.
1186+
if (preReleaseAvailable) {
1187+
displayedPreReleasePrompt.Value = true;
1188+
const message: string = localize("prerelease.message", "A pre-release version of the C/C++ extension is available. Would you like to switch to it?");
1189+
const yes: string = localize("yes.button", "Yes");
1190+
const no: string = localize("no.button", "No");
1191+
void vscode.window.showInformationMessage(message, yes, no).then((selection) => {
1192+
if (selection === yes) {
1193+
void vscode.commands.executeCommand("workbench.extensions.installExtension", "ms-vscode.cpptools", { installPreReleaseVersion: true }).then(undefined, logAndReturn.undefined);
1194+
}
1195+
});
1196+
}
1197+
}
1198+
}

Extension/src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<CppToo
7070
util.checkDistro(info);
7171
await checkVsixCompatibility();
7272
LanguageServer.UpdateInsidersAccess();
73+
await LanguageServer.preReleaseCheck();
7374

7475
const settings: CppSettings = new CppSettings((vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) ? vscode.workspace.workspaceFolders[0]?.uri : undefined);
7576
let isOldMacOs: boolean = false;

0 commit comments

Comments
 (0)