diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 16 | ||||
-rw-r--r-- | crates/rust-analyzer/src/main_loop.rs | 8 |
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::{ | |||
14 | use anyhow::{bail, Context, Result}; | 14 | use anyhow::{bail, Context, Result}; |
15 | use ra_cfg::CfgOptions; | 15 | use ra_cfg::CfgOptions; |
16 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; | 16 | use ra_db::{CrateGraph, CrateName, Edition, Env, ExternSource, ExternSourceId, FileId}; |
17 | use rustc_hash::FxHashMap; | 17 | use rustc_hash::{FxHashMap, FxHashSet}; |
18 | use serde_json::from_reader; | 18 | use serde_json::from_reader; |
19 | 19 | ||
20 | pub use crate::{ | 20 | pub 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)] |
61 | pub enum ProjectRoot { | 61 | pub 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 | ||
133 | impl ProjectWorkspace { | 145 | impl 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::{ | |||
28 | use ra_flycheck::{CheckTask, Status}; | 28 | use ra_flycheck::{CheckTask, Status}; |
29 | use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId}; | 29 | use ra_ide::{Canceled, FileId, LibraryData, LineIndex, SourceRootId}; |
30 | use ra_prof::profile; | 30 | use ra_prof::profile; |
31 | use ra_project_model::{PackageRoot, ProjectWorkspace}; | 31 | use ra_project_model::{PackageRoot, ProjectRoot, ProjectWorkspace}; |
32 | use ra_vfs::{VfsFile, VfsTask, Watch}; | 32 | use ra_vfs::{VfsFile, VfsTask, Watch}; |
33 | use relative_path::RelativePathBuf; | 33 | use relative_path::RelativePathBuf; |
34 | use rustc_hash::FxHashSet; | 34 | use 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( |