about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-18 19:08:32 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-18 19:08:32 +0000
commit132b207a228d0c588b08bbfffd53002b46521a1e (patch)
tree378e1f7c549a1ecf857df1019d74cdcb10d11d3e
parent1cd18f9237b6ac48ca8461307f2a4eaf273ee394 (diff)
parente70e2361b602f7837e8fbed36ae1c51cd8e2f3b5 (diff)
downloadrust-132b207a228d0c588b08bbfffd53002b46521a1e.tar.gz
rust-132b207a228d0c588b08bbfffd53002b46521a1e.zip
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 <villem.penttinen@gmail.com>
-rw-r--r--Cargo.lock8
-rw-r--r--crates/ra_batch/Cargo.toml2
-rw-r--r--crates/ra_batch/src/lib.rs29
-rw-r--r--crates/ra_lsp_server/Cargo.toml2
-rw-r--r--crates/ra_lsp_server/src/server_world.rs30
5 files changed, 61 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6f4c4f767b5..ad9f6970b39 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -928,7 +928,7 @@ dependencies = [
  "ra_hir 0.1.0",
  "ra_project_model 0.1.0",
  "ra_syntax 0.1.0",
- "ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "test_utils 0.1.0",
 ]
@@ -1050,7 +1050,7 @@ dependencies = [
  "ra_project_model 0.1.0",
  "ra_syntax 0.1.0",
  "ra_text_edit 0.1.0",
- "ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1131,7 +1131,7 @@ dependencies = [
 
 [[package]]
 name = "ra_vfs"
-version = "0.1.1"
+version = "0.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1996,7 +1996,7 @@ dependencies = [
 "checksum proptest 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea66c78d75f2c6e9f304269eaef90899798daecc69f1a625d5a3dd793ff3522"
 "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
 "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1"
-"checksum ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5978b0ced52f013ce44bfca6ac903141359e7cc3baea462a4a670de9e5087101"
+"checksum ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1839e4e003d865b58b8b6c231aae6c463dfcd01bfbbddffbdb7662a7b5a627"
 "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca"
 "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
 "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml
index 5b78cb76ed6..3037e27c418 100644
--- a/crates/ra_batch/Cargo.toml
+++ b/crates/ra_batch/Cargo.toml
@@ -10,7 +10,7 @@ rustc-hash = "1.0"
 
 failure = "0.1.4"
 
-ra_vfs = "0.1.0"
+ra_vfs = "0.2.0"
 ra_syntax = { path = "../ra_syntax" }
 ra_db = { path = "../ra_db" }
 ra_hir = { path = "../ra_hir" }
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs
index c6d10107d18..a054d0da30e 100644
--- a/crates/ra_batch/src/lib.rs
+++ b/crates/ra_batch/src/lib.rs
@@ -1,5 +1,5 @@
 use std::sync::Arc;
-use std::path::Path;
+use std::path::{Path, PathBuf};
 use std::collections::HashSet;
 
 use rustc_hash::FxHashMap;
@@ -9,7 +9,7 @@ use ra_db::{
 };
 use ra_hir::{db, HirInterner};
 use ra_project_model::ProjectWorkspace;
-use ra_vfs::{Vfs, VfsChange};
+use ra_vfs::{Vfs, VfsChange, RootEntry, Filter, RelativePath};
 
 type Result<T> = std::result::Result<T, failure::Error>;
 
@@ -43,6 +43,30 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
     SourceRootId(r.0.into())
 }
 
+struct IncludeRustFiles;
+
+impl IncludeRustFiles {
+    fn to_entry(path: PathBuf) -> RootEntry {
+        RootEntry::new(path, Box::new(Self {}))
+    }
+}
+
+impl Filter for IncludeRustFiles {
+    fn include_dir(&self, dir_path: &RelativePath) -> bool {
+        const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"];
+
+        let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str()));
+
+        let hidden = dir_path.components().any(|c| c.as_str().starts_with("."));
+
+        !is_ignored && !hidden
+    }
+
+    fn include_file(&self, file_path: &RelativePath) -> bool {
+        file_path.extension() == Some("rs")
+    }
+}
+
 impl BatchDatabase {
     pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase {
         let mut db =
@@ -100,6 +124,7 @@ impl BatchDatabase {
         let mut roots = Vec::new();
         roots.push(root.clone());
         roots.extend(ws.to_roots());
+        let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>();
         let (mut vfs, roots) = Vfs::new(roots);
         let mut load = |path: &Path| {
             let vfs_file = vfs.load(path);
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 2b3890e0194..d824107004c 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -19,7 +19,7 @@ lsp-types = "0.56.0"
 rustc-hash = "1.0"
 parking_lot = "0.7.0"
 
-ra_vfs = "0.1.0"
+ra_vfs = "0.2.0"
 thread_worker = { path = "../thread_worker" }
 ra_syntax = { path = "../ra_syntax" }
 ra_text_edit = { path = "../ra_text_edit" }
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs
index 7163568b9cd..cf7c17c5cff 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::{
     Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData,
     SourceRootId
 };
-use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot};
-use relative_path::RelativePathBuf;
+use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot, RootEntry, Filter};
+use relative_path::{RelativePath, RelativePathBuf};
 use parking_lot::RwLock;
 use failure::format_err;
 
@@ -33,6 +33,30 @@ pub struct ServerWorld {
     pub vfs: Arc<RwLock<Vfs>>,
 }
 
+struct IncludeRustFiles;
+
+impl IncludeRustFiles {
+    fn to_entry(path: PathBuf) -> RootEntry {
+        RootEntry::new(path, Box::new(Self {}))
+    }
+}
+
+impl Filter for IncludeRustFiles {
+    fn include_dir(&self, dir_path: &RelativePath) -> bool {
+        const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"];
+
+        let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str()));
+
+        let hidden = dir_path.components().any(|c| c.as_str().starts_with("."));
+
+        !is_ignored && !hidden
+    }
+
+    fn include_file(&self, file_path: &RelativePath) -> bool {
+        file_path.extension() == Some("rs")
+    }
+}
+
 impl ServerWorldState {
     pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState {
         let mut change = AnalysisChange::new();
@@ -42,6 +66,8 @@ impl ServerWorldState {
         for ws in workspaces.iter() {
             roots.extend(ws.to_roots());
         }
+        let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>();
+
         let (mut vfs, roots) = Vfs::new(roots);
         let roots_to_scan = roots.len();
         for r in roots {