@@ -287,9 +287,7 @@ export class MiseExtension {
287287 }
288288 } ) ;
289289
290- const globalCmdCache = createCache ( {
291- ttl : 1 ,
292- } ) . define ( "reload" , async ( ) => {
290+ const reloadConfiguration = async ( ) => {
293291 try {
294292 logger . info ( "Reloading Mise configuration" ) ;
295293 this . updateStatusBar ( { state : "loading" } ) ;
@@ -347,18 +345,35 @@ export class MiseExtension {
347345
348346 void this . checkForInvalidMiseConfigFiles ( ) ;
349347 await this . updateStatusBarTooltip ( ) ;
350- } ) ;
348+ } ;
349+
350+ // internal triggers (file watcher, task end, config change) come in
351+ // storms: close reloads are coalesced into one
352+ const globalCmdCache = createCache ( {
353+ ttl : 1 ,
354+ } ) . define ( "reload" , reloadConfiguration ) ;
351355
352356 context . subscriptions . push (
353- vscode . commands . registerCommand ( MISE_RELOAD , async ( ) => {
354- await globalCmdCache . reload ( ) ;
355- } ) ,
357+ vscode . commands . registerCommand (
358+ MISE_RELOAD ,
359+ async ( options ?: { force ?: boolean } ) => {
360+ if ( options ?. force ) {
361+ // a deliberate state change (folder switch, reload asked by
362+ // the user) must not be coalesced into an already running
363+ // reload, which read the state from before the change
364+ await globalCmdCache . clear ( ) ;
365+ await reloadConfiguration ( ) ;
366+ return ;
367+ }
368+ await globalCmdCache . reload ( ) ;
369+ } ,
370+ ) ,
356371 // only the reload the user asked for drops what was kept from before a
357372 // config file broke: the internal reloads above must not empty the
358373 // views while the file is still being typed
359374 vscode . commands . registerCommand ( MISE_RELOAD_FROM_USER , async ( ) => {
360375 this . miseService . forgetRetainedState ( ) ;
361- await vscode . commands . executeCommand ( MISE_RELOAD ) ;
376+ await vscode . commands . executeCommand ( MISE_RELOAD , { force : true } ) ;
362377 } ) ,
363378 ) ;
364379
@@ -396,7 +411,7 @@ export class MiseExtension {
396411
397412 if ( selectedFolder ) {
398413 await setCurrentWorkspaceFolder ( context , selectedFolder ) ;
399- vscode . commands . executeCommand ( MISE_RELOAD ) ;
414+ vscode . commands . executeCommand ( MISE_RELOAD , { force : true } ) ;
400415 }
401416 return ;
402417 }
@@ -412,7 +427,7 @@ export class MiseExtension {
412427 } ) ;
413428 if ( selectedFolder ) {
414429 await setCurrentWorkspaceFolder ( context , selectedFolder ) ;
415- vscode . commands . executeCommand ( MISE_RELOAD ) ;
430+ vscode . commands . executeCommand ( MISE_RELOAD , { force : true } ) ;
416431 }
417432 } ,
418433 ) ,
@@ -422,7 +437,7 @@ export class MiseExtension {
422437 const workspaceFolders = vscode . workspace . workspaceFolders ;
423438 if ( ! workspaceFolders ?. length ) {
424439 await clearCurrentWorkspaceFolder ( context ) ;
425- vscode . commands . executeCommand ( MISE_RELOAD ) ;
440+ vscode . commands . executeCommand ( MISE_RELOAD , { force : true } ) ;
426441 return ;
427442 }
428443
@@ -433,7 +448,7 @@ export class MiseExtension {
433448 await setCurrentWorkspaceFolder ( context , currentFolder ) ;
434449 }
435450
436- vscode . commands . executeCommand ( MISE_RELOAD ) ;
451+ vscode . commands . executeCommand ( MISE_RELOAD , { force : true } ) ;
437452 } ) ;
438453
439454 context . subscriptions . push (
0 commit comments