Skip to content

Commit 9c40897

Browse files
committed
Deduplicate loaded projects
1 parent f5f68e4 commit 9c40897

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

crates/rust-analyzer/src/config.rs

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl Default for ConfigData {
535535

536536
#[derive(Debug, Clone)]
537537
pub struct Config {
538-
discovered_projects: Option<Vec<ProjectManifest>>,
538+
discovered_projects: Vec<ProjectManifest>,
539539
/// The workspace roots as registered by the LSP client
540540
workspace_roots: Vec<AbsPathBuf>,
541541
caps: lsp_types::ClientCapabilities,
@@ -743,7 +743,7 @@ impl Config {
743743
caps,
744744
data: ConfigData::default(),
745745
detached_files: Vec::new(),
746-
discovered_projects: None,
746+
discovered_projects: Vec::new(),
747747
root_path,
748748
snippets: Default::default(),
749749
workspace_roots,
@@ -756,7 +756,7 @@ impl Config {
756756
if discovered.is_empty() {
757757
tracing::error!("failed to find any projects in {:?}", &self.workspace_roots);
758758
}
759-
self.discovered_projects = Some(discovered);
759+
self.discovered_projects = discovered;
760760
}
761761

762762
pub fn remove_workspace(&mut self, path: &AbsPath) {
@@ -871,25 +871,19 @@ impl Config {
871871
pub fn linked_projects(&self) -> Vec<LinkedProject> {
872872
match self.data.linkedProjects.as_slice() {
873873
[] => {
874-
match self.discovered_projects.as_ref() {
875-
Some(discovered_projects) => {
876-
let exclude_dirs: Vec<_> = self
877-
.data
878-
.files_excludeDirs
879-
.iter()
880-
.map(|p| self.root_path.join(p))
881-
.collect();
882-
discovered_projects
883-
.iter()
884-
.filter(|(ProjectManifest::ProjectJson(path) | ProjectManifest::CargoToml(path))| {
874+
let exclude_dirs: Vec<_> =
875+
self.data.files_excludeDirs.iter().map(|p| self.root_path.join(p)).collect();
876+
self.discovered_projects
877+
.iter()
878+
.filter(
879+
|(ProjectManifest::ProjectJson(path)
880+
| ProjectManifest::CargoToml(path))| {
885881
!exclude_dirs.iter().any(|p| path.starts_with(p))
886-
})
887-
.cloned()
888-
.map(LinkedProject::from)
889-
.collect()
890-
}
891-
None => Vec::new(),
892-
}
882+
},
883+
)
884+
.cloned()
885+
.map(LinkedProject::from)
886+
.collect()
893887
}
894888
linked_projects => linked_projects
895889
.iter()

crates/rust-analyzer/src/reload.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,20 @@ impl GlobalState {
212212
})
213213
.collect::<Vec<_>>();
214214

215+
let mut i = 0;
216+
while i < workspaces.len() {
217+
if let Ok(w) = &workspaces[i] {
218+
if let Some(dupe) = workspaces[i + 1..]
219+
.iter()
220+
.filter_map(|it| it.as_ref().ok())
221+
.position(|ws| ws.eq_ignore_build_data(w))
222+
{
223+
_ = workspaces.remove(dupe);
224+
}
225+
}
226+
i += 1;
227+
}
228+
215229
if !detached_files.is_empty() {
216230
workspaces.push(project_model::ProjectWorkspace::load_detached_files(
217231
detached_files,

crates/rust-analyzer/tests/slow-tests/support.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::{
99
use crossbeam_channel::{after, select, Receiver};
1010
use lsp_server::{Connection, Message, Notification, Request};
1111
use lsp_types::{notification::Exit, request::Shutdown, TextDocumentIdentifier, Url};
12-
use project_model::ProjectManifest;
1312
use rust_analyzer::{config::Config, lsp_ext, main_loop};
1413
use serde::Serialize;
1514
use serde_json::{json, to_string_pretty, Value};

0 commit comments

Comments
 (0)