Skip to content

Commit c12369b

Browse files
author
Andy
authored
Fix bug where findAllReferences included a node outside of sourceFilesToSearch (#22062)
1 parent 9acad22 commit c12369b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/services/findAllReferences.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,8 @@ namespace ts.FindAllReferences.Core {
476476
*/
477477
readonly markSeenReExportRHS = nodeSeenTracker();
478478

479+
private readonly includedSourceFiles: Map<true>;
480+
479481
constructor(
480482
readonly sourceFiles: ReadonlyArray<SourceFile>,
481483
/** True if we're searching for constructor references. */
@@ -484,7 +486,13 @@ namespace ts.FindAllReferences.Core {
484486
readonly cancellationToken: CancellationToken,
485487
readonly searchMeaning: SemanticMeaning,
486488
readonly options: Options,
487-
private readonly result: Push<SymbolAndEntries>) {}
489+
private readonly result: Push<SymbolAndEntries>) {
490+
this.includedSourceFiles = arrayToSet(sourceFiles, s => s.fileName);
491+
}
492+
493+
includesSourceFile(sourceFile: SourceFile): boolean {
494+
return this.includedSourceFiles.has(sourceFile.fileName);
495+
}
488496

489497
private importTracker: ImportTracker | undefined;
490498
/** Gets every place to look for references of an exported symbols. See `ImportsResult` in `importTracker.ts` for more documentation. */
@@ -586,7 +594,10 @@ namespace ts.FindAllReferences.Core {
586594
// Go to the symbol we imported from and find references for it.
587595
function searchForImportedSymbol(symbol: Symbol, state: State): void {
588596
for (const declaration of symbol.declarations) {
589-
getReferencesInSourceFile(declaration.getSourceFile(), state.createSearch(declaration, symbol, ImportExport.Import), state);
597+
const exportingFile = declaration.getSourceFile();
598+
if (state.includesSourceFile(exportingFile)) {
599+
getReferencesInSourceFile(exportingFile, state.createSearch(declaration, symbol, ImportExport.Import), state);
600+
}
590601
}
591602
}
592603

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @Filename: /a.ts
4+
////export const [|x|] = 0;
5+
6+
// @Filename: /b.ts
7+
////import { [|x|] } from "./a";
8+
9+
const [r0, r1] = test.ranges();
10+
verify.documentHighlightsOf(r0, [r0], { filesToSearch: [r0.fileName] });
11+
verify.documentHighlightsOf(r1, [r1], { filesToSearch: [r1.fileName] });

0 commit comments

Comments
 (0)