Skip to content

Commit bc285aa

Browse files
author
Andy
authored
findAllReferences: Mark *every* search symbol as seen, not just search.symbol (#23451)
1 parent 8175d29 commit bc285aa

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/services/findAllReferences.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ namespace ts.FindAllReferences.Core {
424424
readonly text: string;
425425
readonly escapedText: __String;
426426
/** Only set if `options.implementations` is true. These are the symbols checked to get the implementations of a property access. */
427-
readonly parents: Symbol[] | undefined;
427+
readonly parents: ReadonlyArray<Symbol> | undefined;
428+
readonly allSearchSymbols: ReadonlyArray<Symbol>;
428429

429430
/**
430431
* Whether a symbol is in the search set.
@@ -500,14 +501,11 @@ namespace ts.FindAllReferences.Core {
500501
// here appears to be intentional).
501502
const {
502503
text = stripQuotes(unescapeLeadingUnderscores((getLocalSymbolForExportDefault(symbol) || symbol).escapedName)),
503-
allSearchSymbols,
504+
allSearchSymbols = [symbol],
504505
} = searchOptions;
505506
const escapedText = escapeLeadingUnderscores(text);
506507
const parents = this.options.implementations && getParentSymbolsOfPropertyAccess(location, symbol, this.checker);
507-
return {
508-
symbol, comingFrom, text, escapedText, parents,
509-
includes: referenceSymbol => allSearchSymbols ? contains(allSearchSymbols, referenceSymbol) : referenceSymbol === symbol,
510-
};
508+
return { symbol, comingFrom, text, escapedText, parents, allSearchSymbols, includes: sym => contains(allSearchSymbols, sym) };
511509
}
512510

513511
private readonly symbolIdToReferences: Entry[][] = [];
@@ -534,13 +532,17 @@ namespace ts.FindAllReferences.Core {
534532
}
535533

536534
// Source file ID → symbol ID → Whether the symbol has been searched for in the source file.
537-
private readonly sourceFileToSeenSymbols: true[][] = [];
535+
private readonly sourceFileToSeenSymbols: Map<true>[] = [];
538536
/** Returns `true` the first time we search for a symbol in a file and `false` afterwards. */
539-
markSearchedSymbol(sourceFile: SourceFile, symbol: Symbol): boolean {
537+
markSearchedSymbols(sourceFile: SourceFile, symbols: ReadonlyArray<Symbol>): boolean {
540538
const sourceId = getNodeId(sourceFile);
541-
const symbolId = getSymbolId(symbol);
542-
const seenSymbols = this.sourceFileToSeenSymbols[sourceId] || (this.sourceFileToSeenSymbols[sourceId] = []);
543-
return !seenSymbols[symbolId] && (seenSymbols[symbolId] = true);
539+
const seenSymbols = this.sourceFileToSeenSymbols[sourceId] || (this.sourceFileToSeenSymbols[sourceId] = createMap<true>());
540+
541+
let anyNewSymbols = false;
542+
for (const sym of symbols) {
543+
anyNewSymbols = addToSeen(seenSymbols, getSymbolId(sym)) || anyNewSymbols;
544+
}
545+
return anyNewSymbols;
544546
}
545547
}
546548

@@ -804,7 +806,7 @@ namespace ts.FindAllReferences.Core {
804806
* searchLocation: a node where the search value
805807
*/
806808
function getReferencesInContainer(container: Node, sourceFile: SourceFile, search: Search, state: State, addReferencesHere: boolean): void {
807-
if (!state.markSearchedSymbol(sourceFile, search.symbol)) {
809+
if (!state.markSearchedSymbols(sourceFile, search.allSearchSymbols)) {
808810
return;
809811
}
810812

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/// <reference path='fourslash.ts' />
22

33
// @Filename: foo.ts
4-
//// export function [|bar|]() { return "bar"; }
5-
6-
//// import('./foo').then(({ [|bar|] }) => undefined);
4+
////export function [|{| "isWriteAccess": true, "isDefinition": true |}bar|]() { return "bar"; }
5+
////import('./foo').then(({ [|{| "isWriteAccess": true, "isDefinition": true |}bar|] }) => undefined);
76

87
const [r0, r1] = test.ranges();
9-
// This is because bindingElement at r1 are both name and value
10-
verify.referencesOf(r0, [r1, r0, r1, r0]);
11-
verify.referencesOf(r1, [r0, r1, r1, r0]);
12-
verify.renameLocations(r0, [r0, r1]);
13-
verify.renameLocations(r1, [r1, r0, r0, r1]);
8+
verify.referenceGroups(r0, [{ definition: "function bar(): string", ranges: [r0, r1] }]);
9+
verify.referenceGroups(r1, [
10+
{ definition: "function bar(): string", ranges: [r0] },
11+
{ definition: "var bar: () => string", ranges: [r1] },
12+
]);
13+
verify.rangesAreRenameLocations();

0 commit comments

Comments
 (0)