Set declaration span only if its not same as own span

This commit is contained in:
Sheetal Nandi 2019-06-04 15:21:31 -07:00
parent cc1cb54e4b
commit 004488c0c9
7 changed files with 24 additions and 30 deletions

View file

@ -111,11 +111,6 @@ namespace ts.FindAllReferences {
case SyntaxKind.ImportClause:
return node.parent;
case SyntaxKind.JsxAttribute:
return (node as JsxAttribute).initializer === undefined ?
undefined :
node;
case SyntaxKind.BinaryExpression:
return isExpressionStatement(node.parent) ?
node.parent :
@ -129,7 +124,6 @@ namespace ts.FindAllReferences {
};
case SyntaxKind.PropertyAssignment:
// TODO(shkamat):: Should we show whole object literal instead?
case SyntaxKind.ShorthandPropertyAssignment:
return isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent) ?
getDeclarationForDeclarationSpan(
@ -137,15 +131,24 @@ namespace ts.FindAllReferences {
isBinaryExpression(node) || isForInOrOfStatement(node)
) as BinaryExpression | ForInOrOfStatement
) :
node.kind === SyntaxKind.PropertyAssignment ?
node :
undefined;
node;
default:
return node;
}
}
export function setDeclarationSpan(span: DocumentSpan, sourceFile: SourceFile, declaration?: DeclarationNode) {
if (declaration) {
const declarationSpan = isDeclarationNodeWithStartAndEnd(declaration) ?
getTextSpan(declaration.start, sourceFile, declaration.end) :
getTextSpan(declaration, sourceFile);
if (declarationSpan.start !== span.textSpan.start || declarationSpan.length !== span.textSpan.length) {
span.declarationSpan = declarationSpan;
}
}
}
export interface Options {
readonly findInStrings?: boolean;
readonly findInComments?: boolean;
@ -287,11 +290,7 @@ namespace ts.FindAllReferences {
textSpan: getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile),
displayParts
};
if (declaration) {
result.declarationSpan = isDeclarationNodeWithStartAndEnd(declaration) ?
getTextSpan(declaration.start, sourceFile, declaration.end) :
getTextSpan(declaration, sourceFile);
}
setDeclarationSpan(result, sourceFile, declaration);
return result;
}
@ -330,11 +329,7 @@ namespace ts.FindAllReferences {
else {
const sourceFile = entry.node.getSourceFile();
const result: DocumentSpan = { textSpan: getTextSpan(entry.node, sourceFile), fileName: sourceFile.fileName };
if (entry.declaration) {
result.declarationSpan = isDeclarationNodeWithStartAndEnd(entry.declaration) ?
getTextSpan(entry.declaration.start, sourceFile, entry.declaration.end) :
getTextSpan(entry.declaration, sourceFile);
}
setDeclarationSpan(result, sourceFile, entry.declaration);
return result;
}
}

View file

@ -281,12 +281,11 @@ namespace ts.GoToDefinition {
containerKind: undefined!, // TODO: GH#18217
containerName,
};
const declarationNode = FindAllReferences.getDeclarationForDeclarationSpan(declaration);
if (declarationNode) {
result.declarationSpan = FindAllReferences.isDeclarationNodeWithStartAndEnd(declarationNode) ?
createTextSpanFromNode(declarationNode.start, sourceFile, declarationNode.end) :
createTextSpanFromNode(declarationNode, sourceFile);
}
FindAllReferences.setDeclarationSpan(
result,
sourceFile,
FindAllReferences.getDeclarationForDeclarationSpan(declaration)
);
return result;
}

View file

@ -117,7 +117,7 @@
////array.forEach(
////
////
////function([|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 43 |}str|]) {
////function([|{| "isWriteAccess": true, "isDefinition": true |}str|]) {
////
////
////

View file

@ -1,6 +1,6 @@
/// <reference path='fourslash.ts' />
////function f([|{[|{| "declarationRangeIndex": 0 |}a|]}: {[|{| "declarationRangeIndex": 2 |}a|]}|]) {
////function f([|{[|{| "declarationRangeIndex": 0 |}a|]}: {[|a|]}|]) {
//// f({[|a|]});
////}

View file

@ -5,7 +5,7 @@
//// set: function (x) {
//// this._x = x;
//// },
//// copy: function ([|{| "declarationRangeIndex": 0 |}x|]) {
//// copy: function ([|x|]) {
//// this._x = [|x|].prop;
//// }
////};

View file

@ -5,7 +5,7 @@
//// set: function (x) {
//// this._x = x;
//// },
//// copy: function ([|{| "declarationRangeIndex": 0 |}x|]) {
//// copy: function ([|x|]) {
//// this._x = [|x|].prop;
//// }
////};

View file

@ -1,6 +1,6 @@
/// <reference path='fourslash.ts'/>
////function f([|{| "declarationRangeIndex": 0 |}this|]) {
////function f([|this|]) {
//// return [|this|];
////}
////this/**/;