diff options
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 34 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/vfs_filter.rs | 59 |
3 files changed, 65 insertions, 29 deletions
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 59e16a47c..113883bdd 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -4,6 +4,7 @@ mod conv; | |||
4 | mod main_loop; | 4 | mod main_loop; |
5 | mod markdown; | 5 | mod markdown; |
6 | mod project_model; | 6 | mod project_model; |
7 | mod vfs_filter; | ||
7 | pub mod req; | 8 | pub mod req; |
8 | pub mod init; | 9 | pub mod init; |
9 | mod server_world; | 10 | mod server_world; |
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(); |
diff --git a/crates/ra_lsp_server/src/vfs_filter.rs b/crates/ra_lsp_server/src/vfs_filter.rs new file mode 100644 index 000000000..290aec172 --- /dev/null +++ b/crates/ra_lsp_server/src/vfs_filter.rs | |||
@@ -0,0 +1,59 @@ | |||
1 | use std::path::PathBuf; | ||
2 | use ra_project_model::ProjectRoot; | ||
3 | use ra_vfs::{RootEntry, Filter, RelativePath}; | ||
4 | |||
5 | pub struct IncludeRustFiles { | ||
6 | /// Is a member of the current workspace | ||
7 | is_member: bool, | ||
8 | } | ||
9 | |||
10 | impl IncludeRustFiles { | ||
11 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | ||
12 | where | ||
13 | R: IntoIterator<Item = ProjectRoot>, | ||
14 | { | ||
15 | roots.into_iter().map(IncludeRustFiles::from_root) | ||
16 | } | ||
17 | |||
18 | pub fn from_root(root: ProjectRoot) -> RootEntry { | ||
19 | let is_member = root.is_member(); | ||
20 | IncludeRustFiles::into_entry(root.into_path(), is_member) | ||
21 | } | ||
22 | |||
23 | #[allow(unused)] | ||
24 | pub fn external(path: PathBuf) -> RootEntry { | ||
25 | IncludeRustFiles::into_entry(path, false) | ||
26 | } | ||
27 | |||
28 | pub fn member(path: PathBuf) -> RootEntry { | ||
29 | IncludeRustFiles::into_entry(path, true) | ||
30 | } | ||
31 | |||
32 | fn into_entry(path: PathBuf, is_member: bool) -> RootEntry { | ||
33 | RootEntry::new(path, Box::new(Self { is_member })) | ||
34 | } | ||
35 | } | ||
36 | |||
37 | impl Filter for IncludeRustFiles { | ||
38 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
39 | const COMMON_IGNORED_DIRS: &[&str] = &["node_modules", "target", ".git"]; | ||
40 | const EXTERNAL_IGNORED_DIRS: &[&str] = &["examples", "tests", "benches"]; | ||
41 | |||
42 | let is_ignored = if self.is_member { | ||
43 | dir_path.components().any(|c| COMMON_IGNORED_DIRS.contains(&c.as_str())) | ||
44 | } else { | ||
45 | dir_path.components().any(|c| { | ||
46 | let path = c.as_str(); | ||
47 | COMMON_IGNORED_DIRS.contains(&path) || EXTERNAL_IGNORED_DIRS.contains(&path) | ||
48 | }) | ||
49 | }; | ||
50 | |||
51 | let hidden = dir_path.components().any(|c| c.as_str().starts_with(".")); | ||
52 | |||
53 | !is_ignored && !hidden | ||
54 | } | ||
55 | |||
56 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
57 | file_path.extension() == Some("rs") | ||
58 | } | ||
59 | } | ||