diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-21 10:56:05 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-21 10:56:05 +0000 |
commit | b03883279528986bd829e14f967db4b4c980049d (patch) | |
tree | b891f591e240e84d14dc8060e3706ee025cc0906 /crates/ra_lsp_server/src/server_world.rs | |
parent | 1eb3bf41d75a8c744a0ecb586d4a2e92a1175c08 (diff) | |
parent | c6d6e6c6259709ec30eadb79a1908dca707a6499 (diff) |
Merge #997
997: Improve filtering of file roots r=matklad a=vipentti
`ProjectWorkspace::to_roots` now returns a new `ProjectRoot` which contains
information regarding whether or not the given path is part of the current
workspace or an external dependency. This information can then be used in
`ra_batch` and `ra_lsp_server` to implement more advanced filtering. This allows
us to filter some unnecessary folders from external dependencies such as tests,
examples and benches.
Relates to discussion in #869
Co-authored-by: Ville Penttinen <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src/server_world.rs')
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index cf7c17c5c..af4798494 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -8,13 +8,14 @@ use ra_ide_api::{ | |||
8 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, | 8 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, |
9 | SourceRootId | 9 | SourceRootId |
10 | }; | 10 | }; |
11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot, RootEntry, Filter}; | 11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; |
12 | use relative_path::{RelativePath, RelativePathBuf}; | 12 | use relative_path::RelativePathBuf; |
13 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
14 | use failure::format_err; | 14 | use failure::format_err; |
15 | 15 | ||
16 | use crate::{ | 16 | use crate::{ |
17 | project_model::ProjectWorkspace, | 17 | project_model::ProjectWorkspace, |
18 | vfs_filter::IncludeRustFiles, | ||
18 | Result, | 19 | Result, |
19 | }; | 20 | }; |
20 | 21 | ||
@@ -33,40 +34,15 @@ pub struct ServerWorld { | |||
33 | pub vfs: Arc<RwLock<Vfs>>, | 34 | pub vfs: Arc<RwLock<Vfs>>, |
34 | } | 35 | } |
35 | 36 | ||
36 | struct IncludeRustFiles; | ||
37 | |||
38 | impl IncludeRustFiles { | ||
39 | fn to_entry(path: PathBuf) -> RootEntry { | ||
40 | RootEntry::new(path, Box::new(Self {})) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | impl Filter for IncludeRustFiles { | ||
45 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
46 | const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"]; | ||
47 | |||
48 | let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str())); | ||
49 | |||
50 | let hidden = dir_path.components().any(|c| c.as_str().starts_with(".")); | ||
51 | |||
52 | !is_ignored && !hidden | ||
53 | } | ||
54 | |||
55 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
56 | file_path.extension() == Some("rs") | ||
57 | } | ||
58 | } | ||
59 | |||
60 | impl ServerWorldState { | 37 | impl ServerWorldState { |
61 | pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState { | 38 | pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState { |
62 | let mut change = AnalysisChange::new(); | 39 | let mut change = AnalysisChange::new(); |
63 | 40 | ||
64 | let mut roots = Vec::new(); | 41 | let mut roots = Vec::new(); |
65 | roots.push(root.clone()); | 42 | roots.push(IncludeRustFiles::member(root.clone())); |
66 | for ws in workspaces.iter() { | 43 | for ws in workspaces.iter() { |
67 | roots.extend(ws.to_roots()); | 44 | roots.extend(IncludeRustFiles::from_roots(ws.to_roots())); |
68 | } | 45 | } |
69 | let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>(); | ||
70 | 46 | ||
71 | let (mut vfs, roots) = Vfs::new(roots); | 47 | let (mut vfs, roots) = Vfs::new(roots); |
72 | let roots_to_scan = roots.len(); | 48 | let roots_to_scan = roots.len(); |