Skip to content

Commit 9aa867c

Browse files
committed
Auto merge of #15946 - roife:master, r=Veykril
internal: simplify the removal of dulicate workspaces. ### Summary: Refactoring the duplicate removal process for `workspaces` in `fetch_workspaces`. ### Changes Made: Replaced `[].iter().enumerate().skip(...).filter_map(...)` with a more concise `[i+1..].positions(...)` provided by `itertools`, which enhances clarity without changing functionality ### Impact: This change aims to enhance the duplicate removal process for `workspaces`. This change has been tested on my machine. Please review and provide feedback. Thanks!
2 parents 23dc01f + e790d7f commit 9aa867c

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)