@@ -274,76 +274,6 @@ export async function activate(
274274 // Checking the vscode version should not block extension activation.
275275 void assertVSCodeVersionGreaterThan ( MIN_VERSION , ctx ) ;
276276
277- async function installOrUpdateDistributionWithProgressTitle (
278- progressTitle : string ,
279- config : DistributionUpdateConfig ,
280- ) : Promise < void > {
281- const minSecondsSinceLastUpdateCheck = config . isUserInitiated ? 0 : 86400 ;
282- const noUpdatesLoggingFunc = config . shouldDisplayMessageWhenNoUpdates
283- ? showAndLogInformationMessage
284- : async ( message : string ) => void extLogger . log ( message ) ;
285- const result =
286- await distributionManager . checkForUpdatesToExtensionManagedDistribution (
287- minSecondsSinceLastUpdateCheck ,
288- ) ;
289-
290- // We do want to auto update if there is no distribution at all
291- const allowAutoUpdating =
292- config . allowAutoUpdating ||
293- ! ( await distributionManager . hasDistribution ( ) ) ;
294-
295- switch ( result . kind ) {
296- case DistributionUpdateCheckResultKind . AlreadyCheckedRecentlyResult :
297- void extLogger . log (
298- "Didn't perform CodeQL CLI update check since a check was already performed within the previous " +
299- `${ minSecondsSinceLastUpdateCheck } seconds.` ,
300- ) ;
301- break ;
302- case DistributionUpdateCheckResultKind . AlreadyUpToDate :
303- await noUpdatesLoggingFunc ( "CodeQL CLI already up to date." ) ;
304- break ;
305- case DistributionUpdateCheckResultKind . InvalidLocation :
306- await noUpdatesLoggingFunc (
307- "CodeQL CLI is installed externally so could not be updated." ,
308- ) ;
309- break ;
310- case DistributionUpdateCheckResultKind . UpdateAvailable :
311- if ( beganMainExtensionActivation || ! allowAutoUpdating ) {
312- const updateAvailableMessage =
313- `Version "${ result . updatedRelease . name } " of the CodeQL CLI is now available. ` +
314- "Do you wish to upgrade?" ;
315- await ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
316- if (
317- await showInformationMessageWithAction (
318- updateAvailableMessage ,
319- "Restart and Upgrade" ,
320- )
321- ) {
322- await commands . executeCommand ( "workbench.action.reloadWindow" ) ;
323- }
324- } else {
325- await withProgress (
326- ( progress ) =>
327- distributionManager . installExtensionManagedDistributionRelease (
328- result . updatedRelease ,
329- progress ,
330- ) ,
331- {
332- title : progressTitle ,
333- } ,
334- ) ;
335-
336- await ctx . globalState . update ( shouldUpdateOnNextActivationKey , false ) ;
337- void showAndLogInformationMessage (
338- `CodeQL CLI updated to version "${ result . updatedRelease . name } ".` ,
339- ) ;
340- }
341- break ;
342- default :
343- assertNever ( result ) ;
344- }
345- }
346-
347277 async function installOrUpdateDistribution (
348278 config : DistributionUpdateConfig ,
349279 ) : Promise < void > {
@@ -364,7 +294,12 @@ export async function activate(
364294 : "Installing CodeQL CLI" ;
365295
366296 try {
367- await installOrUpdateDistributionWithProgressTitle ( messageText , config ) ;
297+ await installOrUpdateDistributionWithProgressTitle (
298+ ctx ,
299+ distributionManager ,
300+ messageText ,
301+ config ,
302+ ) ;
368303 } catch ( e ) {
369304 // Don't rethrow the exception, because if the config is changed, we want to be able to retry installing
370305 // or updating the distribution.
@@ -525,6 +460,77 @@ export async function activate(
525460 return codeQlExtension ;
526461}
527462
463+ async function installOrUpdateDistributionWithProgressTitle (
464+ ctx : ExtensionContext ,
465+ distributionManager : DistributionManager ,
466+ progressTitle : string ,
467+ config : DistributionUpdateConfig ,
468+ ) : Promise < void > {
469+ const minSecondsSinceLastUpdateCheck = config . isUserInitiated ? 0 : 86400 ;
470+ const noUpdatesLoggingFunc = config . shouldDisplayMessageWhenNoUpdates
471+ ? showAndLogInformationMessage
472+ : async ( message : string ) => void extLogger . log ( message ) ;
473+ const result =
474+ await distributionManager . checkForUpdatesToExtensionManagedDistribution (
475+ minSecondsSinceLastUpdateCheck ,
476+ ) ;
477+
478+ // We do want to auto update if there is no distribution at all
479+ const allowAutoUpdating =
480+ config . allowAutoUpdating || ! ( await distributionManager . hasDistribution ( ) ) ;
481+
482+ switch ( result . kind ) {
483+ case DistributionUpdateCheckResultKind . AlreadyCheckedRecentlyResult :
484+ void extLogger . log (
485+ "Didn't perform CodeQL CLI update check since a check was already performed within the previous " +
486+ `${ minSecondsSinceLastUpdateCheck } seconds.` ,
487+ ) ;
488+ break ;
489+ case DistributionUpdateCheckResultKind . AlreadyUpToDate :
490+ await noUpdatesLoggingFunc ( "CodeQL CLI already up to date." ) ;
491+ break ;
492+ case DistributionUpdateCheckResultKind . InvalidLocation :
493+ await noUpdatesLoggingFunc (
494+ "CodeQL CLI is installed externally so could not be updated." ,
495+ ) ;
496+ break ;
497+ case DistributionUpdateCheckResultKind . UpdateAvailable :
498+ if ( beganMainExtensionActivation || ! allowAutoUpdating ) {
499+ const updateAvailableMessage =
500+ `Version "${ result . updatedRelease . name } " of the CodeQL CLI is now available. ` +
501+ "Do you wish to upgrade?" ;
502+ await ctx . globalState . update ( shouldUpdateOnNextActivationKey , true ) ;
503+ if (
504+ await showInformationMessageWithAction (
505+ updateAvailableMessage ,
506+ "Restart and Upgrade" ,
507+ )
508+ ) {
509+ await commands . executeCommand ( "workbench.action.reloadWindow" ) ;
510+ }
511+ } else {
512+ await withProgress (
513+ ( progress ) =>
514+ distributionManager . installExtensionManagedDistributionRelease (
515+ result . updatedRelease ,
516+ progress ,
517+ ) ,
518+ {
519+ title : progressTitle ,
520+ } ,
521+ ) ;
522+
523+ await ctx . globalState . update ( shouldUpdateOnNextActivationKey , false ) ;
524+ void showAndLogInformationMessage (
525+ `CodeQL CLI updated to version "${ result . updatedRelease . name } ".` ,
526+ ) ;
527+ }
528+ break ;
529+ default :
530+ assertNever ( result ) ;
531+ }
532+ }
533+
528534const PACK_GLOBS = [
529535 "**/codeql-pack.yml" ,
530536 "**/qlpack.yml" ,
0 commit comments