From e70e2361b602f7837e8fbed36ae1c51cd8e2f3b5 Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Mon, 18 Mar 2019 19:23:54 +0200 Subject: Upgrade ra_vfs to use new Filtering Currently this matches the previous filtering, meaning all roots are filtered using the same rules. --- crates/ra_batch/Cargo.toml | 2 +- crates/ra_batch/src/lib.rs | 29 +++++++++++++++++++++++++++-- crates/ra_lsp_server/Cargo.toml | 2 +- crates/ra_lsp_server/src/server_world.rs | 30 ++++++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 6 deletions(-) (limited to 'crates') 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" 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 c6d10107d..a054d0da3 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 = std::result::Result; @@ -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::>(); 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 2b3890e01..d82410700 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 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::{ 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>, } +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) -> 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::>(); + let (mut vfs, roots) = Vfs::new(roots); let roots_to_scan = roots.len(); for r in roots { -- cgit v1.2.3