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_lsp_server/src/server_world.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'crates/ra_lsp_server/src/server_world.rs') 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