diff options
author | Aleksey Kladov <[email protected]> | 2019-08-06 12:00:37 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-08-06 13:28:31 +0100 |
commit | 34203256bf8f8ea12b233e0fb49b42bd8c423281 (patch) | |
tree | 79ac51baa1696e06955ced637b6132c6a4eabf48 | |
parent | c9718691043b041f5db878caea687b5a029d4475 (diff) |
introduce ra_vfs_glob crate
It manages exclusion rules for the vfs crate
-rw-r--r-- | Cargo.lock | 39 | ||||
-rw-r--r-- | crates/ra_batch/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_batch/src/lib.rs | 20 | ||||
-rw-r--r-- | crates/ra_batch/src/vfs_filter.rs | 54 | ||||
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/vfs_filter.rs | 54 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/world.rs | 20 | ||||
-rw-r--r-- | crates/ra_project_model/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_project_model/src/lib.rs | 23 | ||||
-rw-r--r-- | crates/ra_vfs_glob/Cargo.toml | 9 | ||||
-rw-r--r-- | crates/ra_vfs_glob/src/lib.rs | 93 |
12 files changed, 173 insertions, 143 deletions
diff --git a/Cargo.lock b/Cargo.lock index a5f56853d..365b77f41 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -118,6 +118,14 @@ dependencies = [ | |||
118 | ] | 118 | ] |
119 | 119 | ||
120 | [[package]] | 120 | [[package]] |
121 | name = "bstr" | ||
122 | version = "0.2.6" | ||
123 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
124 | dependencies = [ | ||
125 | "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
126 | ] | ||
127 | |||
128 | [[package]] | ||
121 | name = "byte-tools" | 129 | name = "byte-tools" |
122 | version = "0.3.1" | 130 | version = "0.3.1" |
123 | source = "registry+https://github.com/rust-lang/crates.io-index" | 131 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -479,6 +487,11 @@ dependencies = [ | |||
479 | ] | 487 | ] |
480 | 488 | ||
481 | [[package]] | 489 | [[package]] |
490 | name = "fnv" | ||
491 | version = "1.0.6" | ||
492 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
493 | |||
494 | [[package]] | ||
482 | name = "format-buf" | 495 | name = "format-buf" |
483 | version = "1.0.0" | 496 | version = "1.0.0" |
484 | source = "registry+https://github.com/rust-lang/crates.io-index" | 497 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -572,6 +585,18 @@ version = "0.3.0" | |||
572 | source = "registry+https://github.com/rust-lang/crates.io-index" | 585 | source = "registry+https://github.com/rust-lang/crates.io-index" |
573 | 586 | ||
574 | [[package]] | 587 | [[package]] |
588 | name = "globset" | ||
589 | version = "0.4.4" | ||
590 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
591 | dependencies = [ | ||
592 | "aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
593 | "bstr 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
594 | "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||
595 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||
596 | "regex 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||
597 | ] | ||
598 | |||
599 | [[package]] | ||
575 | name = "heck" | 600 | name = "heck" |
576 | version = "0.3.1" | 601 | version = "0.3.1" |
577 | source = "registry+https://github.com/rust-lang/crates.io-index" | 602 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1145,6 +1170,7 @@ dependencies = [ | |||
1145 | "ra_ide_api 0.1.0", | 1170 | "ra_ide_api 0.1.0", |
1146 | "ra_project_model 0.1.0", | 1171 | "ra_project_model 0.1.0", |
1147 | "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", | 1172 | "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", |
1173 | "ra_vfs_glob 0.1.0", | ||
1148 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1174 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1149 | ] | 1175 | ] |
1150 | 1176 | ||
@@ -1250,6 +1276,7 @@ dependencies = [ | |||
1250 | "ra_syntax 0.1.0", | 1276 | "ra_syntax 0.1.0", |
1251 | "ra_text_edit 0.1.0", | 1277 | "ra_text_edit 0.1.0", |
1252 | "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", | 1278 | "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", |
1279 | "ra_vfs_glob 0.1.0", | ||
1253 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1280 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1254 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1281 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1255 | "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", | 1282 | "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1301,7 +1328,6 @@ dependencies = [ | |||
1301 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", | 1328 | "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", |
1302 | "ra_arena 0.1.0", | 1329 | "ra_arena 0.1.0", |
1303 | "ra_db 0.1.0", | 1330 | "ra_db 0.1.0", |
1304 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1305 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1331 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1306 | "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", | 1332 | "serde 1.0.98 (registry+https://github.com/rust-lang/crates.io-index)", |
1307 | "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", | 1333 | "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1370,6 +1396,14 @@ dependencies = [ | |||
1370 | ] | 1396 | ] |
1371 | 1397 | ||
1372 | [[package]] | 1398 | [[package]] |
1399 | name = "ra_vfs_glob" | ||
1400 | version = "0.1.0" | ||
1401 | dependencies = [ | ||
1402 | "globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1403 | "ra_vfs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", | ||
1404 | ] | ||
1405 | |||
1406 | [[package]] | ||
1373 | name = "rand" | 1407 | name = "rand" |
1374 | version = "0.6.5" | 1408 | version = "0.6.5" |
1375 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1409 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -2116,6 +2150,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
2116 | "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" | 2150 | "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" |
2117 | "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" | 2151 | "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" |
2118 | "checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" | 2152 | "checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" |
2153 | "checksum bstr 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e0a692f1c740e7e821ca71a22cf99b9b2322dfa94d10f71443befb1797b3946a" | ||
2119 | "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" | 2154 | "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" |
2120 | "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" | 2155 | "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" |
2121 | "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" | 2156 | "checksum c2-chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7d64d04786e0f528460fc884753cf8dddcc466be308f6026f8e355c41a0e4101" |
@@ -2158,6 +2193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
2158 | "checksum filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d" | 2193 | "checksum filetime 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2f8c63033fcba1f51ef744505b3cad42510432b904c062afa67ad7ece008429d" |
2159 | "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" | 2194 | "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" |
2160 | "checksum flexi_logger 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2be2727ae1f60711d1991788605245e70cc500bd1d92edb909af160634e1a869" | 2195 | "checksum flexi_logger 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2be2727ae1f60711d1991788605245e70cc500bd1d92edb909af160634e1a869" |
2196 | "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" | ||
2161 | "checksum format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f7aea5a5909a74969507051a3b17adc84737e31a5f910559892aedce026f4d53" | 2197 | "checksum format-buf 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f7aea5a5909a74969507051a3b17adc84737e31a5f910559892aedce026f4d53" |
2162 | "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" | 2198 | "checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674" |
2163 | "checksum fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" | 2199 | "checksum fsevent 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5ab7d1bd1bd33cc98b0889831b72da23c0aa4df9cec7e0702f46ecea04b35db6" |
@@ -2170,6 +2206,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
2170 | "checksum getrandom 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "34f33de6f0ae7c9cb5e574502a562e2b512799e32abb801cd1e79ad952b62b49" | 2206 | "checksum getrandom 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "34f33de6f0ae7c9cb5e574502a562e2b512799e32abb801cd1e79ad952b62b49" |
2171 | "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" | 2207 | "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" |
2172 | "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" | 2208 | "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" |
2209 | "checksum globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "925aa2cac82d8834e2b2a4415b6f6879757fb5c0928fc445ae76461a12eed8f2" | ||
2173 | "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" | 2210 | "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" |
2174 | "checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" | 2211 | "checksum humansize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" |
2175 | "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" | 2212 | "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" |
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml index 0ee94c445..8e23826a4 100644 --- a/crates/ra_batch/Cargo.toml +++ b/crates/ra_batch/Cargo.toml | |||
@@ -9,6 +9,7 @@ log = "0.4.5" | |||
9 | rustc-hash = "1.0" | 9 | rustc-hash = "1.0" |
10 | 10 | ||
11 | ra_vfs = "0.2.0" | 11 | ra_vfs = "0.2.0" |
12 | ra_vfs_glob = { path = "../ra_vfs_glob" } | ||
12 | ra_db = { path = "../ra_db" } | 13 | ra_db = { path = "../ra_db" } |
13 | ra_ide_api = { path = "../ra_ide_api" } | 14 | ra_ide_api = { path = "../ra_ide_api" } |
14 | ra_hir = { path = "../ra_hir" } | 15 | ra_hir = { path = "../ra_hir" } |
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index c01574fbc..0db751465 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -1,5 +1,3 @@ | |||
1 | mod vfs_filter; | ||
2 | |||
3 | use std::{collections::HashSet, error::Error, path::Path}; | 1 | use std::{collections::HashSet, error::Error, path::Path}; |
4 | 2 | ||
5 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::FxHashMap; |
@@ -7,8 +5,8 @@ use rustc_hash::FxHashMap; | |||
7 | use ra_db::{CrateGraph, FileId, SourceRootId}; | 5 | use ra_db::{CrateGraph, FileId, SourceRootId}; |
8 | use ra_ide_api::{AnalysisChange, AnalysisHost}; | 6 | use ra_ide_api::{AnalysisChange, AnalysisHost}; |
9 | use ra_project_model::{PackageRoot, ProjectWorkspace}; | 7 | use ra_project_model::{PackageRoot, ProjectWorkspace}; |
10 | use ra_vfs::{Vfs, VfsChange}; | 8 | use ra_vfs::{RootEntry, Vfs, VfsChange}; |
11 | use vfs_filter::IncludeRustFiles; | 9 | use ra_vfs_glob::RustPackageFilterBuilder; |
12 | 10 | ||
13 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; | 11 | type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>; |
14 | 12 | ||
@@ -23,7 +21,19 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, | |||
23 | let root = std::env::current_dir()?.join(root); | 21 | let root = std::env::current_dir()?.join(root); |
24 | let ws = ProjectWorkspace::discover(root.as_ref())?; | 22 | let ws = ProjectWorkspace::discover(root.as_ref())?; |
25 | let project_roots = ws.to_roots(); | 23 | let project_roots = ws.to_roots(); |
26 | let (mut vfs, roots) = Vfs::new(IncludeRustFiles::from_roots(project_roots.clone()).collect()); | 24 | let (mut vfs, roots) = Vfs::new( |
25 | project_roots | ||
26 | .iter() | ||
27 | .map(|pkg_root| { | ||
28 | RootEntry::new( | ||
29 | pkg_root.path().clone(), | ||
30 | RustPackageFilterBuilder::default() | ||
31 | .set_member(pkg_root.is_member()) | ||
32 | .into_vfs_filter(), | ||
33 | ) | ||
34 | }) | ||
35 | .collect(), | ||
36 | ); | ||
27 | let crate_graph = ws.to_crate_graph(&mut |path: &Path| { | 37 | let crate_graph = ws.to_crate_graph(&mut |path: &Path| { |
28 | let vfs_file = vfs.load(path); | 38 | let vfs_file = vfs.load(path); |
29 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); | 39 | log::debug!("vfs file {:?} -> {:?}", path, vfs_file); |
diff --git a/crates/ra_batch/src/vfs_filter.rs b/crates/ra_batch/src/vfs_filter.rs deleted file mode 100644 index 63bf77704..000000000 --- a/crates/ra_batch/src/vfs_filter.rs +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | use ra_project_model::PackageRoot; | ||
2 | use ra_vfs::{Filter, RelativePath, RootEntry}; | ||
3 | use std::path::PathBuf; | ||
4 | |||
5 | /// `IncludeRustFiles` is used to convert | ||
6 | /// from `PackageRoot` to `RootEntry` for VFS | ||
7 | pub struct IncludeRustFiles { | ||
8 | root: PackageRoot, | ||
9 | } | ||
10 | |||
11 | impl IncludeRustFiles { | ||
12 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | ||
13 | where | ||
14 | R: IntoIterator<Item = PackageRoot>, | ||
15 | { | ||
16 | roots.into_iter().map(IncludeRustFiles::from_root) | ||
17 | } | ||
18 | |||
19 | pub fn from_root(root: PackageRoot) -> RootEntry { | ||
20 | IncludeRustFiles::from(root).into() | ||
21 | } | ||
22 | |||
23 | #[allow(unused)] | ||
24 | pub fn external(path: PathBuf) -> RootEntry { | ||
25 | IncludeRustFiles::from_root(PackageRoot::new(path, false)) | ||
26 | } | ||
27 | |||
28 | pub fn member(path: PathBuf) -> RootEntry { | ||
29 | IncludeRustFiles::from_root(PackageRoot::new(path, true)) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | impl Filter for IncludeRustFiles { | ||
34 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
35 | self.root.include_dir(dir_path) | ||
36 | } | ||
37 | |||
38 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
39 | self.root.include_file(file_path) | ||
40 | } | ||
41 | } | ||
42 | |||
43 | impl From<PackageRoot> for IncludeRustFiles { | ||
44 | fn from(v: PackageRoot) -> IncludeRustFiles { | ||
45 | IncludeRustFiles { root: v } | ||
46 | } | ||
47 | } | ||
48 | |||
49 | impl From<IncludeRustFiles> for RootEntry { | ||
50 | fn from(v: IncludeRustFiles) -> RootEntry { | ||
51 | let path = v.root.path().clone(); | ||
52 | RootEntry::new(path, Box::new(v)) | ||
53 | } | ||
54 | } | ||
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index cec360667..c282d6db8 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -25,6 +25,7 @@ ra_ide_api = { path = "../ra_ide_api" } | |||
25 | gen_lsp_server = { path = "../gen_lsp_server" } | 25 | gen_lsp_server = { path = "../gen_lsp_server" } |
26 | ra_project_model = { path = "../ra_project_model" } | 26 | ra_project_model = { path = "../ra_project_model" } |
27 | ra_prof = { path = "../ra_prof" } | 27 | ra_prof = { path = "../ra_prof" } |
28 | ra_vfs_glob = { path = "../ra_vfs_glob" } | ||
28 | 29 | ||
29 | [dev-dependencies] | 30 | [dev-dependencies] |
30 | tempfile = "3" | 31 | tempfile = "3" |
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 56a263aa5..2ae6300c8 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -4,7 +4,6 @@ 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; | ||
8 | pub mod req; | 7 | pub mod req; |
9 | pub mod init; | 8 | pub mod init; |
10 | mod world; | 9 | mod world; |
diff --git a/crates/ra_lsp_server/src/vfs_filter.rs b/crates/ra_lsp_server/src/vfs_filter.rs deleted file mode 100644 index abdc8dbad..000000000 --- a/crates/ra_lsp_server/src/vfs_filter.rs +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | use ra_project_model::PackageRoot; | ||
2 | use ra_vfs::{Filter, RelativePath, RootEntry}; | ||
3 | use std::path::PathBuf; | ||
4 | |||
5 | /// `IncludeRustFiles` is used to convert | ||
6 | /// from `PackageRoot` to `RootEntry` for VFS | ||
7 | pub struct IncludeRustFiles { | ||
8 | root: PackageRoot, | ||
9 | } | ||
10 | |||
11 | impl IncludeRustFiles { | ||
12 | pub fn from_roots<R>(roots: R) -> impl Iterator<Item = RootEntry> | ||
13 | where | ||
14 | R: IntoIterator<Item = PackageRoot>, | ||
15 | { | ||
16 | roots.into_iter().map(IncludeRustFiles::from_root) | ||
17 | } | ||
18 | |||
19 | pub fn from_root(root: PackageRoot) -> RootEntry { | ||
20 | IncludeRustFiles::from(root).into() | ||
21 | } | ||
22 | |||
23 | #[allow(unused)] | ||
24 | pub fn external(path: PathBuf) -> RootEntry { | ||
25 | IncludeRustFiles::from_root(PackageRoot::new(path, false)) | ||
26 | } | ||
27 | |||
28 | pub fn member(path: PathBuf) -> RootEntry { | ||
29 | IncludeRustFiles::from_root(PackageRoot::new(path, true)) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | impl Filter for IncludeRustFiles { | ||
34 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
35 | self.root.include_dir(dir_path) | ||
36 | } | ||
37 | |||
38 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
39 | self.root.include_file(file_path) | ||
40 | } | ||
41 | } | ||
42 | |||
43 | impl std::convert::From<PackageRoot> for IncludeRustFiles { | ||
44 | fn from(v: PackageRoot) -> IncludeRustFiles { | ||
45 | IncludeRustFiles { root: v } | ||
46 | } | ||
47 | } | ||
48 | |||
49 | impl std::convert::From<IncludeRustFiles> for RootEntry { | ||
50 | fn from(v: IncludeRustFiles) -> RootEntry { | ||
51 | let path = v.root.path().clone(); | ||
52 | RootEntry::new(path, Box::new(v)) | ||
53 | } | ||
54 | } | ||
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index b57cdf925..a8aafe5cb 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs | |||
@@ -9,13 +9,13 @@ use parking_lot::RwLock; | |||
9 | use ra_ide_api::{ | 9 | use ra_ide_api::{ |
10 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, | 10 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, |
11 | }; | 11 | }; |
12 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; | 12 | use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile, VfsRoot}; |
13 | use ra_vfs_glob::RustPackageFilterBuilder; | ||
13 | use relative_path::RelativePathBuf; | 14 | use relative_path::RelativePathBuf; |
14 | 15 | ||
15 | use crate::{ | 16 | use crate::{ |
16 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, | 17 | main_loop::pending_requests::{CompletedRequest, LatestRequests}, |
17 | project_model::ProjectWorkspace, | 18 | project_model::ProjectWorkspace, |
18 | vfs_filter::IncludeRustFiles, | ||
19 | LspError, Result, | 19 | LspError, Result, |
20 | }; | 20 | }; |
21 | 21 | ||
@@ -61,9 +61,21 @@ impl WorldState { | |||
61 | let mut change = AnalysisChange::new(); | 61 | let mut change = AnalysisChange::new(); |
62 | 62 | ||
63 | let mut roots = Vec::new(); | 63 | let mut roots = Vec::new(); |
64 | roots.extend(folder_roots.iter().cloned().map(IncludeRustFiles::member)); | 64 | roots.extend(folder_roots.iter().map(|path| { |
65 | RootEntry::new( | ||
66 | path.clone(), | ||
67 | RustPackageFilterBuilder::default().set_member(true).into_vfs_filter(), | ||
68 | ) | ||
69 | })); | ||
65 | for ws in workspaces.iter() { | 70 | for ws in workspaces.iter() { |
66 | roots.extend(IncludeRustFiles::from_roots(ws.to_roots())); | 71 | roots.extend(ws.to_roots().into_iter().map(|pkg_root| { |
72 | RootEntry::new( | ||
73 | pkg_root.path().clone(), | ||
74 | RustPackageFilterBuilder::default() | ||
75 | .set_member(pkg_root.is_member()) | ||
76 | .into_vfs_filter(), | ||
77 | ) | ||
78 | })); | ||
67 | } | 79 | } |
68 | 80 | ||
69 | let (mut vfs, vfs_roots) = Vfs::new(roots); | 81 | let (mut vfs, vfs_roots) = Vfs::new(roots); |
diff --git a/crates/ra_project_model/Cargo.toml b/crates/ra_project_model/Cargo.toml index 3545d23c9..4fd6c75ef 100644 --- a/crates/ra_project_model/Cargo.toml +++ b/crates/ra_project_model/Cargo.toml | |||
@@ -7,7 +7,6 @@ authors = ["rust-analyzer developers"] | |||
7 | [dependencies] | 7 | [dependencies] |
8 | log = "0.4.5" | 8 | log = "0.4.5" |
9 | rustc-hash = "1.0" | 9 | rustc-hash = "1.0" |
10 | relative-path = "0.4.0" | ||
11 | 10 | ||
12 | cargo_metadata = "0.8.0" | 11 | cargo_metadata = "0.8.0" |
13 | 12 | ||
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index c7167046b..55b94b911 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -10,7 +10,6 @@ use std::{ | |||
10 | }; | 10 | }; |
11 | 11 | ||
12 | use ra_db::{CrateGraph, Edition, FileId}; | 12 | use ra_db::{CrateGraph, Edition, FileId}; |
13 | use relative_path::RelativePath; | ||
14 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashMap; |
15 | use serde_json::from_reader; | 14 | use serde_json::from_reader; |
16 | 15 | ||
@@ -54,28 +53,6 @@ impl PackageRoot { | |||
54 | pub fn is_member(&self) -> bool { | 53 | pub fn is_member(&self) -> bool { |
55 | self.is_member | 54 | self.is_member |
56 | } | 55 | } |
57 | |||
58 | pub fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
59 | const COMMON_IGNORED_DIRS: &[&str] = &["node_modules", "target", ".git"]; | ||
60 | const EXTERNAL_IGNORED_DIRS: &[&str] = &["examples", "tests", "benches"]; | ||
61 | |||
62 | let is_ignored = if self.is_member { | ||
63 | dir_path.components().any(|c| COMMON_IGNORED_DIRS.contains(&c.as_str())) | ||
64 | } else { | ||
65 | dir_path.components().any(|c| { | ||
66 | let path = c.as_str(); | ||
67 | COMMON_IGNORED_DIRS.contains(&path) || EXTERNAL_IGNORED_DIRS.contains(&path) | ||
68 | }) | ||
69 | }; | ||
70 | |||
71 | let hidden = dir_path.components().any(|c| c.as_str().starts_with('.')); | ||
72 | |||
73 | !is_ignored && !hidden | ||
74 | } | ||
75 | |||
76 | pub fn include_file(&self, file_path: &RelativePath) -> bool { | ||
77 | file_path.extension() == Some("rs") | ||
78 | } | ||
79 | } | 56 | } |
80 | 57 | ||
81 | impl ProjectWorkspace { | 58 | impl ProjectWorkspace { |
diff --git a/crates/ra_vfs_glob/Cargo.toml b/crates/ra_vfs_glob/Cargo.toml new file mode 100644 index 000000000..0390d7da1 --- /dev/null +++ b/crates/ra_vfs_glob/Cargo.toml | |||
@@ -0,0 +1,9 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_vfs_glob" | ||
4 | version = "0.1.0" | ||
5 | authors = ["rust-analyzer developers"] | ||
6 | |||
7 | [dependencies] | ||
8 | ra_vfs = "0.2.0" | ||
9 | globset = "0.4.4" | ||
diff --git a/crates/ra_vfs_glob/src/lib.rs b/crates/ra_vfs_glob/src/lib.rs new file mode 100644 index 000000000..3e54da5fe --- /dev/null +++ b/crates/ra_vfs_glob/src/lib.rs | |||
@@ -0,0 +1,93 @@ | |||
1 | //! `ra_vfs_glob` crate implements exclusion rules for vfs. | ||
2 | //! | ||
3 | //! By default, we include only `.rs` files, and skip some know offenders like | ||
4 | //! `/target` or `/node_modules` altogether. | ||
5 | //! | ||
6 | //! It's also possible to add custom exclusion globs. | ||
7 | |||
8 | use globset::{Glob, GlobSet, GlobSetBuilder}; | ||
9 | use ra_vfs::{Filter, RelativePath}; | ||
10 | |||
11 | const ALWAYS_IGNORED: &[&str] = &["target/**", "**/node_modules/**", "**/.git/**"]; | ||
12 | const IGNORED_FOR_NON_MEMBERS: &[&str] = &["examples/**", "tests/**", "benches/**"]; | ||
13 | |||
14 | pub struct RustPackageFilterBuilder { | ||
15 | is_member: bool, | ||
16 | exclude: GlobSetBuilder, | ||
17 | } | ||
18 | |||
19 | impl Default for RustPackageFilterBuilder { | ||
20 | fn default() -> RustPackageFilterBuilder { | ||
21 | RustPackageFilterBuilder { is_member: false, exclude: GlobSetBuilder::new() } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | impl RustPackageFilterBuilder { | ||
26 | pub fn set_member(mut self, is_member: bool) -> RustPackageFilterBuilder { | ||
27 | self.is_member = is_member; | ||
28 | self | ||
29 | } | ||
30 | pub fn exclude(mut self, glob: &str) -> Result<RustPackageFilterBuilder, globset::Error> { | ||
31 | self.exclude.add(Glob::new(glob)?); | ||
32 | Ok(self) | ||
33 | } | ||
34 | pub fn into_vfs_filter(self) -> Box<dyn Filter> { | ||
35 | let RustPackageFilterBuilder { is_member, mut exclude } = self; | ||
36 | for &glob in ALWAYS_IGNORED { | ||
37 | exclude.add(Glob::new(glob).unwrap()); | ||
38 | } | ||
39 | if !is_member { | ||
40 | for &glob in IGNORED_FOR_NON_MEMBERS { | ||
41 | exclude.add(Glob::new(glob).unwrap()); | ||
42 | } | ||
43 | } | ||
44 | Box::new(RustPackageFilter { exclude: exclude.build().unwrap() }) | ||
45 | } | ||
46 | } | ||
47 | |||
48 | struct RustPackageFilter { | ||
49 | exclude: GlobSet, | ||
50 | } | ||
51 | |||
52 | impl Filter for RustPackageFilter { | ||
53 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
54 | !self.exclude.is_match(dir_path.as_str()) | ||
55 | } | ||
56 | |||
57 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
58 | file_path.extension() == Some("rs") | ||
59 | } | ||
60 | } | ||
61 | |||
62 | #[test] | ||
63 | fn test_globs() { | ||
64 | let filter = RustPackageFilterBuilder::default().set_member(true).into_vfs_filter(); | ||
65 | |||
66 | assert!(filter.include_dir(RelativePath::new("src/tests"))); | ||
67 | assert!(filter.include_dir(RelativePath::new("src/target"))); | ||
68 | assert!(filter.include_dir(RelativePath::new("tests"))); | ||
69 | assert!(filter.include_dir(RelativePath::new("benches"))); | ||
70 | |||
71 | assert!(!filter.include_dir(RelativePath::new("target"))); | ||
72 | assert!(!filter.include_dir(RelativePath::new("src/foo/.git"))); | ||
73 | assert!(!filter.include_dir(RelativePath::new("foo/node_modules"))); | ||
74 | |||
75 | let filter = RustPackageFilterBuilder::default().set_member(false).into_vfs_filter(); | ||
76 | |||
77 | assert!(filter.include_dir(RelativePath::new("src/tests"))); | ||
78 | assert!(filter.include_dir(RelativePath::new("src/target"))); | ||
79 | |||
80 | assert!(!filter.include_dir(RelativePath::new("target"))); | ||
81 | assert!(!filter.include_dir(RelativePath::new("src/foo/.git"))); | ||
82 | assert!(!filter.include_dir(RelativePath::new("foo/node_modules"))); | ||
83 | assert!(!filter.include_dir(RelativePath::new("tests"))); | ||
84 | assert!(!filter.include_dir(RelativePath::new("benches"))); | ||
85 | |||
86 | let filter = RustPackageFilterBuilder::default() | ||
87 | .set_member(true) | ||
88 | .exclude("src/llvm-project/**") | ||
89 | .unwrap() | ||
90 | .into_vfs_filter(); | ||
91 | |||
92 | assert!(!filter.include_dir(RelativePath::new("src/llvm-project/clang"))); | ||
93 | } | ||