-
Notifications
You must be signed in to change notification settings - Fork 1.7k
vscode workspaces don't play nicely with r-a #14571
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
Comments
So basically I think the server should try to dedup/map workspace folders that indirectly point to the same top-level cargo workspace. We discover them here https://github.com/veykril/rust-analyzer/blob/3c7b6716d1ab458664a8b372b79347b9a9cacb98/crates/rust-analyzer/src/config.rs#L753 where workspace roots are the folders supplied by VSCode. |
Short answer (realized while writing long answer): Looking into your fix #14603 I recognized that rust-analyzer/crates/rust-analyzer/src/reload.rs Lines 215 to 227 in 112464f
Possible fix: while i < workspaces.len() {
if let Ok(w) = &workspaces[i] {
match workspaces
.iter()
.filter_map(|it| it.as_ref().ok())
.enumerate().filter(|&(idx, _)| idx != i).map(|(_, v)| v)
.position(|ws| ws.eq_ignore_build_data(w))
{
Some(dupe) => _ = workspaces.remove(dupe),
None => i += 1,
}
} else {
i += 1;
}
} Long answer:Coincidentally I have also been looking at this issue (for learning purposes) and I suspect your fix #14603 does not correct the excess memory usage through duplicated cargo workspaces.My test setup is a vscode workspace with folders for each crate from rust-analyzer basically duplicating the cargo workspace. With your fix memory usage still grows to 6.9 GB in the vscode workspace compared to ~870 MB when opening the cargo workspace under vscode. Debugging the vscode workspace indicates that rust-analyzer/crates/rust-analyzer/src/reload.rs Lines 215 to 227 in 112464f
|
1.) You are right, if we dedup we are moving two indices instead of one (classic modifying collection while iterating it mistake) |
Can you explain this more? It did remove duplicates in my testing, I used a vscode workspace that had 2 folders opened pointing to 2 crates of a cargo workspace resulting in rust-analyzer deduplicating the loaded projects to the cargo workspace once instead of twice. |
In 2) position() short-circuits, so if one match is found all other elements are not compared to and the index is advanced. Details about my debugging I can explain, when I am at my computer. |
Ah, no need to give me details now I understand what you were trying to get at. Yes you are correct this is also a bug. |
fix: Fix vscode workspaces not working properly Fixes #14571
@bors , sorry for reviving this old issue, but I ran into this after switching to cargo workspaces. I'm seeing the same problem duplicated once for each crate in the workspace. I also use VSCode code workspaces, 1 for each crate. Was there a fix for this available? |
When using a code workspace where a cargo workspace is split up into multiple folder views, r-a will duplicate the loaded cargo workspace for each folder currently which leads to excessive memory usage. We should investigate if we can prevent this from happening somehow
The text was updated successfully, but these errors were encountered: