-
Notifications
You must be signed in to change notification settings - Fork 1.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
feat: Creating rust dependencies tree explorer #11557
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
795a1cb
Creating rust dependencies tree view
bruno-ortiz 68aa20b
fixing stblib loading
bruno-ortiz 77a4bfd
fixing linting problemas
bruno-ortiz 364308d
removing unused function
bruno-ortiz 76432d3
Reformat VSCode client code
Veykril 16cba19
Remove unnecessary openFile command
Veykril 1201b15
WIP: Add lsp-ext scaffold
Veykril 09e0a00
fetching dependencies from the server
bruno-ortiz d01fc64
Creating rust dependencies tree view
bruno-ortiz f8215dd
fixing stblib loading
bruno-ortiz ee54c65
fixing linting problemas
bruno-ortiz d1721b1
removing unused function
bruno-ortiz af999f1
Reformat VSCode client code
Veykril 9533644
Remove unnecessary openFile command
Veykril 299382d
WIP: Add lsp-ext scaffold
Veykril fc57339
removing unused code
bruno-ortiz 440889e
fixing main_loop.rs
bruno-ortiz 061940d
running prettier
bruno-ortiz e253592
Fixing tests
bruno-ortiz 1b8288f
Fixing naming from graph to list
bruno-ortiz 8e687f7
improving code to work with multi-workspaces
bruno-ortiz a3081a6
Adding crate_root_path to crate_graph
bruno-ortiz fe7874a
reveal only when tree is visible
bruno-ortiz c372fb3
fixing tests for windows
bruno-ortiz 66fe84d
accepting review suggestions
bruno-ortiz bd2160f
final rabasing fixes
bruno-ortiz 072f69e
fixing ts linting and rust test
bruno-ortiz 800b3b6
adding doc and simplifying function
bruno-ortiz bcb2131
Accepting review suggestions
bruno-ortiz 0aed507
fixing TS linting, removing import
bruno-ortiz ecfe7c0
last fixes after rebase
bruno-ortiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use ide_db::{ | ||
base_db::{CrateOrigin, FileId, SourceDatabase}, | ||
FxIndexSet, RootDatabase, | ||
}; | ||
|
||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
pub struct CrateInfo { | ||
pub name: Option<String>, | ||
pub version: Option<String>, | ||
pub root_file_id: FileId, | ||
} | ||
|
||
// Feature: Show Dependency Tree | ||
// | ||
// Shows a view tree with all the dependencies of this project | ||
// | ||
// |=== | ||
// image::https://user-images.githubusercontent.com/5748995/229394139-2625beab-f4c9-484b-84ed-ad5dee0b1e1a.png[] | ||
pub(crate) fn fetch_crates(db: &RootDatabase) -> FxIndexSet<CrateInfo> { | ||
let crate_graph = db.crate_graph(); | ||
crate_graph | ||
.iter() | ||
.map(|crate_id| &crate_graph[crate_id]) | ||
.filter(|&data| !matches!(data.origin, CrateOrigin::Local { .. })) | ||
.map(|data| crate_info(data)) | ||
.collect() | ||
} | ||
|
||
fn crate_info(data: &ide_db::base_db::CrateData) -> CrateInfo { | ||
let crate_name = crate_name(data); | ||
let version = data.version.clone(); | ||
CrateInfo { name: crate_name, version, root_file_id: data.root_file_id } | ||
} | ||
|
||
fn crate_name(data: &ide_db::base_db::CrateData) -> Option<String> { | ||
data.display_name.as_ref().map(|it| it.canonical_name().to_owned()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more general (and more in line with the language server protocol) to use
textDocument: TextDocumentIdentifier
here instead of the currentpath: string
?And as a side note: why this is called a graph/tree, when this is just a list? It is not possible to construct a graph from the response. Ie.: visualize the the dependencies of a dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nemethf you're right about the naming, I changed from "graph" to "list". The tree is because the crates are displayed in a "ViewTree".
About the
TextDocumentIdentifier
, I tried using it, but it just made the code more complicated, because to reveal the items in the viewTree I need to work with the filesystem path, and theTextDocumentIdentifier
inputs the "scheme" in the path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking over
vscode.TreeItem
, it seems like it requires you to operate in terms of URIs anyways, so I think it might clean up some of the code here if everything here operated in terms of URIs—the scheme can be dropped accordingly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I have no objections against it. However, it is a bit strange that a client-side implementation detail determines an abstract name in protocol specification. I can imagine some clients using this extension for something else, for example, to provide a "jump to dependency" functionality that implements an incremental search on the dependencies without showing them beforehand.
Also this fetchDependencyGraph reminds me of the rust-analyzer/viewCrateGraph LSP extension. In the long run, it might make sense to generalize both of them to send the same details. fetchDependencyGraph could list the dependencies of a dependency, and viewCrateGraph could be extended to have a uri/path for each dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
TextDocumentIdentifier
would indeed make more sense if possible