Skip to content

Commit 0a88de8

Browse files
committed
Move project discovery
1 parent 992e125 commit 0a88de8

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

crates/ra_project_model/src/lib.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
use anyhow::{bail, Context, Result};
1515
use ra_cfg::CfgOptions;
1616
use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId};
17-
use rustc_hash::FxHashMap;
17+
use rustc_hash::{FxHashMap, FxHashSet};
1818
use serde_json::from_reader;
1919

2020
pub use crate::{
@@ -57,7 +57,7 @@ impl PackageRoot {
5757
}
5858
}
5959

60-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
60+
#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
6161
pub enum ProjectRoot {
6262
ProjectJson(PathBuf),
6363
CargoToml(PathBuf),
@@ -128,6 +128,18 @@ impl ProjectRoot {
128128
.collect()
129129
}
130130
}
131+
132+
pub fn discover_all(paths: &[impl AsRef<Path>]) -> Vec<ProjectRoot> {
133+
let mut res = paths
134+
.iter()
135+
.filter_map(|it| ProjectRoot::discover(it.as_ref()).ok())
136+
.flatten()
137+
.collect::<FxHashSet<_>>()
138+
.into_iter()
139+
.collect::<Vec<_>>();
140+
res.sort();
141+
res
142+
}
131143
}
132144

133145
impl ProjectWorkspace {

crates/rust-analyzer/src/main_loop.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use lsp_types::{
2828
use ra_flycheck::{CheckTask, Status};
2929
use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId};
3030
use ra_prof::profile;
31-
use ra_project_model::{PackageRoot, ProjectWorkspace};
31+
use ra_project_model::{PackageRoot, ProjectRoot, ProjectWorkspace};
3232
use ra_vfs::{VfsFile, VfsTask, Watch};
3333
use relative_path::RelativePathBuf;
3434
use rustc_hash::FxHashSet;
@@ -96,11 +96,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
9696
let mut global_state = {
9797
let workspaces = {
9898
// FIXME: support dynamic workspace loading.
99-
let project_roots: FxHashSet<_> = ws_roots
100-
.iter()
101-
.filter_map(|it| ra_project_model::ProjectRoot::discover(it).ok())
102-
.flatten()
103-
.collect();
99+
let project_roots = ProjectRoot::discover_all(&ws_roots);
104100

105101
if project_roots.is_empty() && config.notifications.cargo_toml_not_found {
106102
show_message(

0 commit comments

Comments
 (0)