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!
This commit is contained in:
commit
9aa867cd01
@ -22,6 +22,7 @@ use ide_db::{
|
|||||||
base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, ProcMacros},
|
base_db::{salsa::Durability, CrateGraph, ProcMacroPaths, ProcMacros},
|
||||||
FxHashMap,
|
FxHashMap,
|
||||||
};
|
};
|
||||||
|
use itertools::Itertools;
|
||||||
use load_cargo::{load_proc_macro, ProjectFolders};
|
use load_cargo::{load_proc_macro, ProjectFolders};
|
||||||
use proc_macro_api::ProcMacroServer;
|
use proc_macro_api::ProcMacroServer;
|
||||||
use project_model::{ProjectWorkspace, WorkspaceBuildScripts};
|
use project_model::{ProjectWorkspace, WorkspaceBuildScripts};
|
||||||
@ -227,16 +228,12 @@ impl GlobalState {
|
|||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
while i < workspaces.len() {
|
while i < workspaces.len() {
|
||||||
if let Ok(w) = &workspaces[i] {
|
if let Ok(w) = &workspaces[i] {
|
||||||
let dupes: Vec<_> = workspaces
|
let dupes: Vec<_> = workspaces[i + 1..]
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.positions(|it| it.as_ref().is_ok_and(|ws| ws.eq_ignore_build_data(w)))
|
||||||
.skip(i + 1)
|
|
||||||
.filter_map(|(i, it)| {
|
|
||||||
it.as_ref().ok().filter(|ws| ws.eq_ignore_build_data(w)).map(|_| i)
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
dupes.into_iter().rev().for_each(|d| {
|
dupes.into_iter().rev().for_each(|d| {
|
||||||
_ = workspaces.remove(d);
|
_ = workspaces.remove(d + i + 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
i += 1;
|
i += 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user