Skip to content

Commit 132b207

Browse files
bors[bot]vipentti
andcommitted
Merge #994
994: Upgrade ra_vfs to use new Filtering r=matklad a=vipentti Upgrade `ra_vfs` to `0.2.0` that includes the filtering. Currently this matches the previous filtering, meaning all roots are filtered using the same rules. Co-authored-by: Ville Penttinen <[email protected]>
2 parents 1cd18f9 + e70e236 commit 132b207

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_batch/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ rustc-hash = "1.0"
1010

1111
failure = "0.1.4"
1212

13-
ra_vfs = "0.1.0"
13+
ra_vfs = "0.2.0"
1414
ra_syntax = { path = "../ra_syntax" }
1515
ra_db = { path = "../ra_db" }
1616
ra_hir = { path = "../ra_hir" }

crates/ra_batch/src/lib.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::sync::Arc;
2-
use std::path::Path;
2+
use std::path::{Path, PathBuf};
33
use std::collections::HashSet;
44

55
use rustc_hash::FxHashMap;
@@ -9,7 +9,7 @@ use ra_db::{
99
};
1010
use ra_hir::{db, HirInterner};
1111
use ra_project_model::ProjectWorkspace;
12-
use ra_vfs::{Vfs, VfsChange};
12+
use ra_vfs::{Vfs, VfsChange, RootEntry, Filter, RelativePath};
1313

1414
type Result<T> = std::result::Result<T, failure::Error>;
1515

@@ -43,6 +43,30 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
4343
SourceRootId(r.0.into())
4444
}
4545

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+
4670
impl BatchDatabase {
4771
pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase {
4872
let mut db =
@@ -100,6 +124,7 @@ impl BatchDatabase {
100124
let mut roots = Vec::new();
101125
roots.push(root.clone());
102126
roots.extend(ws.to_roots());
127+
let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>();
103128
let (mut vfs, roots) = Vfs::new(roots);
104129
let mut load = |path: &Path| {
105130
let vfs_file = vfs.load(path);

crates/ra_lsp_server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ lsp-types = "0.56.0"
1919
rustc-hash = "1.0"
2020
parking_lot = "0.7.0"
2121

22-
ra_vfs = "0.1.0"
22+
ra_vfs = "0.2.0"
2323
thread_worker = { path = "../thread_worker" }
2424
ra_syntax = { path = "../ra_syntax" }
2525
ra_text_edit = { path = "../ra_text_edit" }

crates/ra_lsp_server/src/server_world.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use ra_ide_api::{
88
Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData,
99
SourceRootId
1010
};
11-
use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
12-
use relative_path::RelativePathBuf;
11+
use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot, RootEntry, Filter};
12+
use relative_path::{RelativePath, RelativePathBuf};
1313
use parking_lot::RwLock;
1414
use failure::format_err;
1515

@@ -33,6 +33,30 @@ pub struct ServerWorld {
3333
pub vfs: Arc<RwLock<Vfs>>,
3434
}
3535

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+
3660
impl ServerWorldState {
3761
pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState {
3862
let mut change = AnalysisChange::new();
@@ -42,6 +66,8 @@ impl ServerWorldState {
4266
for ws in workspaces.iter() {
4367
roots.extend(ws.to_roots());
4468
}
69+
let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>();
70+
4571
let (mut vfs, roots) = Vfs::new(roots);
4672
let roots_to_scan = roots.len();
4773
for r in roots {

0 commit comments

Comments
 (0)