Add support for Call Hierarchies in language server (#35176)

* Add support for Call Hierarchies in language server

* Use baselines for callHierarchy tests

* Clean up commented code

* Support multiple hierarchy items when an implementation can't be found

* Use optional chaining in a few places

* Use getFileAndProject
This commit is contained in:
Ron Buckton
2019-12-22 13:25:09 -08:00
committed by GitHub
parent 114dad7f56
commit 6c413e0bbb
55 changed files with 2712 additions and 55 deletions

View File

@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />
//// function foo() {
//// new C().bar;
//// }
////
//// class C {
//// get /**/bar() {
//// return baz();
//// }
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
//// function foo() {
//// bar();
//// }
////
//// function /**/bar() {
//// new Baz();
//// }
////
//// class Baz {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
//// function foo() {
//// bar();
//// }
////
//// const /**/bar = () => {
//// baz();
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />
//// function foo() {
//// new Bar();
//// }
////
//// const /**/Bar = class {
//// constructor() {
//// baz();
//// }
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
//// function foo() {
//// bar();
//// }
////
//// const /**/bar = function () {
//// baz();
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @experimentalDecorators: true
//// @bar
//// class Foo {
//// }
////
//// function /**/bar() {
//// baz();
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,21 @@
/// <reference path="fourslash.ts" />
// @filename: main.ts
//// import Bar from "./other";
////
//// function foo() {
//// new Bar();
//// }
// @filename: other.ts
//// export /**/default class {
//// constructor() {
//// baz();
//// }
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts" />
// @filename: main.ts
//// import bar from "./other";
////
//// function foo() {
//// bar();
//// }
// @filename: other.ts
//// export /**/default function () {
//// baz();
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts" />
// @filename: main.ts
//// import bar = require("./other");
////
//// function foo() {
//// bar();
//// }
// @filename: other.ts
//// export = /**/function () {
//// baz();
//// }
////
//// function baz() {
//// }
// NOTE: exported function is unnamed, so we expand the item to the entire file...
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts" />
//// foo();
//// function /**/foo() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts" />
//// function foo() {
//// bar();
//// }
////
//// function /**/bar() {
//// baz();
//// quxx();
//// baz();
//// }
////
//// function baz() {
//// }
////
//// function quxx() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @filename: a.d.ts
//// declare function foo(x?: number): void;
// @filename: b.d.ts
//// declare function foo(x?: string): void;
//// declare function foo(x?: boolean): void;
// @filename: main.ts
//// function bar() {
//// /**/foo();
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @filename: a.d.ts
//// declare function /**/foo(x?: number): void;
// @filename: b.d.ts
//// declare function foo(x?: string): void;
//// declare function foo(x?: boolean): void;
// @filename: main.ts
//// function bar() {
//// foo();
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @filename: a.d.ts
//// declare function foo(x?: number): void;
// @filename: b.d.ts
//// declare function /**/foo(x?: string): void;
//// declare function foo(x?: boolean): void;
// @filename: main.ts
//// function bar() {
//// foo();
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @filename: a.d.ts
//// declare function foo(x?: number): void;
// @filename: b.d.ts
//// declare function foo(x?: string): void;
//// declare function /**/foo(x?: boolean): void;
// @filename: main.ts
//// function bar() {
//// foo();
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />
// @filename: a.d.ts
//// declare function foo(x?: number): void;
// @filename: b.d.ts
//// declare function foo(x?: string): void;
//// declare function foo(x?: boolean): void;
// @filename: main.ts
//// function /**/bar() {
//// foo();
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />
//// interface I {
//// /**/foo(): void;
//// }
////
//// const obj: I = { foo() {} };
////
//// obj.foo();
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,17 @@
/// <reference path="fourslash.ts" />
// @jsx: preserve
// @filename: main.tsx
//// function foo() {
//// return <Bar/>;
//// }
////
//// function /**/Bar() {
//// baz();
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -0,0 +1,15 @@
/// <reference path="fourslash.ts" />
//// function foo() {
//// bar`a${1}b`;
//// }
////
//// function /**/bar(array: TemplateStringsArray, ...args: any[]) {
//// baz();
//// }
////
//// function baz() {
//// }
goTo.marker();
verify.baselineCallHierarchy();

View File

@@ -383,6 +383,7 @@ declare namespace FourSlashInterface {
readonly newFileContents: { readonly [fileName: string]: string };
readonly preferences?: UserPreferences;
}): void;
baselineCallHierarchy(): void;
moveToNewFile(options: {
readonly newFileContents: { readonly [fileName: string]: string };
readonly preferences?: UserPreferences;
@@ -773,4 +774,4 @@ declare namespace completion {
export const statementKeywordsWithTypes: ReadonlyArray<Entry>;
export const statementKeywords: ReadonlyArray<Entry>;
export const statementInJsKeywords: ReadonlyArray<Entry>;
}
}