@@ -6,8 +6,10 @@ import (
66 "testing"
77
88 "github.com/microsoft/typescript-go/internal/collections"
9+ "github.com/microsoft/typescript-go/internal/core"
910 "github.com/microsoft/typescript-go/internal/ls/autoimport"
1011 "github.com/microsoft/typescript-go/internal/ls/lsconv"
12+ "github.com/microsoft/typescript-go/internal/ls/lsutil"
1113 "github.com/microsoft/typescript-go/internal/lsp/lsproto"
1214 "github.com/microsoft/typescript-go/internal/project"
1315 "github.com/microsoft/typescript-go/internal/testutil/autoimporttestutil"
@@ -497,6 +499,63 @@ export declare const otherValue: string;`,
497499 nodeModulesBucket = singleBucket (t , stats .NodeModulesBuckets )
498500 assert .Equal (t , nodeModulesBucket .State .Dirty (), false , "bucket should be clean after rebuild" )
499501 })
502+
503+ t .Run ("changed fileExcludePatterns triggers bucket rebuild" , func (t * testing.T ) {
504+ t .Parallel ()
505+ fixture := autoimporttestutil .SetupLifecycleSession (t , lifecycleProjectRoot , 1 )
506+ session := fixture .Session ()
507+ project := fixture .SingleProject ()
508+ mainFile := project .File (0 )
509+
510+ ctx := context .Background ()
511+
512+ // Open file and build auto-imports initially
513+ session .DidOpenFile (ctx , mainFile .URI (), 1 , mainFile .Content (), lsproto .LanguageKindTypeScript )
514+ _ , err := session .GetLanguageServiceWithAutoImports (ctx , mainFile .URI ())
515+ assert .NilError (t , err )
516+
517+ // Verify buckets are clean after initial build
518+ stats := autoImportStats (t , session )
519+ projectBucket := singleBucket (t , stats .ProjectBuckets )
520+ nodeModulesBucket := singleBucket (t , stats .NodeModulesBuckets )
521+ assert .Equal (t , false , projectBucket .State .Dirty ())
522+ assert .Equal (t , false , nodeModulesBucket .State .Dirty ())
523+
524+ // IsPreparedForImportingFile should return true with no exclude patterns
525+ snapshot , release := session .Snapshot ()
526+ defaultProject := snapshot .GetDefaultProject (mainFile .URI ())
527+ assert .Assert (t , defaultProject != nil )
528+ projectPath := defaultProject .ConfigFilePath ()
529+ preferences := lsutil .NewDefaultUserPreferences ()
530+ preferences .IncludeCompletionsForModuleExports = core .TSTrue
531+ preferences .IncludeCompletionsForImportStatements = core .TSTrue
532+ isPrepared := snapshot .AutoImportRegistry ().IsPreparedForImportingFile (mainFile .FileName (), projectPath , preferences )
533+ release ()
534+ assert .Assert (t , isPrepared )
535+
536+ // Change the file exclude patterns preference
537+ newPreferences := lsutil .NewDefaultUserPreferences ()
538+ newPreferences .IncludeCompletionsForModuleExports = core .TSTrue
539+ newPreferences .IncludeCompletionsForImportStatements = core .TSTrue
540+ newPreferences .AutoImportFileExcludePatterns = []string {"**/node_modules/**/*.d.ts" }
541+ session .Configure (lsutil .NewUserConfig (newPreferences ))
542+
543+ // IsPreparedForImportingFile should return false since exclude patterns changed
544+ snapshot2 , release2 := session .Snapshot ()
545+ isPrepared2 := snapshot2 .AutoImportRegistry ().IsPreparedForImportingFile (mainFile .FileName (), projectPath , newPreferences )
546+ release2 ()
547+ assert .Assert (t , ! isPrepared2 )
548+
549+ // After GetLanguageServiceWithAutoImports, buckets should be rebuilt
550+ _ , err = session .GetLanguageServiceWithAutoImports (ctx , mainFile .URI ())
551+ assert .NilError (t , err )
552+
553+ // IsPreparedForImportingFile should return true now that buckets are rebuilt
554+ snapshot3 , release3 := session .Snapshot ()
555+ isPrepared3 := snapshot3 .AutoImportRegistry ().IsPreparedForImportingFile (mainFile .FileName (), projectPath , newPreferences )
556+ release3 ()
557+ assert .Assert (t , isPrepared3 , "IsPreparedForImportingFile should return true after bucket rebuild with new fileExcludePatterns" )
558+ })
500559}
501560
502561const (
0 commit comments