Skip to content

Commit e790d7f

Browse files
committed
internal: simplify the removal of dulicate workspaces.
refactor: replace multiple steps with `positions` in `fetch_workspaces` for clarity.
1 parent 4513651 commit e790d7f

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

crates/rust-analyzer/src/reload.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use ide_db::{
2222
base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, ProcMacros},
2323
FxHashMap,
2424
};
25+
use itertools::Itertools;
2526
use load_cargo::{load_proc_macro, ProjectFolders};
2627
use proc_macro_api::ProcMacroServer;
2728
use project_model::{ProjectWorkspace, WorkspaceBuildScripts};
@@ -227,16 +228,12 @@ impl GlobalState {
227228
let mut i = 0;
228229
while i < workspaces.len() {
229230
if let Ok(w) = &workspaces[i] {
230-
let dupes: Vec<_> = workspaces
231+
let dupes: Vec<_> = workspaces[i + 1..]
231232
.iter()
232-
.enumerate()
233-
.skip(i + 1)
234-
.filter_map(|(i, it)| {
235-
it.as_ref().ok().filter(|ws| ws.eq_ignore_build_data(w)).map(|_| i)
236-
})
233+
.positions(|it| it.as_ref().is_ok_and(|ws| ws.eq_ignore_build_data(w)))
237234
.collect();
238235
dupes.into_iter().rev().for_each(|d| {
239-
_ = workspaces.remove(d);
236+
_ = workspaces.remove(d + i + 1);
240237
});
241238
}
242239
i += 1;

0 commit comments

Comments
 (0)