From 34203256bf8f8ea12b233e0fb49b42bd8c423281 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Aug 2019 13:00:37 +0200 Subject: introduce ra_vfs_glob crate It manages exclusion rules for the vfs crate --- crates/ra_lsp_server/src/lib.rs | 1 - crates/ra_lsp_server/src/vfs_filter.rs | 54 ---------------------------------- crates/ra_lsp_server/src/world.rs | 20 ++++++++++--- 3 files changed, 16 insertions(+), 59 deletions(-) delete mode 100644 crates/ra_lsp_server/src/vfs_filter.rs (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 56a263aa5..2ae6300c8 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs @@ -4,7 +4,6 @@ mod conv; mod main_loop; mod markdown; mod project_model; -mod vfs_filter; pub mod req; pub mod init; mod world; diff --git a/crates/ra_lsp_server/src/vfs_filter.rs b/crates/ra_lsp_server/src/vfs_filter.rs deleted file mode 100644 index abdc8dbad..000000000 --- a/crates/ra_lsp_server/src/vfs_filter.rs +++ /dev/null @@ -1,54 +0,0 @@ -use ra_project_model::PackageRoot; -use ra_vfs::{Filter, RelativePath, RootEntry}; -use std::path::PathBuf; - -/// `IncludeRustFiles` is used to convert -/// from `PackageRoot` to `RootEntry` for VFS -pub struct IncludeRustFiles { - root: PackageRoot, -} - -impl IncludeRustFiles { - pub fn from_roots(roots: R) -> impl Iterator - where - R: IntoIterator, - { - roots.into_iter().map(IncludeRustFiles::from_root) - } - - pub fn from_root(root: PackageRoot) -> RootEntry { - IncludeRustFiles::from(root).into() - } - - #[allow(unused)] - pub fn external(path: PathBuf) -> RootEntry { - IncludeRustFiles::from_root(PackageRoot::new(path, false)) - } - - pub fn member(path: PathBuf) -> RootEntry { - IncludeRustFiles::from_root(PackageRoot::new(path, true)) - } -} - -impl Filter for IncludeRustFiles { - fn include_dir(&self, dir_path: &RelativePath) -> bool { - self.root.include_dir(dir_path) - } - - fn include_file(&self, file_path: &RelativePath) -> bool { - self.root.include_file(file_path) - } -} - -impl std::convert::From for IncludeRustFiles { - fn from(v: PackageRoot) -> IncludeRustFiles { - IncludeRustFiles { root: v } - } -} - -impl std::convert::From for RootEntry { - fn from(v: IncludeRustFiles) -> RootEntry { - let path = v.root.path().clone(); - RootEntry::new(path, Box::new(v)) - } -} diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs index b57cdf925..a8aafe5cb 100644 --- a/crates/ra_lsp_server/src/world.rs +++ b/crates/ra_lsp_server/src/world.rs @@ -9,13 +9,13 @@ use parking_lot::RwLock; use ra_ide_api::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, SourceRootId, }; -use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; +use ra_vfs::{RootEntry, Vfs, VfsChange, VfsFile, VfsRoot}; +use ra_vfs_glob::RustPackageFilterBuilder; use relative_path::RelativePathBuf; use crate::{ main_loop::pending_requests::{CompletedRequest, LatestRequests}, project_model::ProjectWorkspace, - vfs_filter::IncludeRustFiles, LspError, Result, }; @@ -61,9 +61,21 @@ impl WorldState { let mut change = AnalysisChange::new(); let mut roots = Vec::new(); - roots.extend(folder_roots.iter().cloned().map(IncludeRustFiles::member)); + roots.extend(folder_roots.iter().map(|path| { + RootEntry::new( + path.clone(), + RustPackageFilterBuilder::default().set_member(true).into_vfs_filter(), + ) + })); for ws in workspaces.iter() { - roots.extend(IncludeRustFiles::from_roots(ws.to_roots())); + roots.extend(ws.to_roots().into_iter().map(|pkg_root| { + RootEntry::new( + pkg_root.path().clone(), + RustPackageFilterBuilder::default() + .set_member(pkg_root.is_member()) + .into_vfs_filter(), + ) + })); } let (mut vfs, vfs_roots) = Vfs::new(roots); -- cgit v1.2.3