Skip to content

Commit 4f16560

Browse files
author
Andy
authored
findAllReferences: Consistently use getTextSpan (microsoft#22847)
* findAllReferences: Consistently use getTextSpan * Remove initializer
1 parent ddb7bb2 commit 4f16560

3 files changed

Lines changed: 22 additions & 31 deletions

File tree

src/services/findAllReferences.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,8 @@ namespace ts.FindAllReferences {
132132

133133
const { node, name, kind, displayParts } = info;
134134
const sourceFile = node.getSourceFile();
135-
return {
136-
containerKind: ScriptElementKind.unknown,
137-
containerName: "",
138-
fileName: sourceFile.fileName,
139-
kind,
140-
name,
141-
textSpan: createTextSpanFromNode(node, sourceFile),
142-
displayParts
143-
};
135+
const textSpan = getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile);
136+
return { containerKind: ScriptElementKind.unknown, containerName: "", fileName: sourceFile.fileName, kind, name, textSpan, displayParts };
144137
}
145138

146139
function getDefinitionKindAndDisplayParts(symbol: Symbol, checker: TypeChecker, node: Node): { displayParts: SymbolDisplayPart[], kind: ScriptElementKind } {
@@ -218,8 +211,8 @@ namespace ts.FindAllReferences {
218211
return { fileName, span };
219212
}
220213

221-
function getTextSpan(node: Node): TextSpan {
222-
let start = node.getStart();
214+
function getTextSpan(node: Node, sourceFile?: SourceFile): TextSpan {
215+
let start = node.getStart(sourceFile);
223216
let end = node.getEnd();
224217
if (node.kind === SyntaxKind.StringLiteral) {
225218
start += 1;
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
/// <reference path='fourslash.ts'/>
22

33
////interface I {
4-
//// [|["[|{| "isDefinition": true |}prop1|]"]|]: () => void;
4+
//// ["[|{| "isDefinition": true |}prop1|]"]: () => void;
55
////}
66
////
77
////class C implements I {
8-
//// [|["[|{| "isDefinition": true |}prop1|]"]|]: any;
8+
//// ["[|{| "isDefinition": true |}prop1|]"]: any;
99
////}
1010
////
1111
////var x: I = {
12-
//// [|["[|{| "isDefinition": true |}prop1|]"]|]: function () { },
12+
//// ["[|{| "isDefinition": true |}prop1|]"]: function () { },
1313
////}
1414

15-
// TODO: GH#22690
16-
const [r0Big, r0, r1Big, r1, r2Big, r2] = test.ranges();
15+
const [r0, r1, r2] = test.ranges();
1716
verify.referenceGroups([r0, r1], [
18-
{ definition: { text: '(property) I["prop1"]: () => void', range: r0Big }, ranges: [r0, r2] },
19-
{ definition: { text: '(property) C["prop1"]: any', range: r1Big }, ranges: [r1] },
17+
{ definition: { text: '(property) I["prop1"]: () => void', range: r0 }, ranges: [r0, r2] },
18+
{ definition: { text: '(property) C["prop1"]: any', range: r1 }, ranges: [r1] },
2019
]);
2120
verify.referenceGroups(r2, [
22-
{ definition: { text: '(property) I["prop1"]: () => void', range: r0Big }, ranges: [r0] },
23-
{ definition: { text: '(property) C["prop1"]: any', range: r1Big }, ranges: [r1] },
24-
{ definition: { text: '(property) ["prop1"]: () => void', range: r2Big }, ranges: [r2] },
21+
{ definition: { text: '(property) I["prop1"]: () => void', range: r0 }, ranges: [r0] },
22+
{ definition: { text: '(property) C["prop1"]: any', range: r1 }, ranges: [r1] },
23+
{ definition: { text: '(property) ["prop1"]: () => void', range: r2 }, ranges: [r2] },
2524
]);
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
/// <reference path='fourslash.ts'/>
22

33
////interface I {
4-
//// [|[[|{| "isDefinition": true |}42|]]|](): void;
4+
//// [[|{| "isDefinition": true |}42|]](): void;
55
////}
66
////
77
////class C implements I {
8-
//// [|[[|{| "isDefinition": true |}42|]]|]: any;
8+
//// [[|{| "isDefinition": true |}42|]]: any;
99
////}
1010
////
1111
////var x: I = {
12-
//// [|["[|{| "isDefinition": true |}42|]"]|]: function () { }
12+
//// ["[|{| "isDefinition": true |}42|]"]: function () { }
1313
////}
1414

15-
// TODO: GH#22690
16-
const [r0Big, r0, r1Big, r1, r2Big, r2] = test.ranges();
15+
const [r0, r1, r2] = test.ranges();
1716
verify.referenceGroups([r0, r1], [
18-
{ definition: { text: '(method) I[42](): void', range: r0Big }, ranges: [r0, r2] },
19-
{ definition: { text: '(property) C[42]: any', range: r1Big }, ranges: [r1] },
17+
{ definition: { text: '(method) I[42](): void', range: r0 }, ranges: [r0, r2] },
18+
{ definition: { text: '(property) C[42]: any', range: r1 }, ranges: [r1] },
2019
]);
2120
verify.referenceGroups(r2, [
22-
{ definition: { text: '(method) I[42](): void', range: r0Big }, ranges: [r0] },
23-
{ definition: { text: '(property) C[42]: any', range: r1Big }, ranges: [r1] },
24-
{ definition: { text: '(property) ["42"]: () => void', range: r2Big }, ranges: [r2] },
21+
{ definition: { text: '(method) I[42](): void', range: r0 }, ranges: [r0] },
22+
{ definition: { text: '(property) C[42]: any', range: r1 }, ranges: [r1] },
23+
{ definition: { text: '(property) ["42"]: () => void', range: r2 }, ranges: [r2] },
2524
]);

0 commit comments

Comments
 (0)