@@ -166,11 +166,6 @@ describe("activate", () => {
166166 title : string ;
167167 } ;
168168 expect ( treeView . title ) . toBe ( `${ FOLDER_NAME_PREFIX } MyVault` ) ;
169- expect ( vscode . commands . executeCommand ) . toHaveBeenCalledWith (
170- "setContext" ,
171- "obsidianVFS.active" ,
172- true ,
173- ) ;
174169 expect ( registerCommands ) . toHaveBeenCalledWith (
175170 ctx ,
176171 fakeTracker ,
@@ -373,7 +368,45 @@ describe("activate", () => {
373368 expect ( statusBarInstance . show ) . toHaveBeenCalled ( ) ;
374369 } ) ;
375370
376- it ( "does not set explorerEnabled context when explorer is false" , async ( ) => {
371+ it ( "refreshes tree provider when view becomes visible" , async ( ) => {
372+ const fakeTracker = {
373+ context : {
374+ name : "MyVault" ,
375+ physicalPath : "/vault" ,
376+ mode : "full" ,
377+ vfsConfig : { agents : [ ] , skills : [ ] , allowed : [ ] , blocked : [ ] } ,
378+ } ,
379+ } as unknown as LocalIndexTracker ;
380+
381+ mockBootstrap . mockResolvedValueOnce ( {
382+ ok : true ,
383+ value : { tracker : fakeTracker , initMs : 42 } ,
384+ } ) ;
385+
386+ await activate ( fakeContext ( ) as never ) ;
387+
388+ const treeView = vi . mocked ( vscode . window . createTreeView ) . mock . results [ 0 ] . value as {
389+ onDidChangeVisibility : ReturnType < typeof vi . fn > ;
390+ } ;
391+ expect ( treeView . onDidChangeVisibility ) . toHaveBeenCalledWith ( expect . any ( Function ) ) ;
392+
393+ const treeProviderInstance = vi . mocked ( VaultTreeDataProvider ) . mock . results [ 0 ] . value as {
394+ refresh : ReturnType < typeof vi . fn > ;
395+ } ;
396+
397+ const visibilityCallback = treeView . onDidChangeVisibility . mock . calls [ 0 ] [ 0 ] as ( e : {
398+ visible : boolean ;
399+ } ) => void ;
400+
401+ visibilityCallback ( { visible : true } ) ;
402+ expect ( treeProviderInstance . refresh ) . toHaveBeenCalled ( ) ;
403+
404+ treeProviderInstance . refresh . mockClear ( ) ;
405+ visibilityCallback ( { visible : false } ) ;
406+ expect ( treeProviderInstance . refresh ) . not . toHaveBeenCalled ( ) ;
407+ } ) ;
408+
409+ it ( "disables tree provider when explorer is false" , async ( ) => {
377410 const fakeTracker = {
378411 context : {
379412 name : "MyVault" ,
@@ -398,12 +431,13 @@ describe("activate", () => {
398431
399432 await activate ( fakeContext ( ) as never ) ;
400433
401- const executeCommand = vi . mocked ( vscode . commands . executeCommand ) ;
402- expect ( executeCommand ) . toHaveBeenCalledWith ( "setContext" , "obsidianVFS.active" , true ) ;
403- expect ( executeCommand ) . toHaveBeenCalledWith ( "setContext" , "obsidianVFS.explorerEnabled" , false ) ;
434+ const treeProviderInstance = vi . mocked ( VaultTreeDataProvider ) . mock . results [ 0 ] . value as {
435+ enabled : boolean ;
436+ } ;
437+ expect ( treeProviderInstance . enabled ) . toBe ( false ) ;
404438 } ) ;
405439
406- it ( "sets explorerEnabled context when explorer is true" , async ( ) => {
440+ it ( "keeps tree provider enabled when explorer is true" , async ( ) => {
407441 const fakeTracker = {
408442 context : {
409443 name : "MyVault" ,
@@ -428,9 +462,10 @@ describe("activate", () => {
428462
429463 await activate ( fakeContext ( ) as never ) ;
430464
431- const executeCommand = vi . mocked ( vscode . commands . executeCommand ) ;
432- expect ( executeCommand ) . toHaveBeenCalledWith ( "setContext" , "obsidianVFS.active" , true ) ;
433- expect ( executeCommand ) . toHaveBeenCalledWith ( "setContext" , "obsidianVFS.explorerEnabled" , true ) ;
465+ const treeProviderInstance = vi . mocked ( VaultTreeDataProvider ) . mock . results [ 0 ] . value as {
466+ enabled : boolean ;
467+ } ;
468+ expect ( treeProviderInstance . enabled ) . toBe ( true ) ;
434469 } ) ;
435470} ) ;
436471
@@ -460,7 +495,7 @@ describe("configuration change listener", () => {
460495 expect ( vscode . workspace . onDidChangeConfiguration ) . toHaveBeenCalled ( ) ;
461496 } ) ;
462497
463- it ( "updates explorerEnabled context when explorer config changes to true" , async ( ) => {
498+ it ( "enables tree provider when explorer config changes to true" , async ( ) => {
464499 const fakeTracker = {
465500 context : {
466501 name : "MyVault" ,
@@ -498,11 +533,13 @@ describe("configuration change listener", () => {
498533
499534 configChangeListener ! ( { affectsConfiguration : ( key ) => key === "obsidianVFS.explorer" } ) ;
500535
501- const executeCommand = vi . mocked ( vscode . commands . executeCommand ) ;
502- expect ( executeCommand ) . toHaveBeenCalledWith ( "setContext" , "obsidianVFS.explorerEnabled" , true ) ;
536+ const treeProviderInstance = vi . mocked ( VaultTreeDataProvider ) . mock . results [ 0 ] . value as {
537+ enabled : boolean ;
538+ } ;
539+ expect ( treeProviderInstance . enabled ) . toBe ( true ) ;
503540 } ) ;
504541
505- it ( "updates explorerEnabled context when explorer config changes to false" , async ( ) => {
542+ it ( "disables tree provider when explorer config changes to false" , async ( ) => {
506543 const fakeTracker = {
507544 context : {
508545 name : "MyVault" ,
@@ -538,8 +575,10 @@ describe("configuration change listener", () => {
538575
539576 configChangeListener ! ( { affectsConfiguration : ( key ) => key === "obsidianVFS.explorer" } ) ;
540577
541- const executeCommand = vi . mocked ( vscode . commands . executeCommand ) ;
542- expect ( executeCommand ) . toHaveBeenCalledWith ( "setContext" , "obsidianVFS.explorerEnabled" , false ) ;
578+ const treeProviderInstance = vi . mocked ( VaultTreeDataProvider ) . mock . results [ 0 ] . value as {
579+ enabled : boolean ;
580+ } ;
581+ expect ( treeProviderInstance . enabled ) . toBe ( false ) ;
543582 } ) ;
544583
545584 it ( "shows status bar when statusBar config changes to true" , async ( ) => {
0 commit comments