diff options
author | Aleksey Kladov <[email protected]> | 2020-06-03 10:44:51 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-06-03 11:04:27 +0100 |
commit | 0a88de809f13f3b4abe0ffa11ff87c6f845050bd (patch) | |
tree | 3f9eaaf517b4c11974b20b6eda2211f68af7e197 /crates/ra_project_model | |
parent | 992e1256d05d1ec046e284e597b2932e50ccff49 (diff) |
Move project discovery
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 16 |
1 files changed, 14 insertions, 2 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 { |