aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_project_model/src/lib.rs16
-rw-r--r--crates/rust-analyzer/src/main_loop.rs8
2 files changed, 16 insertions, 8 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 9b30bef8d..d5f82f17a 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -14,7 +14,7 @@ use std::{
14use anyhow::{bail, Context, Result}; 14use anyhow::{bail, Context, Result};
15use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
16use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; 16use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId};
17use rustc_hash::FxHashMap; 17use rustc_hash::{FxHashMap, FxHashSet};
18use serde_json::from_reader; 18use serde_json::from_reader;
19 19
20pub use crate::{ 20pub use crate::{
@@ -57,7 +57,7 @@ impl PackageRoot {
57 } 57 }
58} 58}
59 59
60#[derive(Debug, Clone, PartialEq, Eq, Hash)] 60#[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)]
61pub enum ProjectRoot { 61pub enum ProjectRoot {
62 ProjectJson(PathBuf), 62 ProjectJson(PathBuf),
63 CargoToml(PathBuf), 63 CargoToml(PathBuf),
@@ -128,6 +128,18 @@ impl ProjectRoot {
128 .collect() 128 .collect()
129 } 129 }
130 } 130 }
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 }
131} 143}
132 144
133impl ProjectWorkspace { 145impl ProjectWorkspace {
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 35f2d7001..82348c6fc 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -28,7 +28,7 @@ use lsp_types::{
28use ra_flycheck::{CheckTask, Status}; 28use ra_flycheck::{CheckTask, Status};
29use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId}; 29use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId};
30use ra_prof::profile; 30use ra_prof::profile;
31use ra_project_model::{PackageRoot, ProjectWorkspace}; 31use ra_project_model::{PackageRoot, ProjectRoot, ProjectWorkspace};
32use ra_vfs::{VfsFile, VfsTask, Watch}; 32use ra_vfs::{VfsFile, VfsTask, Watch};
33use relative_path::RelativePathBuf; 33use relative_path::RelativePathBuf;
34use rustc_hash::FxHashSet; 34use rustc_hash::FxHashSet;
@@ -96,11 +96,7 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
96 let mut global_state = { 96 let mut global_state = {
97 let workspaces = { 97 let workspaces = {
98 // FIXME: support dynamic workspace loading. 98 // FIXME: support dynamic workspace loading.
99 let project_roots: FxHashSet<_> = ws_roots 99 let project_roots = ProjectRoot::discover_all(&ws_roots);
100 .iter()
101 .filter_map(|it| ra_project_model::ProjectRoot::discover(it).ok())
102 .flatten()
103 .collect();
104 100
105 if project_roots.is_empty() && config.notifications.cargo_toml_not_found { 101 if project_roots.is_empty() && config.notifications.cargo_toml_not_found {
106 show_message( 102 show_message(