@@ -439,6 +439,36 @@ func TestProjectCollectionBuilder(t *testing.T) {
439439 // triggering a crash.
440440 session .DidOpenFile (context .Background (), "file:///project/index.ts" , 1 , files ["/project/index.ts" ].(string ), lsproto .LanguageKindTypeScript )
441441 })
442+
443+ t .Run ("inferred project root files are in stable order" , func (t * testing.T ) {
444+ t .Parallel ()
445+ files := map [string ]any {
446+ "/project/a.ts" : `export const a = 1;` ,
447+ "/project/b.ts" : `export const b = 1;` ,
448+ "/project/c.ts" : `export const c = 1;` ,
449+ }
450+
451+ session , _ := projecttestutil .Setup (files )
452+
453+ // b, c, a
454+ session .DidOpenFile (context .Background (), "file:///project/b.ts" , 1 , files ["/project/b.ts" ].(string ), lsproto .LanguageKindTypeScript )
455+ session .DidOpenFile (context .Background (), "file:///project/c.ts" , 1 , files ["/project/c.ts" ].(string ), lsproto .LanguageKindTypeScript )
456+ session .DidOpenFile (context .Background (), "file:///project/a.ts" , 1 , files ["/project/a.ts" ].(string ), lsproto .LanguageKindTypeScript )
457+
458+ snapshot , release := session .Snapshot ()
459+ defer release ()
460+ assert .Equal (t , len (snapshot .ProjectCollection .Projects ()), 1 )
461+ inferredProject := snapshot .ProjectCollection .InferredProject ()
462+ assert .Assert (t , inferredProject != nil )
463+ // It's more bookkeeping to maintain order of opening, since any file can move into or out of
464+ // the inferred project due to changes in other projects. Order shouldn't matter for correctness,
465+ // we just want it to be consistent, in case there are observable type ordering issues.
466+ assert .DeepEqual (t , inferredProject .Program .CommandLine ().FileNames (), []string {
467+ "/project/a.ts" ,
468+ "/project/b.ts" ,
469+ "/project/c.ts" ,
470+ })
471+ })
442472}
443473
444474func filesForSolutionConfigFile (solutionRefs []string , compilerOptions string , ownFiles []string ) map [string ]any {
0 commit comments