mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
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:
17
tests/cases/fourslash/callHierarchyAccessor.ts
Normal file
17
tests/cases/fourslash/callHierarchyAccessor.ts
Normal 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();
|
||||
15
tests/cases/fourslash/callHierarchyClass.ts
Normal file
15
tests/cases/fourslash/callHierarchyClass.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// function foo() {
|
||||
//// bar();
|
||||
//// }
|
||||
////
|
||||
//// function /**/bar() {
|
||||
//// new Baz();
|
||||
//// }
|
||||
////
|
||||
//// class Baz {
|
||||
//// }
|
||||
|
||||
goTo.marker();
|
||||
verify.baselineCallHierarchy();
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// function foo() {
|
||||
//// bar();
|
||||
//// }
|
||||
////
|
||||
//// const /**/bar = () => {
|
||||
//// baz();
|
||||
//// }
|
||||
////
|
||||
//// function baz() {
|
||||
//// }
|
||||
|
||||
goTo.marker();
|
||||
verify.baselineCallHierarchy();
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// function foo() {
|
||||
//// new Bar();
|
||||
//// }
|
||||
////
|
||||
//// const /**/Bar = class {
|
||||
//// constructor() {
|
||||
//// baz();
|
||||
//// }
|
||||
//// }
|
||||
////
|
||||
//// function baz() {
|
||||
//// }
|
||||
|
||||
goTo.marker();
|
||||
verify.baselineCallHierarchy();
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// function foo() {
|
||||
//// bar();
|
||||
//// }
|
||||
////
|
||||
//// const /**/bar = function () {
|
||||
//// baz();
|
||||
//// }
|
||||
////
|
||||
//// function baz() {
|
||||
//// }
|
||||
|
||||
goTo.marker();
|
||||
verify.baselineCallHierarchy();
|
||||
16
tests/cases/fourslash/callHierarchyDecorator.ts
Normal file
16
tests/cases/fourslash/callHierarchyDecorator.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @experimentalDecorators: true
|
||||
//// @bar
|
||||
//// class Foo {
|
||||
//// }
|
||||
////
|
||||
//// function /**/bar() {
|
||||
//// baz();
|
||||
//// }
|
||||
////
|
||||
//// function baz() {
|
||||
//// }
|
||||
|
||||
goTo.marker();
|
||||
verify.baselineCallHierarchy();
|
||||
21
tests/cases/fourslash/callHierarchyExportDefaultClass.ts
Normal file
21
tests/cases/fourslash/callHierarchyExportDefaultClass.ts
Normal 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();
|
||||
19
tests/cases/fourslash/callHierarchyExportDefaultFunction.ts
Normal file
19
tests/cases/fourslash/callHierarchyExportDefaultFunction.ts
Normal 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();
|
||||
20
tests/cases/fourslash/callHierarchyExportEqualsFunction.ts
Normal file
20
tests/cases/fourslash/callHierarchyExportEqualsFunction.ts
Normal 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();
|
||||
8
tests/cases/fourslash/callHierarchyFile.ts
Normal file
8
tests/cases/fourslash/callHierarchyFile.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// foo();
|
||||
//// function /**/foo() {
|
||||
//// }
|
||||
|
||||
goTo.marker();
|
||||
verify.baselineCallHierarchy();
|
||||
20
tests/cases/fourslash/callHierarchyFunction.ts
Normal file
20
tests/cases/fourslash/callHierarchyFunction.ts
Normal 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();
|
||||
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.1.ts
Normal file
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.1.ts
Normal 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();
|
||||
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.2.ts
Normal file
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.2.ts
Normal 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();
|
||||
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.3.ts
Normal file
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.3.ts
Normal 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();
|
||||
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.4.ts
Normal file
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.4.ts
Normal 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();
|
||||
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.5.ts
Normal file
16
tests/cases/fourslash/callHierarchyFunctionAmbiguity.5.ts
Normal 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();
|
||||
12
tests/cases/fourslash/callHierarchyInterfaceMethod.ts
Normal file
12
tests/cases/fourslash/callHierarchyInterfaceMethod.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// interface I {
|
||||
//// /**/foo(): void;
|
||||
//// }
|
||||
////
|
||||
//// const obj: I = { foo() {} };
|
||||
////
|
||||
//// obj.foo();
|
||||
|
||||
goTo.marker();
|
||||
verify.baselineCallHierarchy();
|
||||
17
tests/cases/fourslash/callHierarchyJsxElement.ts
Normal file
17
tests/cases/fourslash/callHierarchyJsxElement.ts
Normal 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();
|
||||
15
tests/cases/fourslash/callHierarchyTaggedTemplate.ts
Normal file
15
tests/cases/fourslash/callHierarchyTaggedTemplate.ts
Normal 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();
|
||||
@@ -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>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user