|
8 | 8 | "github.com/microsoft/typescript-go/internal/bundled" |
9 | 9 | "github.com/microsoft/typescript-go/internal/collections" |
10 | 10 | "github.com/microsoft/typescript-go/internal/core" |
| 11 | + "github.com/microsoft/typescript-go/internal/ls" |
11 | 12 | "github.com/microsoft/typescript-go/internal/ls/autoimport" |
12 | 13 | "github.com/microsoft/typescript-go/internal/ls/lsconv" |
13 | 14 | "github.com/microsoft/typescript-go/internal/ls/lsutil" |
@@ -633,10 +634,21 @@ export declare const otherValue: string;`, |
633 | 634 | {WholeDocument: &lsproto.TextDocumentContentChangeWholeDocument{Text: `export declare function otherFunction(): void;`}}, |
634 | 635 | }) |
635 | 636 |
|
636 | | - // other-pkg should trigger a full rebuild (multipleFilesDirty), not a granular update |
637 | | - _, err = session.GetLanguageService(ctx, projectAURI) |
| 637 | + // other-pkg should trigger a full rebuild (multipleFilesDirty), not a granular update. |
| 638 | + // Read stats from the request-time snapshot (held by ref via WithLanguageServiceAndSnapshot) |
| 639 | + // rather than session.Snapshot(), so a background auto-import warm task — which would |
| 640 | + // walk otherPkgURI's ancestor chain through project-a's node_modules and rebuild that |
| 641 | + // bucket — cannot race with the assertion by adopting a freshly-cleaned snapshot |
| 642 | + // before we read it. |
| 643 | + _, err = session.WithLanguageServiceAndSnapshot( |
| 644 | + ctx, |
| 645 | + projectAURI, |
| 646 | + func(_ *ls.LanguageService, snapshot *project.Snapshot) (func() error, error) { |
| 647 | + stats = snapshot.AutoImportRegistry().GetCacheStats() |
| 648 | + return nil, nil |
| 649 | + }, |
| 650 | + ) |
638 | 651 | assert.NilError(t, err) |
639 | | - stats = autoImportStats(t, session) |
640 | 652 | nodeModulesBucket = singleBucket(t, stats.NodeModulesBuckets) |
641 | 653 | assert.Equal(t, nodeModulesBucket.State.Dirty(), true, "bucket should be dirty after registry package change") |
642 | 654 | dirtyPackages = nodeModulesBucket.State.DirtyPackages() |
|
0 commit comments