mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 10:46:28 -05:00
findAllReferences: Consistently use getTextSpan (#22847)
* findAllReferences: Consistently use getTextSpan * Remove initializer
This commit is contained in:
@@ -132,15 +132,8 @@ namespace ts.FindAllReferences {
|
||||
|
||||
const { node, name, kind, displayParts } = info;
|
||||
const sourceFile = node.getSourceFile();
|
||||
return {
|
||||
containerKind: ScriptElementKind.unknown,
|
||||
containerName: "",
|
||||
fileName: sourceFile.fileName,
|
||||
kind,
|
||||
name,
|
||||
textSpan: createTextSpanFromNode(node, sourceFile),
|
||||
displayParts
|
||||
};
|
||||
const textSpan = getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile);
|
||||
return { containerKind: ScriptElementKind.unknown, containerName: "", fileName: sourceFile.fileName, kind, name, textSpan, displayParts };
|
||||
}
|
||||
|
||||
function getDefinitionKindAndDisplayParts(symbol: Symbol, checker: TypeChecker, node: Node): { displayParts: SymbolDisplayPart[], kind: ScriptElementKind } {
|
||||
@@ -218,8 +211,8 @@ namespace ts.FindAllReferences {
|
||||
return { fileName, span };
|
||||
}
|
||||
|
||||
function getTextSpan(node: Node): TextSpan {
|
||||
let start = node.getStart();
|
||||
function getTextSpan(node: Node, sourceFile?: SourceFile): TextSpan {
|
||||
let start = node.getStart(sourceFile);
|
||||
let end = node.getEnd();
|
||||
if (node.kind === SyntaxKind.StringLiteral) {
|
||||
start += 1;
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////interface I {
|
||||
//// [|["[|{| "isDefinition": true |}prop1|]"]|]: () => void;
|
||||
//// ["[|{| "isDefinition": true |}prop1|]"]: () => void;
|
||||
////}
|
||||
////
|
||||
////class C implements I {
|
||||
//// [|["[|{| "isDefinition": true |}prop1|]"]|]: any;
|
||||
//// ["[|{| "isDefinition": true |}prop1|]"]: any;
|
||||
////}
|
||||
////
|
||||
////var x: I = {
|
||||
//// [|["[|{| "isDefinition": true |}prop1|]"]|]: function () { },
|
||||
//// ["[|{| "isDefinition": true |}prop1|]"]: function () { },
|
||||
////}
|
||||
|
||||
// TODO: GH#22690
|
||||
const [r0Big, r0, r1Big, r1, r2Big, r2] = test.ranges();
|
||||
const [r0, r1, r2] = test.ranges();
|
||||
verify.referenceGroups([r0, r1], [
|
||||
{ definition: { text: '(property) I["prop1"]: () => void', range: r0Big }, ranges: [r0, r2] },
|
||||
{ definition: { text: '(property) C["prop1"]: any', range: r1Big }, ranges: [r1] },
|
||||
{ definition: { text: '(property) I["prop1"]: () => void', range: r0 }, ranges: [r0, r2] },
|
||||
{ definition: { text: '(property) C["prop1"]: any', range: r1 }, ranges: [r1] },
|
||||
]);
|
||||
verify.referenceGroups(r2, [
|
||||
{ definition: { text: '(property) I["prop1"]: () => void', range: r0Big }, ranges: [r0] },
|
||||
{ definition: { text: '(property) C["prop1"]: any', range: r1Big }, ranges: [r1] },
|
||||
{ definition: { text: '(property) ["prop1"]: () => void', range: r2Big }, ranges: [r2] },
|
||||
{ definition: { text: '(property) I["prop1"]: () => void', range: r0 }, ranges: [r0] },
|
||||
{ definition: { text: '(property) C["prop1"]: any', range: r1 }, ranges: [r1] },
|
||||
{ definition: { text: '(property) ["prop1"]: () => void', range: r2 }, ranges: [r2] },
|
||||
]);
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////interface I {
|
||||
//// [|[[|{| "isDefinition": true |}42|]]|](): void;
|
||||
//// [[|{| "isDefinition": true |}42|]](): void;
|
||||
////}
|
||||
////
|
||||
////class C implements I {
|
||||
//// [|[[|{| "isDefinition": true |}42|]]|]: any;
|
||||
//// [[|{| "isDefinition": true |}42|]]: any;
|
||||
////}
|
||||
////
|
||||
////var x: I = {
|
||||
//// [|["[|{| "isDefinition": true |}42|]"]|]: function () { }
|
||||
//// ["[|{| "isDefinition": true |}42|]"]: function () { }
|
||||
////}
|
||||
|
||||
// TODO: GH#22690
|
||||
const [r0Big, r0, r1Big, r1, r2Big, r2] = test.ranges();
|
||||
const [r0, r1, r2] = test.ranges();
|
||||
verify.referenceGroups([r0, r1], [
|
||||
{ definition: { text: '(method) I[42](): void', range: r0Big }, ranges: [r0, r2] },
|
||||
{ definition: { text: '(property) C[42]: any', range: r1Big }, ranges: [r1] },
|
||||
{ definition: { text: '(method) I[42](): void', range: r0 }, ranges: [r0, r2] },
|
||||
{ definition: { text: '(property) C[42]: any', range: r1 }, ranges: [r1] },
|
||||
]);
|
||||
verify.referenceGroups(r2, [
|
||||
{ definition: { text: '(method) I[42](): void', range: r0Big }, ranges: [r0] },
|
||||
{ definition: { text: '(property) C[42]: any', range: r1Big }, ranges: [r1] },
|
||||
{ definition: { text: '(property) ["42"]: () => void', range: r2Big }, ranges: [r2] },
|
||||
{ definition: { text: '(method) I[42](): void', range: r0 }, ranges: [r0] },
|
||||
{ definition: { text: '(property) C[42]: any', range: r1 }, ranges: [r1] },
|
||||
{ definition: { text: '(property) ["42"]: () => void', range: r2 }, ranges: [r2] },
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user