diff options
author | Ville Penttinen <[email protected]> | 2019-03-18 17:23:54 +0000 |
---|---|---|
committer | Ville Penttinen <[email protected]> | 2019-03-18 18:53:08 +0000 |
commit | e70e2361b602f7837e8fbed36ae1c51cd8e2f3b5 (patch) | |
tree | 378e1f7c549a1ecf857df1019d74cdcb10d11d3e /crates/ra_lsp_server/src | |
parent | 1cd18f9237b6ac48ca8461307f2a4eaf273ee394 (diff) |
Upgrade ra_vfs to use new Filtering
Currently this matches the previous filtering, meaning all roots are filtered
using the same rules.
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 7163568b9..cf7c17c5c 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -8,8 +8,8 @@ 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}; | 11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot, RootEntry, Filter}; |
12 | use relative_path::RelativePathBuf; | 12 | use relative_path::{RelativePath, RelativePathBuf}; |
13 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
14 | use failure::format_err; | 14 | use failure::format_err; |
15 | 15 | ||
@@ -33,6 +33,30 @@ pub struct ServerWorld { | |||
33 | pub vfs: Arc<RwLock<Vfs>>, | 33 | pub vfs: Arc<RwLock<Vfs>>, |
34 | } | 34 | } |
35 | 35 | ||
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 | |||
36 | impl ServerWorldState { | 60 | impl ServerWorldState { |
37 | pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState { | 61 | pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState { |
38 | let mut change = AnalysisChange::new(); | 62 | let mut change = AnalysisChange::new(); |
@@ -42,6 +66,8 @@ impl ServerWorldState { | |||
42 | for ws in workspaces.iter() { | 66 | for ws in workspaces.iter() { |
43 | roots.extend(ws.to_roots()); | 67 | roots.extend(ws.to_roots()); |
44 | } | 68 | } |
69 | let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>(); | ||
70 | |||
45 | let (mut vfs, roots) = Vfs::new(roots); | 71 | let (mut vfs, roots) = Vfs::new(roots); |
46 | let roots_to_scan = roots.len(); | 72 | let roots_to_scan = roots.len(); |
47 | for r in roots { | 73 | for r in roots { |