@@ -173,7 +173,7 @@ export class ExplorerView extends ViewPane implements IExplorerView {
173173 private viewHasSomeCollapsibleRootItem : IContextKey < boolean > ;
174174 private viewVisibleContextKey : IContextKey < boolean > ;
175175
176-
176+ private setTreeInputPromise : Promise < void > | undefined ;
177177 private horizontalScrolling : boolean | undefined ;
178178
179179 private dragHandler ! : DelayedDragHandler ;
@@ -522,7 +522,7 @@ export class ExplorerView extends ViewPane implements IExplorerView {
522522
523523 // save view state
524524 this . _register ( this . storageService . onWillSaveState ( ( ) => {
525- this . storageService . store ( ExplorerView . TREE_VIEW_STATE_STORAGE_KEY , JSON . stringify ( this . tree . getViewState ( ) ) , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
525+ this . storeTreeViewState ( ) ;
526526 } ) ) ;
527527 }
528528
@@ -540,6 +540,10 @@ export class ExplorerView extends ViewPane implements IExplorerView {
540540 }
541541 }
542542
543+ private storeTreeViewState ( ) {
544+ this . storageService . store ( ExplorerView . TREE_VIEW_STATE_STORAGE_KEY , JSON . stringify ( this . tree . getViewState ( ) ) , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
545+ }
546+
543547 private setContextKeys ( stat : ExplorerItem | null | undefined ) : void {
544548 const folders = this . contextService . getWorkspace ( ) . folders ;
545549 const resource = stat ? stat . resource : folders [ folders . length - 1 ] . uri ;
@@ -666,6 +670,11 @@ export class ExplorerView extends ViewPane implements IExplorerView {
666670 return Promise . resolve ( undefined ) ;
667671 }
668672
673+ // Wait for the last execution to complete before executing
674+ if ( this . setTreeInputPromise ) {
675+ await this . setTreeInputPromise ;
676+ }
677+
669678 const initialInputSetup = ! this . tree . getInput ( ) ;
670679 if ( initialInputSetup ) {
671680 perf . mark ( 'code/willResolveExplorer' ) ;
@@ -688,7 +697,7 @@ export class ExplorerView extends ViewPane implements IExplorerView {
688697 }
689698
690699 const previousInput = this . tree . getInput ( ) ;
691- const promise = this . tree . setInput ( input , viewState ) . then ( async ( ) => {
700+ const promise = this . setTreeInputPromise = this . tree . setInput ( input , viewState ) . then ( async ( ) => {
692701 if ( Array . isArray ( input ) ) {
693702 if ( ! viewState || previousInput instanceof ExplorerItem ) {
694703 // There is no view state for this workspace (we transitioned from a folder workspace?), expand up to five roots.
@@ -883,6 +892,8 @@ export class ExplorerView extends ViewPane implements IExplorerView {
883892 const treeInputArray = Array . isArray ( treeInput ) ? treeInput : Array . from ( treeInput . children . values ( ) ) ;
884893 // Has collapsible root when anything is expanded
885894 this . viewHasSomeCollapsibleRootItem . set ( hasExpandedNode ( this . tree , treeInputArray ) ) ;
895+ // synchronize state to cache
896+ this . storeTreeViewState ( ) ;
886897 }
887898
888899 override dispose ( ) : void {
0 commit comments