From e32462c6d56592acd22f1aab64f627636a476d6c Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Tue, 19 Mar 2019 15:14:16 +0200 Subject: Improve filtering of file roots `ProjectWorkspace::to_roots` now returns a new `ProjectRoot` which contains information regarding whether or not the given path is part of the current workspace or an external dependency. This information can then be used in `ra_batch` and `ra_lsp_server` to implement more advanced filtering. This allows us to filter some unnecessary folders from external dependencies such as tests, examples and benches. --- crates/ra_lsp_server/src/server_world.rs | 34 +++++--------------------------- 1 file changed, 5 insertions(+), 29 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 cf7c17c5c..af4798494 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs @@ -8,13 +8,14 @@ use ra_ide_api::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId }; -use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot, RootEntry, Filter}; -use relative_path::{RelativePath, RelativePathBuf}; +use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; +use relative_path::RelativePathBuf; use parking_lot::RwLock; use failure::format_err; use crate::{ project_model::ProjectWorkspace, + vfs_filter::IncludeRustFiles, Result, }; @@ -33,40 +34,15 @@ 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(); let mut roots = Vec::new(); - roots.push(root.clone()); + roots.push(IncludeRustFiles::member(root.clone())); for ws in workspaces.iter() { - roots.extend(ws.to_roots()); + roots.extend(IncludeRustFiles::from_roots(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(); -- cgit v1.2.3