Skip to content

Add call hierarchy feature #612

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

Closed
xster opened this issue Feb 22, 2018 · 19 comments
Closed

Add call hierarchy feature #612

xster opened this issue Feb 22, 2018 · 19 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Milestone

Comments

@xster
Copy link

xster commented Feb 22, 2018

Don't know if it's possible. It's possible to check a function's call hierarchy in IntelliJ. Is it possible to bring it to VSCode?

@DanTup
Copy link
Member

DanTup commented Feb 23, 2018

@bwilkerson I guess this would need support from the analyzer? I can't see anything in the docs that looks like it would provide this.

@xster If we had the data, I'm not sure how we could best display this. We have implemented Type Heirarchy (F4?) but render it in a pick list and I think it looks a bit weird (being a tree in a flat list), see #190 (comment)

@DanTup DanTup added this to the Backlog milestone Feb 23, 2018
@DanTup DanTup added is enhancement blocked on dart / flutter Requires a change in Dart or Flutter to progress in editor Relates to code editing or language features labels Feb 23, 2018
@bwilkerson
Copy link

By call hierarchy, do you mean a tree where the top-level nodes are all of the methods containing invocations of a selected method, and the children of each node are the methods containing invocations of the parent node?

If so, then it's all done lazily. Each level in the tree is fetched (by searching for references to an element) when the parent node is expanded. It is done this way both for performance and in order to deal with recursive chains of functions. The result isn't strictly a call hierarchy, it's a reference hierarchy, but the distinction is subtle and not interesting to most users.

@DanTup DanTup removed the blocked on dart / flutter Requires a change in Dart or Flutter to progress label Feb 23, 2018
@DanTup
Copy link
Member

DanTup commented Feb 23, 2018

Aha, makes sense! I guess we can't wedge it into a picker like we did for types then; it'd have to go in the explorer (tree).

@xster
Copy link
Author

xster commented Feb 23, 2018

I wonder if it's possible to augment the Find all References peek window and make each descendent node also expandable.

@DanTup
Copy link
Member

DanTup commented Feb 23, 2018

We can't really control this, since Code does all rendering here. However, I think you can do another Find References inside the peek window?

@DanTup DanTup added the blocked on vs code / lsp / dap Requires a change in VS Code to progress label Nov 15, 2018
@DanTup
Copy link
Member

DanTup commented Nov 15, 2018

This makes most sense implemented in VS Code - there's an issue at microsoft/vscode#16110.

@DanTup DanTup added upstream in dart / flutter Needs changing in Dart or Flutter upstream in vs code / lsp / dap Needs changing in VS Code, LSP or DAP protocols/libraries and removed blocked on vs code / lsp / dap Requires a change in VS Code to progress upstream in dart / flutter Needs changing in Dart or Flutter labels Nov 15, 2018
@DanTup DanTup modified the milestones: Backlog, On Deck Apr 5, 2019
@DanTup DanTup removed the upstream in vs code / lsp / dap Needs changing in VS Code, LSP or DAP protocols/libraries label Apr 5, 2019
@DanTup
Copy link
Member

DanTup commented Apr 5, 2019

VS Code is adding new APIs for first-class support for this, so this might be possible soon :-)

https://code.visualstudio.com/updates/v1_33#_call-hierarchy

@xster
Copy link
Author

xster commented Apr 5, 2019

I noticed that in the new release notes too. Woohoo!

@DanTup DanTup modified the milestones: On Deck, v3.8.0 Dec 5, 2019
@DanTup DanTup modified the milestones: v3.8.0, v3.9.0 Jan 16, 2020
@DanTup DanTup modified the milestones: v3.9.0, v3.10.0 Mar 24, 2020
@DanTup
Copy link
Member

DanTup commented Apr 21, 2020

@bwilkerson

I was just having a go at implementing this:

If so, then it's all done lazily. Each level in the tree is fetched (by searching for references to an element) when the parent node is expanded

The API in VS Code can call us asking for the "incoming calls" and "outgoing calls" for a node (so you can navigate both ways). I think the incoming calls we could get with search.findElementReferences (the same we use for "Find References") but I'm not sure if there's something that allows us to get the outgoing calls (eg. for a given function, find the calls it makes out to other functions)?

If there's nothing already there, then we could just build this in LSP on the server (rather than add new APIs that we'll migrate away from) once the LSP spec work for this lands.

@DanTup DanTup modified the milestones: v3.10.0, On Deck Apr 21, 2020
@bsutton
Copy link

bsutton commented Mar 2, 2022

Any update on this one.
It's probably the feature I miss the most coming from java/eclipse.

@DanTup DanTup modified the milestones: On Deck, v3.46.0 Jul 13, 2022
@DanTup
Copy link
Member

DanTup commented Jul 13, 2022

I have an implementation of this working now. It's not a feature I've really used much myself so I am interested additional testing/feedback once it lands. It's implemented in the Dart SDK (LSP server), so you'd need to use a dev SDK in order for it to show up.

Screenshot 2022-07-13 at 17 46 08

One odd thing I've noticed though is that although we supply the ranges of outbound calls to the client, VS Code doesn't seem to use them. When you click a called method in the tree, VS Code jumps to the declaration and never seems to show you the locations of the outbound calls. There's an open issue about this at microsoft/vscode#111454 which may need 👍 's if that's to be addressed :-)

@bsutton
Copy link

bsutton commented Jul 18, 2022

So how do I trigger the call hierarchy?

I'm running dart 2.180.271.0.dev
I'm running dartr code 3.44.0
restarted vscode.
image

I've tried 'find all references'

Screencast.from.18-07-22.12.33.46.webm

@DanTup
Copy link
Member

DanTup commented Jul 18, 2022

@bsutton v2.180.271.0.dev looks like a branch made for a beta build (see flutter/flutter#107564) and forked before the change above. When using a newer version that does include the change, Call Hierarchy will appear on the context menu:

Screenshot 2022-07-18 at 11 01 30

@bsutton
Copy link

bsutton commented Jul 18, 2022

@DanTup
Do you have a version no. that you know should work:
I've tried:
2.18.0-263.0.dev
2.18.0-250.0.dev
2.18.0-271.0.dev

none of which show the menu.

@DanTup
Copy link
Member

DanTup commented Jul 18, 2022

According to the tags shown on the commit, the following versions include it:

  • 2.19.0-5.0.dev
  • 2.19.0-4.0.dev
  • 2.19.0-3.0.dev
  • 2.19.0-2.0.dev
  • 2.19.0-1.0.dev
  • 2.19.0-0.0.dev
  • 2.18.0-286.0.dev
  • 2.18.0-285.0.dev
  • 2.18.0-284.0.dev

I don't know whether those 2.18 dev versions are just automatic tags though. Based on the issue linked above about branching for a beta release (which was before any of those branches), I suspect this change would not show up if that beta branch became a stable 2.18 release, instead being included in a future version.

Note: Right now it seems dart.dev also stops at 2.18.0-271.0.dev which may be because of branching. If you want to test with a bleeding-edge build (not recommended for general production work) there's info here:

https://dart.dev/get-dart/archive#main-channel-url-scheme

For example for macOS:

https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-macos-x64-release.zip for Intel or https://storage.googleapis.com/dart-archive/channels/be/raw/latest/sdk/dartsdk-macos-arm64-release.zip for M1.

@DanTup DanTup modified the milestones: v3.46.0, v3.48.0 Aug 1, 2022
@DanTup DanTup modified the milestones: v3.48.0, v3.50.0 Aug 23, 2022
@DanTup DanTup added the relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available label Sep 6, 2022
@DanTup DanTup modified the milestones: v3.50.0, Next SDK Release Oct 3, 2022
@bsutton
Copy link

bsutton commented Oct 11, 2022 via email

@DanTup
Copy link
Member

DanTup commented Oct 11, 2022

I'm not sure what "archive channels" means in this context, but FWIW the latest Dart beta on https://dart.dev/get-dart/archive is 2.19.0-255.2.beta which should definitely include it. So if you're able to use beta releases (and not only stable releases) then it should be available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is enhancement relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Projects
None yet
Development

No branches or pull requests

4 participants