-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call Hierarchy support for TypeScript #31863
Comments
what's changes in this issue? not |
@rbuckton When I talked this over this @jrieken from the VS Code team, it sounds like we will need a specialized TypeScript server api to implement this correctly and efficiently. Determining outgoing calls in particular is very difficult using current TSServer apis. Can we please revisit this for 3.8 |
Hey @jrieken, what sort of things were insufficient with the current approach? It'd help to get an idea so we can make sure those are tested. |
A few thing that I know of:
|
I suppose that it would be hard to understand every call-like behavior (tagged templates, decorators, function calls, new invocations, etc. |
@mjbvz, @jrieken: I've been working on the TSServer API for call hierarchies, and here's what I've come up with: export const enum CommandTypes {
...
PrepareCallHierarchy = "prepareCallHierarchy",
ProvideCallHierarchyIncomingCalls = "provideCallHierarchyIncomingCalls",
ProvideCallHierarchyOutgoingCalls = "provideCallHierarchyOutgoingCalls",
}
export interface CallHierarchyItem {
name: string;
kind: ScriptElementKind;
detail: string;
file: string;
span: TextSpan;
selectionSpan: TextSpan;
}
export interface CallHierarchyIncomingCall {
from: CallHierarchyItem;
fromSpans: TextSpan[];
}
export interface CallHierarchyOutgoingCall {
to: CallHierarchyItem;
fromSpans: TextSpan[];
}
export interface PrepareCallHierarchyRequest extends FileLocationRequest {
command: CommandTypes.PrepareCallHierarchy;
}
export interface PrepareCallHierarchyResponse extends Response {
readonly body: CallHierarchyItem;
}
export interface ProvideCallHierarchyIncomingCallsRequest extends FileLocationRequest {
command: CommandTypes.ProvideCallHierarchyIncomingCalls;
}
export interface ProvideCallHierarchyIncomingCallsResponse extends Response {
readonly body: CallHierarchyIncomingCall[];
}
export interface ProvideCallHierarchyOutgoingCallsRequest extends FileLocationRequest {
command: CommandTypes.ProvideCallHierarchyOutgoingCalls;
}
export interface ProvideCallHierarchyOutgoingCallsResponse extends Response {
readonly body: CallHierarchyOutgoingCall[];
} Rather than round-tripping a I've built a prototype of both the VS Code support for the TSServer API, as well as the TSServer implementation itself, though I do have a few additional questions: Files in the Call HierarchyHow should a function foo() { }
foo(); I am including source files in the prototype I have built, however I'm not certain of the best way to represent the "name" of the call hierarchy item: Call Hierarchy Item DetailsThe comment for the Items to show in Call HierarchyThis has been brought up in microsoft/vscode#84100, but I'll mention it here as well. TS/JS have several different calling conventions we should be aware of:
Method SignaturesShould we support Call Hierarchy on Method Signatures in interfaces? They obviously wouldn't have outgoing calls, but they could have incoming calls. The VS version of Call Hierarchy does seem to support this (though they also include things such as places that a member is overridden or implemented as well): |
Also, a // file1.d.ts
interface Shared {
foo(): void; // merges with `Shared` in file2
}
declare function bar(): void; // merges with `bar` in file2
// file2.d.ts
interface Shared {
foo(): void; // merges with `Shared` in file1
}
declare function bar(): void; // merges with `bar` in file1
// file3.ts
declare const x: Shared;
x.foo(); // Which `foo` should we pick for the call hierarchy item's range/selection range?
bar(); // Which `bar` should we pick for the call hierarchy item's range/selection range? |
We actually do the same - internally each item is associated with an ID and only that goes over the wire. For the API we wanted to be more expressive and give implementor a chance to store data subsequent requests in an item.
That's a good question. I think the base-filename, e.g
Not sure tbh - the details field is a bit of a free form field for extensions to add "something" useful. We have the same for outline and there TS isn't using it, some extension are. Generally, it will be rendered as is, no MD formatting or so.
👍 I think that's useful in order to see how an interface is being used.
🤷♂ though question... for calls each item could just be a call but when starting/preparing it's a little more trick... We might need to evolve our API so that prepare can return N items. |
Is there an API I can leverage to format the path in an OS-specific way? As you can see from the screenshot above, it's currently using TypeScript's internal path representation ( |
Yeah, we have asRelativePath which should be able to handle that |
See microsoft/vscode#16110
The text was updated successfully, but these errors were encountered: