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_batch | |
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_batch')
-rw-r--r-- | crates/ra_batch/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_batch/src/lib.rs | 29 |
2 files changed, 28 insertions, 3 deletions
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml index 5b78cb76e..3037e27c4 100644 --- a/crates/ra_batch/Cargo.toml +++ b/crates/ra_batch/Cargo.toml | |||
@@ -10,7 +10,7 @@ rustc-hash = "1.0" | |||
10 | 10 | ||
11 | failure = "0.1.4" | 11 | failure = "0.1.4" |
12 | 12 | ||
13 | ra_vfs = "0.1.0" | 13 | ra_vfs = "0.2.0" |
14 | ra_syntax = { path = "../ra_syntax" } | 14 | ra_syntax = { path = "../ra_syntax" } |
15 | ra_db = { path = "../ra_db" } | 15 | ra_db = { path = "../ra_db" } |
16 | ra_hir = { path = "../ra_hir" } | 16 | ra_hir = { path = "../ra_hir" } |
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index c6d10107d..a054d0da3 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | use std::path::Path; | 2 | use std::path::{Path, PathBuf}; |
3 | use std::collections::HashSet; | 3 | use std::collections::HashSet; |
4 | 4 | ||
5 | use rustc_hash::FxHashMap; | 5 | use rustc_hash::FxHashMap; |
@@ -9,7 +9,7 @@ use ra_db::{ | |||
9 | }; | 9 | }; |
10 | use ra_hir::{db, HirInterner}; | 10 | use ra_hir::{db, HirInterner}; |
11 | use ra_project_model::ProjectWorkspace; | 11 | use ra_project_model::ProjectWorkspace; |
12 | use ra_vfs::{Vfs, VfsChange}; | 12 | use ra_vfs::{Vfs, VfsChange, RootEntry, Filter, RelativePath}; |
13 | 13 | ||
14 | type Result<T> = std::result::Result<T, failure::Error>; | 14 | type Result<T> = std::result::Result<T, failure::Error>; |
15 | 15 | ||
@@ -43,6 +43,30 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { | |||
43 | SourceRootId(r.0.into()) | 43 | SourceRootId(r.0.into()) |
44 | } | 44 | } |
45 | 45 | ||
46 | struct IncludeRustFiles; | ||
47 | |||
48 | impl IncludeRustFiles { | ||
49 | fn to_entry(path: PathBuf) -> RootEntry { | ||
50 | RootEntry::new(path, Box::new(Self {})) | ||
51 | } | ||
52 | } | ||
53 | |||
54 | impl Filter for IncludeRustFiles { | ||
55 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
56 | const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"]; | ||
57 | |||
58 | let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str())); | ||
59 | |||
60 | let hidden = dir_path.components().any(|c| c.as_str().starts_with(".")); | ||
61 | |||
62 | !is_ignored && !hidden | ||
63 | } | ||
64 | |||
65 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
66 | file_path.extension() == Some("rs") | ||
67 | } | ||
68 | } | ||
69 | |||
46 | impl BatchDatabase { | 70 | impl BatchDatabase { |
47 | pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase { | 71 | pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase { |
48 | let mut db = | 72 | let mut db = |
@@ -100,6 +124,7 @@ impl BatchDatabase { | |||
100 | let mut roots = Vec::new(); | 124 | let mut roots = Vec::new(); |
101 | roots.push(root.clone()); | 125 | roots.push(root.clone()); |
102 | roots.extend(ws.to_roots()); | 126 | roots.extend(ws.to_roots()); |
127 | let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>(); | ||
103 | let (mut vfs, roots) = Vfs::new(roots); | 128 | let (mut vfs, roots) = Vfs::new(roots); |
104 | let mut load = |path: &Path| { | 129 | let mut load = |path: &Path| { |
105 | let vfs_file = vfs.load(path); | 130 | let vfs_file = vfs.load(path); |