rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Creating rust dependencies tree explorer

Open bruno-ortiz opened this issue 3 years ago • 9 comments

Hello!

I tried to implement a tree view that shows the dependencies of a project.

It allows to see all dependencies to the project and it uses cargo tree for it. Also it allows to click and open the files, the viewtree tries its best to follow the openned file in the editor.

Here is an example: image

Any feedback is welcome since i have basically no professional experience with TS.

bruno-ortiz avatar Feb 26 '22 01:02 bruno-ortiz

Hey guys! I don't want to be a annoying or anything like that, but as this is my first PR here, do i need to do something else for the PR to be reviewed?

bruno-ortiz avatar Mar 01 '22 14:03 bruno-ortiz

Instead of using cargo tree should this use the dependency graph of rust-analyzer? That will also make it work when using rust-project.json instead of cargo and when using rust-analyzer.linkedProjects.

bjorn3 avatar Mar 10 '22 16:03 bjorn3

@bjorn3 Can you please send me a reference or any example on how i can use the dependency graph? And is this blocking, can we make this change afterwards?

Thanks for the comments

bruno-ortiz avatar Mar 10 '22 17:03 bruno-ortiz

We will probably need an lsp extension to provide the dependency graph from the language server to the extension. @Veykril maybe you can explain how to do this?

bjorn3 avatar Mar 10 '22 18:03 bjorn3

There is a "view dependency graph" command which could serve as inspiration.

lnicola avatar Mar 10 '22 18:03 lnicola

Ye, the server notifying the client here will have to be done as an lsp extension, a good inspiration for that would probably be the ServerStatus notification, as well as the view dependency graph as noted earlier.

Veykril avatar Mar 10 '22 21:03 Veykril

:umbrella: The latest upstream changes (presumably #12294) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar May 17 '22 19:05 bors

Went ahead and rebased this, this still needs to use the server for querying, I added a small commit implementing the scaffolding part for the lsp extension for now.

Veykril avatar Jul 17 '22 16:07 Veykril

:umbrella: The latest upstream changes (presumably #12919) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Aug 02 '22 13:08 bors

@Veykril sorry for the long delay, I got swamped at work.

I implemented the server query, feel free to review the code again..

bruno-ortiz avatar Apr 03 '23 01:04 bruno-ortiz

~~I converted this PR to draft because I detected some problems working with multi-workspaces. I'll try to fix it ASAP.~~ Marking this PR as ready to review again.

bruno-ortiz avatar Apr 05 '23 04:04 bruno-ortiz

@davidbarsky @nemethf I've made some quality of life improvements and made some best effort attempts to support the every usecase possible. One pain point is:

I could not figure out if a crate is vendored or not. Since RA uses "cargo metadata" to fetch the info about the crates, it receives this info from cargo itself, so unless we are able to parse cargo's config(config.toml), I think we will not be able to get a hold of this information. This doesn't mean that it doesn't works for projects with vendored crates, the dependencies will be shown, but the automatic navigation will be turned off, since vscode itself will auto-navigate using the primary explorer.

Does anyone see any other issues that would make this PR unmergeable?

bruno-ortiz avatar Apr 08 '23 20:04 bruno-ortiz

Does anyone see any other issues that would make this PR unmergeable?

I've only looked at lsp-extensions.md, and it is not a showstopper for me, but there is a bit of an inconsistency: the fetchDependencyList has FetchDependencyGraphParams and FetchDependencyGraphResult. I think it should be FetchDependencyListParams and FetchDependencyListResult.

Thank you.

nemethf avatar Apr 11 '23 14:04 nemethf

I believe this will show duplicate entries for project that have multiple cargo workspaces/linked projects loaded. Not a huge problem but something we should be aware of (this would be fixed once we deduplicate crates in the crate graph).

Veykril avatar Apr 13 '23 13:04 Veykril

@Veykril @nemethf thanks for the review. I fixed the appointed problems.

bruno-ortiz avatar Apr 13 '23 16:04 bruno-ortiz

Also please remove the merge commits, we prefer to not introduce merge commits aside from the ones bors introduces.

Veykril avatar Apr 24 '23 06:04 Veykril

@Veykril I added the requested comment and rebased the commits onto master branch.

bruno-ortiz avatar Apr 27 '23 01:04 bruno-ortiz

Two more things then I think its ready to go 🎉 (though I'll wait with merging until next week just to have some nightly time for it)

Veykril avatar Apr 27 '23 10:04 Veykril

@Veykril I made the requested fixes:

  • changed the type of the returned path to be an Url;
  • changed the crate_path function to lookup for the Cargo.toml dir.

bruno-ortiz avatar Apr 27 '23 19:04 bruno-ortiz

:umbrella: The latest upstream changes (presumably #14664) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar May 01 '23 21:05 bors

@bors delegate+

We got another round of merge conflicts 😅 Could you fix those up one last time, then you can merge it :) tyvm for this

Veykril avatar May 02 '23 07:05 Veykril

:v: @bruno-ortiz can now approve this pull request

bors avatar May 02 '23 07:05 bors

@bors r+

bruno-ortiz avatar May 02 '23 14:05 bruno-ortiz

:pushpin: Commit ecfe7c04888a9c2567773370b127d2e6e1cdaa22 has been approved by bruno-ortiz

It is now in the queue for this repository.

bors avatar May 02 '23 14:05 bors

:hourglass: Testing commit ecfe7c04888a9c2567773370b127d2e6e1cdaa22 with merge a48e0e14e15abf47feae17e54d149eb443729375...

bors avatar May 02 '23 14:05 bors

:sunny: Test successful - checks-actions Approved by: bruno-ortiz Pushing a48e0e14e15abf47feae17e54d149eb443729375 to master...

bors avatar May 02 '23 15:05 bors