Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions internal/ls/autoimport/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/microsoft/typescript-go/internal/bundled"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/ls"
"github.com/microsoft/typescript-go/internal/ls/autoimport"
"github.com/microsoft/typescript-go/internal/ls/lsconv"
"github.com/microsoft/typescript-go/internal/ls/lsutil"
Expand Down Expand Up @@ -633,10 +634,21 @@ export declare const otherValue: string;`,
{WholeDocument: &lsproto.TextDocumentContentChangeWholeDocument{Text: `export declare function otherFunction(): void;`}},
})

// other-pkg should trigger a full rebuild (multipleFilesDirty), not a granular update
_, err = session.GetLanguageService(ctx, projectAURI)
// other-pkg should trigger a full rebuild (multipleFilesDirty), not a granular update.
// Read stats from the request-time snapshot (held by ref via WithLanguageServiceAndSnapshot)
// rather than session.Snapshot(), so a background auto-import warm task — which would
// walk otherPkgURI's ancestor chain through project-a's node_modules and rebuild that
// bucket — cannot race with the assertion by adopting a freshly-cleaned snapshot
// before we read it.
_, err = session.WithLanguageServiceAndSnapshot(
ctx,
projectAURI,
func(_ *ls.LanguageService, snapshot *project.Snapshot) (func() error, error) {
stats = snapshot.AutoImportRegistry().GetCacheStats()
return nil, nil
},
)
assert.NilError(t, err)
stats = autoImportStats(t, session)
nodeModulesBucket = singleBucket(t, stats.NodeModulesBuckets)
assert.Equal(t, nodeModulesBucket.State.Dirty(), true, "bucket should be dirty after registry package change")
dirtyPackages = nodeModulesBucket.State.DirtyPackages()
Expand Down
Loading