@@ -585,6 +585,41 @@ describe('ProjectManager', () => {
585585 } ) ;
586586
587587 describe ( 'flushDocumentChanges' , ( ) => {
588+ it ( 'reuses cached PathCollection across multiple flushes' , async ( ) => {
589+ fsExtra . outputFileSync ( `${ rootDir } /source/main.brs` , `` ) ;
590+ fsExtra . outputJsonSync ( `${ rootDir } /bsconfig.json` , { } ) ;
591+ await manager . syncProjects ( [ workspaceSettings ] ) ;
592+
593+ //spy on PathCollection constructor to count how many are created
594+ const project = manager . projects [ 0 ] ;
595+ //first flush to warm the cache
596+ await manager [ 'flushDocumentChanges' ] ( {
597+ actions : [ {
598+ srcPath : s `${ rootDir } /source/main.brs` ,
599+ type : 'set' ,
600+ fileContents : 'sub main():end sub' ,
601+ allowStandaloneProject : true
602+ } ]
603+ } ) ;
604+
605+ //grab the cached filterer
606+ const cachedFilterer = manager [ 'projectFiltererCache' ] . get ( project ) ;
607+ expect ( cachedFilterer ) . to . exist ;
608+
609+ //second flush should reuse the same filterer instance
610+ await manager [ 'flushDocumentChanges' ] ( {
611+ actions : [ {
612+ srcPath : s `${ rootDir } /source/main.brs` ,
613+ type : 'set' ,
614+ fileContents : 'sub main2():end sub' ,
615+ allowStandaloneProject : true
616+ } ]
617+ } ) ;
618+
619+ const cachedFilterer2 = manager [ 'projectFiltererCache' ] . get ( project ) ;
620+ expect ( cachedFilterer2 ) . to . equal ( cachedFilterer ) ;
621+ } ) ;
622+
588623 it ( 'does not crash when getting undefined back from projects' , async ( ) => {
589624 fsExtra . outputFileSync ( `${ rootDir } /source/main.brs` , `` ) ;
590625 fsExtra . outputJsonSync ( `${ rootDir } /project1/bsconfig.json` , {
0 commit comments