diff options
author | Aleksey Kladov <[email protected]> | 2020-07-21 11:52:51 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-07-21 11:52:51 +0100 |
commit | 39a2bc5e3cd86876eef6f3a96bef188f88e85114 (patch) | |
tree | 6e655b139235d23c7640e404a10eb543ef85caac | |
parent | 818aeb8a242bba5d8947ce2960e1af27d998f4fc (diff) |
Expose package roots more directly
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 62 | ||||
-rw-r--r-- | crates/rust-analyzer/src/reload.rs | 40 | ||||
-rw-r--r-- | crates/vfs/src/loader.rs | 2 |
3 files changed, 50 insertions, 54 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index b9c5424bf..cf46048e5 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -37,28 +37,10 @@ pub enum ProjectWorkspace { | |||
37 | /// the current workspace. | 37 | /// the current workspace. |
38 | #[derive(Debug, Clone)] | 38 | #[derive(Debug, Clone)] |
39 | pub struct PackageRoot { | 39 | pub struct PackageRoot { |
40 | /// Path to the root folder | ||
41 | path: AbsPathBuf, | ||
42 | /// Is a member of the current workspace | 40 | /// Is a member of the current workspace |
43 | is_member: bool, | 41 | pub is_member: bool, |
44 | out_dir: Option<AbsPathBuf>, | 42 | pub include: Vec<AbsPathBuf>, |
45 | } | 43 | pub exclude: Vec<AbsPathBuf>, |
46 | impl PackageRoot { | ||
47 | pub fn new_member(path: AbsPathBuf) -> PackageRoot { | ||
48 | Self { path, is_member: true, out_dir: None } | ||
49 | } | ||
50 | pub fn new_non_member(path: AbsPathBuf) -> PackageRoot { | ||
51 | Self { path, is_member: false, out_dir: None } | ||
52 | } | ||
53 | pub fn path(&self) -> &AbsPath { | ||
54 | &self.path | ||
55 | } | ||
56 | pub fn out_dir(&self) -> Option<&AbsPath> { | ||
57 | self.out_dir.as_deref() | ||
58 | } | ||
59 | pub fn is_member(&self) -> bool { | ||
60 | self.is_member | ||
61 | } | ||
62 | } | 44 | } |
63 | 45 | ||
64 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] | 46 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] |
@@ -195,18 +177,38 @@ impl ProjectWorkspace { | |||
195 | /// the root is a member of the current workspace | 177 | /// the root is a member of the current workspace |
196 | pub fn to_roots(&self) -> Vec<PackageRoot> { | 178 | pub fn to_roots(&self) -> Vec<PackageRoot> { |
197 | match self { | 179 | match self { |
198 | ProjectWorkspace::Json { project } => { | 180 | ProjectWorkspace::Json { project } => project |
199 | project.roots.iter().map(|r| PackageRoot::new_member(r.path.clone())).collect() | 181 | .roots |
200 | } | 182 | .iter() |
183 | .map(|r| { | ||
184 | let path = r.path.clone(); | ||
185 | let include = vec![path]; | ||
186 | PackageRoot { is_member: true, include, exclude: Vec::new() } | ||
187 | }) | ||
188 | .collect(), | ||
201 | ProjectWorkspace::Cargo { cargo, sysroot } => cargo | 189 | ProjectWorkspace::Cargo { cargo, sysroot } => cargo |
202 | .packages() | 190 | .packages() |
203 | .map(|pkg| PackageRoot { | 191 | .map(|pkg| { |
204 | path: cargo[pkg].root().to_path_buf(), | 192 | let is_member = cargo[pkg].is_member; |
205 | is_member: cargo[pkg].is_member, | 193 | let pkg_root = cargo[pkg].root().to_path_buf(); |
206 | out_dir: cargo[pkg].out_dir.clone(), | 194 | |
195 | let mut include = vec![pkg_root.clone()]; | ||
196 | include.extend(cargo[pkg].out_dir.clone()); | ||
197 | |||
198 | let mut exclude = vec![pkg_root.join(".git")]; | ||
199 | if is_member { | ||
200 | exclude.push(pkg_root.join("target")); | ||
201 | } else { | ||
202 | exclude.push(pkg_root.join("tests")); | ||
203 | exclude.push(pkg_root.join("examples")); | ||
204 | exclude.push(pkg_root.join("benches")); | ||
205 | } | ||
206 | PackageRoot { is_member, include, exclude } | ||
207 | }) | 207 | }) |
208 | .chain(sysroot.crates().map(|krate| { | 208 | .chain(sysroot.crates().map(|krate| PackageRoot { |
209 | PackageRoot::new_non_member(sysroot[krate].root_dir().to_path_buf()) | 209 | is_member: false, |
210 | include: vec![sysroot[krate].root_dir().to_path_buf()], | ||
211 | exclude: Vec::new(), | ||
210 | })) | 212 | })) |
211 | .collect(), | 213 | .collect(), |
212 | } | 214 | } |
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs index d7ae00b07..1907f2f13 100644 --- a/crates/rust-analyzer/src/reload.rs +++ b/crates/rust-analyzer/src/reload.rs | |||
@@ -5,7 +5,7 @@ use flycheck::FlycheckHandle; | |||
5 | use ra_db::{CrateGraph, SourceRoot, VfsPath}; | 5 | use ra_db::{CrateGraph, SourceRoot, VfsPath}; |
6 | use ra_ide::AnalysisChange; | 6 | use ra_ide::AnalysisChange; |
7 | use ra_prof::profile; | 7 | use ra_prof::profile; |
8 | use ra_project_model::{PackageRoot, ProcMacroClient, ProjectWorkspace}; | 8 | use ra_project_model::{ProcMacroClient, ProjectWorkspace}; |
9 | use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind}; | 9 | use vfs::{file_set::FileSetConfig, AbsPath, AbsPathBuf, ChangeKind}; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
@@ -149,8 +149,10 @@ impl GlobalState { | |||
149 | watchers: workspaces | 149 | watchers: workspaces |
150 | .iter() | 150 | .iter() |
151 | .flat_map(ProjectWorkspace::to_roots) | 151 | .flat_map(ProjectWorkspace::to_roots) |
152 | .filter(PackageRoot::is_member) | 152 | .filter(|it| it.is_member) |
153 | .map(|root| format!("{}/**/*.rs", root.path().display())) | 153 | .flat_map(|root| { |
154 | root.include.into_iter().map(|it| format!("{}/**/*.rs", it.display())) | ||
155 | }) | ||
154 | .map(|glob_pattern| lsp_types::FileSystemWatcher { glob_pattern, kind: None }) | 156 | .map(|glob_pattern| lsp_types::FileSystemWatcher { glob_pattern, kind: None }) |
155 | .collect(), | 157 | .collect(), |
156 | }; | 158 | }; |
@@ -261,31 +263,23 @@ impl ProjectFolders { | |||
261 | let mut local_filesets = vec![]; | 263 | let mut local_filesets = vec![]; |
262 | 264 | ||
263 | for root in workspaces.iter().flat_map(|it| it.to_roots()) { | 265 | for root in workspaces.iter().flat_map(|it| it.to_roots()) { |
264 | let path = root.path().to_owned(); | 266 | let file_set_roots: Vec<VfsPath> = |
265 | 267 | root.include.iter().cloned().map(VfsPath::from).collect(); | |
266 | let mut file_set_roots: Vec<VfsPath> = vec![]; | ||
267 | 268 | ||
268 | let entry = if root.is_member() { | 269 | let entry = { |
269 | vfs::loader::Entry::local_cargo_package(path.to_path_buf()) | 270 | let mut dirs = vfs::loader::Directories::default(); |
270 | } else { | 271 | dirs.extensions.push("rs".into()); |
271 | vfs::loader::Entry::cargo_package_dependency(path.to_path_buf()) | 272 | dirs.include.extend(root.include); |
273 | dirs.exclude.extend(root.exclude); | ||
274 | vfs::loader::Entry::Directories(dirs) | ||
272 | }; | 275 | }; |
273 | res.load.push(entry); | ||
274 | if root.is_member() { | ||
275 | res.watch.push(res.load.len() - 1); | ||
276 | } | ||
277 | 276 | ||
278 | if let Some(out_dir) = root.out_dir() { | 277 | if root.is_member { |
279 | let out_dir = out_dir.to_path_buf(); | 278 | res.watch.push(res.load.len()); |
280 | res.load.push(vfs::loader::Entry::rs_files_recursively(out_dir.clone())); | ||
281 | if root.is_member() { | ||
282 | res.watch.push(res.load.len() - 1); | ||
283 | } | ||
284 | file_set_roots.push(out_dir.into()); | ||
285 | } | 279 | } |
286 | file_set_roots.push(path.to_path_buf().into()); | 280 | res.load.push(entry); |
287 | 281 | ||
288 | if root.is_member() { | 282 | if root.is_member { |
289 | local_filesets.push(fsc.len()); | 283 | local_filesets.push(fsc.len()); |
290 | } | 284 | } |
291 | fsc.add_file_set(file_set_roots) | 285 | fsc.add_file_set(file_set_roots) |
diff --git a/crates/vfs/src/loader.rs b/crates/vfs/src/loader.rs index 04e257f53..40cf96020 100644 --- a/crates/vfs/src/loader.rs +++ b/crates/vfs/src/loader.rs | |||
@@ -17,7 +17,7 @@ pub enum Entry { | |||
17 | /// * it is not under `exclude` path | 17 | /// * it is not under `exclude` path |
18 | /// | 18 | /// |
19 | /// If many include/exclude paths match, the longest one wins. | 19 | /// If many include/exclude paths match, the longest one wins. |
20 | #[derive(Debug, Clone)] | 20 | #[derive(Debug, Clone, Default)] |
21 | pub struct Directories { | 21 | pub struct Directories { |
22 | pub extensions: Vec<String>, | 22 | pub extensions: Vec<String>, |
23 | pub include: Vec<AbsPathBuf>, | 23 | pub include: Vec<AbsPathBuf>, |