implementations: Use declaration name for the span (#24537)

* implementations: Use declaration name for the span

* Always get name in nodeEntry
This commit is contained in:
Andy
2018-05-31 13:32:02 -07:00
committed by GitHub
parent 997991fdcb
commit 9d42ab983d
48 changed files with 111 additions and 126 deletions

View File

@@ -24,7 +24,7 @@ namespace ts.FindAllReferences {
textSpan: TextSpan;
}
export function nodeEntry(node: Node, isInString?: true): NodeEntry {
return { type: "node", node, isInString };
return { type: "node", node: (node as NamedDeclaration).name || node, isInString };
}
export interface Options {
@@ -1096,7 +1096,7 @@ namespace ts.FindAllReferences.Core {
function addImplementationReferences(refNode: Node, addReference: (node: Node) => void, state: State): void {
// Check if we found a function/propertyAssignment/method with an implementation or initializer
if (isDeclarationName(refNode) && isImplementation(refNode.parent)) {
addReference(refNode.parent);
addReference(refNode);
return;
}

View File

@@ -3,7 +3,7 @@
// Should handle calls made on members declared in a class
//// class Bar {
//// [|{|"parts": ["(","method",")"," ","Bar",".","hello","(",")",":"," ","void"], "kind": "method"|}hello() {}|]
//// [|{|"parts": ["(","method",")"," ","Bar",".","hello","(",")",":"," ","void"], "kind": "method"|}hello|]() {}
//// }
////
//// new Bar().hel/*reference*/lo;

View File

@@ -7,7 +7,7 @@
//// }
////
//// class Bar extends AbstractBar{
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// function whatever(x: AbstractBar) {

View File

@@ -3,7 +3,7 @@
// Should handle calls made on members of an enum
//// enum Foo {
//// [|Foo1 = function initializer() { return 5 } ()|],
//// [|Foo1|] = function initializer() { return 5 } (),
//// Foo2 = 6
//// }
////

View File

@@ -2,10 +2,10 @@
// Should handle calls made on enum name
//// [|enum Foo {
//// enum [|Foo|] {
//// Foo1 = function initializer() { return 5 } (),
//// Foo2 = 6
//// }|]
//// }
////
//// Fo/*reference*/o;

View File

@@ -6,19 +6,19 @@
//// he/*declaration*/llo: () => void
//// }
////
//// var bar: Foo = { [|hello: helloImpl|] };
//// var baz: Foo = { [|"hello": helloImpl|] };
//// var bar: Foo = { [|hello|]: helloImpl };
//// var baz: Foo = { "[|hello|]": helloImpl };
////
//// function helloImpl () {}
////
//// function whatever(x: Foo = { [|hello() {/**1*/}|] }) {
//// function whatever(x: Foo = { [|hello|]() {/**1*/} }) {
//// x.he/*function_call*/llo()
//// }
////
//// class Bar {
//// x: Foo = { [|hello() {/*2*/}|] }
//// x: Foo = { [|hello|]() {/*2*/} }
////
//// constructor(public f: Foo = { [|hello() {/**3*/}|] } ) {}
//// constructor(public f: Foo = { [|hello|]() {/**3*/} } ) {}
//// }
verify.allRangesAppearInImplementationList("function_call");

View File

@@ -8,7 +8,7 @@
//// }
////
//// class Bar implements Foo {
//// [|hello() {}|]
//// [|hello|]() {}
//// public sure() {}
//// }
////

View File

@@ -11,7 +11,7 @@
//// }
////
//// class Bar extends AbstractBar {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// function whatever(a: AbstractBar) {

View File

@@ -7,7 +7,7 @@
//// }
////
//// class Bar extends SuperBar {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// class SuperBar implements Foo {

View File

@@ -7,11 +7,11 @@
//// }
////
//// class Bar extends SuperBar {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// class SuperBar implements Foo {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// class OtherBar implements Foo {

View File

@@ -7,7 +7,7 @@
//// }
////
//// class SuperBar implements Foo {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// class Bar extends SuperBar {

View File

@@ -11,19 +11,19 @@
//// }
////
//// class Bar implements Foo {
//// [|hello() {}|]
//// [|hello|]() {}
//// someOtherFunction() {}
//// }
////
//// function createFoo(): Foo {
//// return {
//// [|hello() {}|],
//// [|hello|]() {},
//// someOtherFunction() {}
//// };
//// }
////
//// var y: Foo = {
//// [|hello() {}|],
//// [|hello|]() {},
//// someOtherFunction() {}
//// };
////

View File

@@ -7,7 +7,7 @@
//// }
////
//// class SuperBar implements Foo {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// class Bar extends SuperBar {
@@ -15,7 +15,7 @@
//// }
////
//// class SubBar extends Bar {
//// [|hello() {}|]
//// [|hello|]() {}
//// }

View File

@@ -20,7 +20,7 @@
//// }
////
//// class SuperBar extends MegaBar {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// class MegaBar implements Foo {

View File

@@ -16,7 +16,7 @@
//// }
////
//// class FooImpl implements Foo {
//// [|hello() {/**FooImpl*/}|]
//// [|hello|]() {/**FooImpl*/}
//// aloha() {}
//// }
////
@@ -25,12 +25,12 @@
//// }
////
//// class BarImpl implements Bar {
//// [|hello() {/**BarImpl*/}|]
//// [|hello|]() {/**BarImpl*/}
//// goodbye() {}
//// }
////
//// class FooAndBarImpl implements Foo, Bar {
//// [|hello() {/**FooAndBarImpl*/}|]
//// [|hello|]() {/**FooAndBarImpl*/}
//// aloha() {}
//// goodbye() {}
//// }

View File

@@ -6,7 +6,7 @@
//// hel/*reference*/lo(): void;
//// }
////
//// var x = <Foo> { [|hello: () => {}|] };
//// var y = <Foo> (((({ [|hello: () => {}|] }))));
//// var x = <Foo> { [|hello|]: () => {} };
//// var y = <Foo> (((({ [|hello|]: () => {} }))));
verify.allRangesAppearInImplementationList("reference");

View File

@@ -6,17 +6,17 @@
//// hello: number
//// }
////
//// var bar: Foo = { [|hello: 5|] };
//// var bar: Foo = { [|hello|]: 5 };
////
////
//// function whatever(x: Foo = { [|hello: 5 * 9|] }) {
//// function whatever(x: Foo = { [|hello|]: 5 * 9 }) {
//// x.he/*reference*/llo
//// }
////
//// class Bar {
//// x: Foo = { [|hello: 6|] }
//// x: Foo = { [|hello|]: 6 }
////
//// constructor(public f: Foo = { [|hello: 7|] } ) {}
//// constructor(public f: Foo = { [|hello|]: 7 } ) {}
//// }
verify.allRangesAppearInImplementationList("reference");

View File

@@ -5,7 +5,7 @@
//// interface Foo { hello: number }
////
//// class Bar implements Foo {
//// [|hello = 5 * 9;|]
//// [|hello|] = 5 * 9;
//// }
////
//// function whatever(foo: Foo) {

View File

@@ -2,13 +2,13 @@
//// interface Fo/*interface_definition*/o { hello(): void }
////
//// [|class SuperBar implements Foo {
//// class [|SuperBar|] implements Foo {
//// hello () {}
//// }|]
//// }
////
//// [|abstract class AbstractBar implements Foo {
//// abstract class [|AbstractBar|] implements Foo {
//// abstract hello (): void;
//// }|]
//// }
////
//// class Bar extends SuperBar {
//// }

View File

@@ -20,11 +20,11 @@
//// let x8: Foo[] = [|[{ hello () { /**arrayType*/} }]|];
//// let x9: { y: Foo } = [|{ y: { hello () { /**typeLiteral*/} } }|];
//// let x10 = [|{|"parts": ["(","anonymous local class",")"], "kind": "local class"|}class implements Foo { hello() {} }|]
//// let x11 = [|{|"parts": ["(","local class",")"," ","C"], "kind": "local class"|}class C implements Foo { hello() {} }|]
//// let x11 = class [|{|"parts": ["(","local class",")"," ","C"], "kind": "local class"|}C|] implements Foo { hello() {} }
////
//// // Should not do anything for type predicates
//// function isFoo(a: any): a is Foo {
//// return true;
//// }
verify.allRangesAppearInImplementationList("interface_definition");
verify.allRangesAppearInImplementationList("interface_definition");

View File

@@ -11,7 +11,7 @@
//// interface C extends B, A {}
////
//// class X implements B {
//// [|hello() {}|]
//// [|hello|]() {}
//// }
////
//// function someFunction(d : A) {

View File

@@ -3,6 +3,6 @@
// Should return definition of locally declared functions
//// he/*function_call*/llo();
//// [|function hello() {}|]
//// function [|hello|]() {}
verify.allRangesAppearInImplementationList("function_call");
verify.allRangesAppearInImplementationList("function_call");

View File

@@ -2,7 +2,7 @@
// Should return the defintion of locally defined variables
//// const [|hello = function() {}|];
//// const [|hello|] = function() {};
//// he/*function_call*/llo();
verify.allRangesAppearInImplementationList("function_call");
verify.allRangesAppearInImplementationList("function_call");

View File

@@ -1,8 +1,8 @@
/// <reference path='fourslash.ts'/>
//// const x = { [|hello: () => {}|] };
//// const x = { [|hello|]: () => {} };
////
//// x.he/*function_call*/llo();
////
verify.allRangesAppearInImplementationList("function_call");
verify.allRangesAppearInImplementationList("function_call");

View File

@@ -2,11 +2,11 @@
// Should return the definition when invoked on variable assignment
//// let [|he/*local_var*/llo = {}|];
//// let [|he/*local_var*/llo|] = {};
////
//// x.hello();
////
//// hello = {};
////
verify.allRangesAppearInImplementationList("local_var");
verify.allRangesAppearInImplementationList("local_var");

View File

@@ -2,9 +2,9 @@
// Should return definition of function when invoked on the declaration
//// [|function he/*local_var*/llo() {}|]
//// function [|he/*local_var*/llo|]() {}
////
//// hello();
////
verify.allRangesAppearInImplementationList("local_var");
verify.allRangesAppearInImplementationList("local_var");

View File

@@ -6,7 +6,7 @@
//// public hello() {}
//// }
////
//// var [|someVar = new Bar()|];
//// var [|someVar|] = new Bar();
//// someVa/*reference*/r.hello();
verify.allRangesAppearInImplementationList("reference");
verify.allRangesAppearInImplementationList("reference");

View File

@@ -2,7 +2,7 @@
// Should be able to go to ambient variable declarations
//// declare var [|someVar: string|];
//// declare var [|someVar|]: string;
//// someVa/*reference*/r
verify.allRangesAppearInImplementationList("reference");
verify.allRangesAppearInImplementationList("reference");

View File

@@ -2,7 +2,7 @@
// Should be able to go to ambient function declarations
//// [|declare function someFunction(): () => void;|]
//// declare function [|someFunction|](): () => void;
//// someFun/*reference*/ction();
verify.allRangesAppearInImplementationList("reference");
verify.allRangesAppearInImplementationList("reference");

View File

@@ -2,7 +2,7 @@
// Should be able to go to ambient function declarations
//// [|declare function someFunction(): () => void;|]
//// declare function [|someFunction|](): () => void;
//// someFun/*reference*/ction();
verify.allRangesAppearInImplementationList("reference");
verify.allRangesAppearInImplementationList("reference");

View File

@@ -2,11 +2,11 @@
// Should handle namespace and module implementations
//// /*implementation0*/namespace Foo {
//// namespace /*implementation0*/Foo {
//// export function hello() {}
//// }
////
//// /*implementation1*/module Bar {
//// module /*implementation1*/Bar {
//// export function sure() {}
//// }
////

View File

@@ -3,7 +3,7 @@
// Should handle property access expressions on namespaces
//// namespace Foo {
//// [|export function hello() {}|]
//// export function [|hello|]() {}
//// }
////
//// Foo.hell/*reference*/o();

View File

@@ -3,7 +3,7 @@
// Should handle property access expressions on namespaces
//// module Foo {
//// [|export function hello() {}|]
//// export function [|hello|]() {}
//// }
////
//// Foo.hell/*reference*/o();

View File

@@ -7,14 +7,14 @@
//// hello(): void;
//// }
////
//// [|class BarImpl implements Bar {
//// class [|BarImpl|] implements Bar {
//// hello() {}
//// }|]
//// }
//// }
////
//// [|class Baz implements Foo.Bar {
//// class [|Baz|] implements Foo.Bar {
//// hello() {}
//// }|]
//// }
////
//// var someVar1 : Foo.Bar = [|{ hello: () => {/**1*/} }|];
////

View File

@@ -7,14 +7,14 @@
//// hello(): void;
//// }
////
//// [|class BarImpl implements Bar {
//// class [|BarImpl|] implements Bar {
//// hello() {}
//// }|]
//// }
//// }
////
//// [|class Baz implements Foo.Bar {
//// class [|Baz|] implements Foo.Bar {
//// hello() {}
//// }|]
//// }
////
//// var someVar1 : Foo.Bar = [|{ hello: () => {/**1*/} }|];
////

View File

@@ -2,11 +2,11 @@
// Should handle namespace and module implementations with qualified names
//// /*implementation0*/namespace Foo./*implementation2*/Baz {
//// namespace /*implementation0*/Foo./*implementation2*/Baz {
//// export function hello() {}
//// }
////
//// /*implementation1*/module Bar./*implementation3*/Baz {
//// module /*implementation1*/Bar./*implementation3*/Baz {
//// export function sure() {}
//// }
////

View File

@@ -2,9 +2,9 @@
// Should handle type queries
//// [|namespace F/*declaration*/oo {
//// namespace [|F/*declaration*/oo|] {
//// declare function hello(): void;
//// }|]
//// }
////
////
//// let x: typeof Foo = [|{ hello() {} }|];

View File

@@ -14,7 +14,7 @@
//// Foo: FooConstructor;
//// }
////
//// var x = /*classExpression*/class Foo {
//// var x = class /*classExpression*/Foo {
//// createBarInClassExpression(): Bar {
//// return {
//// Fo/*classExpressionRef*/o
@@ -24,7 +24,7 @@
//// someFunction() {}
//// }
////
//// /*declaredClass*/class Foo {
//// class /*declaredClass*/Foo {
////
//// }
////
@@ -40,4 +40,4 @@ verify.caretAtMarker("classExpression");
goTo.marker("declaredClassRef");
goTo.implementation();
verify.caretAtMarker("declaredClass");
verify.caretAtMarker("declaredClass");

View File

@@ -15,7 +15,7 @@
//// }
////
//// // Class expression that gets used in a bar implementation
//// var x = [|class Foo {
//// var x = class [|Foo|] {
//// createBarInClassExpression(): Bar {
//// return {
//// Foo
@@ -23,13 +23,13 @@
//// }
////
//// someFunction() {}
//// }|];
//// };
////
//// // Class declaration that gets used in a bar implementation. This class has multiple definitions
//// // (the class declaration and the interface above), but we only want the class returned
//// [|class Foo {
//// class [|Foo|] {
////
//// }|]
//// }
////
//// function createBarUsingClassDeclaration(): Bar {
//// return {

View File

@@ -11,7 +11,7 @@
//// hello
//// };
////
//// [|function hello() {}|]
//// function [|hello|]() {}
//// }
////
//// function whatever(x: Foo) {

View File

@@ -2,9 +2,9 @@
// Should go to super class declaration when invoked on a super call expression
//// [|class Foo {
//// class [|Foo|] {
//// constructor() {}
//// }|]
//// }
////
//// class Bar extends Foo {
//// constructor() {

View File

@@ -2,9 +2,9 @@
// Should go to the super class declaration when invoked on the super keyword in a property access expression
//// [|class Foo {
//// class [|Foo|] {
//// hello() {}
//// }|]
//// }
////
//// class Bar extends Foo {
//// hello() {

View File

@@ -2,12 +2,12 @@
// Should go to class declaration when invoked on this keyword in property access expression
//// [|class Bar extends Foo {
//// class [|Bar|] extends Foo {
//// hello() {
//// thi/*this_call*/s.whatever();
//// }
////
//// whatever() {}
//// }|]
//// }
verify.allRangesAppearInImplementationList("this_call");
verify.allRangesAppearInImplementationList("this_call");

View File

@@ -2,10 +2,10 @@
// Should go to class declaration when invoked on a this type reference
//// [|class Bar extends Foo {
//// class [|Bar|] extends Foo {
//// hello(): th/*this_type*/is {
//// return this;
//// }
//// }|]
//// }
verify.allRangesAppearInImplementationList("this_type");
verify.allRangesAppearInImplementationList("this_type");

View File

@@ -3,13 +3,13 @@
// @Filename: /bar.ts
////import {Foo} from './foo'
////
////[|class A implements Foo {
////class [|A|] implements Foo {
//// func() {}
////}|]
////}
////
////[|class B implements Foo {
////class [|B|] implements Foo {
//// func() {}
////}|]
////}
// @Filename: /foo.ts
////export interface /**/Foo {

View File

@@ -1,8 +1,7 @@
/// <reference path="../fourslash.ts"/>
// @Filename: a.ts
//// interface Fo/*1*/o {}
//// /*2*/class Bar implements Foo {}
////interface Fo/*1*/o {}
////class /*2*/Bar implements Foo {}
goTo.marker('1');
goTo.implementation();

View File

@@ -1,9 +1,9 @@
/// <reference path='fourslash.ts' />
/// <reference path='../fourslash.ts' />
// @Filename: goToImplementationDifferentFile_Implementation.ts
//// /*fooClassImplementation*/class FooImpl implements Foo {}
//// class /*fooClassImplementation*/FooImpl implements Foo {}
////
//// /*barClassImplementation*/class Bar {
//// class /*barClassImplementation*/Bar {
//// /*barHelloFunctionImplementation*/hello() {}
//// }
////
@@ -15,21 +15,14 @@
////
//// x.hel/*barHelloFunctionReference*/lo();
////
//// /*thisImplementation*/class SomeClass {
//// class /*thisImplementation*/SomeClass {
//// someMethod() {
//// thi/*thisReference*/s.someMethod();
//// }
//// }
var markerList = [
"fooClass",
"barClass",
"barHelloFunction",
"this"
];
markerList.forEach((marker) => {
for (const marker of ["fooClass", "barClass", "barHelloFunction", "this"]) {
goTo.marker(marker + 'Reference');
goTo.implementation();
verify.caretAtMarker(marker + 'Implementation');
});
};

View File

@@ -1,9 +1,9 @@
/// <reference path='fourslash.ts' />
/// <reference path='../fourslash.ts' />
// @Filename: goToImplementationDifferentFile_Implementation.ts
//// /*fooClassImplementation*/class FooImpl implements Foo {}
//// class /*fooClassImplementation*/FooImpl implements Foo {}
////
//// /*barClassImplementation*/class Bar {
//// class /*barClassImplementation*/Bar {
//// /*barHelloFunctionImplementation*/hello() {}
//// }
////
@@ -15,21 +15,14 @@
////
//// x.hel/*barHelloFunctionReference*/lo();
////
//// /*thisImplementation*/class SomeClass {
//// class /*thisImplementation*/SomeClass {
//// someMethod() {
//// thi/*thisReference*/s.someMethod();
//// }
//// }
var markerList = [
"fooClass",
"barClass",
"barHelloFunction",
"this"
];
markerList.forEach((marker) => {
for (const marker of ["fooClass", "barClass", "barHelloFunction", "this"]) {
goTo.marker(marker + 'Reference');
goTo.implementation();
verify.caretAtMarker(marker + 'Implementation');
});
};