mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
introduce ra_vfs_glob crate
It manages exclusion rules for the vfs crate
This commit is contained in:
parent
c971869104
commit
34203256bf
12 changed files with 173 additions and 143 deletions
|
@ -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;
|
||||
|
|
|
@ -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<R>(roots: R) -> impl Iterator<Item = RootEntry>
|
||||
where
|
||||
R: IntoIterator<Item = PackageRoot>,
|
||||
{
|
||||
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<PackageRoot> for IncludeRustFiles {
|
||||
fn from(v: PackageRoot) -> IncludeRustFiles {
|
||||
IncludeRustFiles { root: v }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<IncludeRustFiles> for RootEntry {
|
||||
fn from(v: IncludeRustFiles) -> RootEntry {
|
||||
let path = v.root.path().clone();
|
||||
RootEntry::new(path, Box::new(v))
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue