@@ -11,6 +11,7 @@ import * as path from 'path';
1111import * as vscode from 'vscode' ;
1212import { Range } from 'vscode-languageclient' ;
1313import * as nls from 'vscode-nls' ;
14+ import { TargetPopulation } from 'vscode-tas-client' ;
1415import { logAndReturn } from '../Utility/Async/returns' ;
1516import * as util from '../common' ;
1617import { 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+ }
0 commit comments