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
|
@ -1,5 +1,3 @@
|
|||
mod vfs_filter;
|
||||
|
||||
use std::{collections::HashSet, error::Error, path::Path};
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
|
@ -7,8 +5,8 @@ use rustc_hash::FxHashMap;
|
|||
use ra_db::{CrateGraph, FileId, SourceRootId};
|
||||
use ra_ide_api::{AnalysisChange, AnalysisHost};
|
||||
use ra_project_model::{PackageRoot, ProjectWorkspace};
|
||||
use ra_vfs::{Vfs, VfsChange};
|
||||
use vfs_filter::IncludeRustFiles;
|
||||
use ra_vfs::{RootEntry, Vfs, VfsChange};
|
||||
use ra_vfs_glob::RustPackageFilterBuilder;
|
||||
|
||||
type Result<T> = std::result::Result<T, Box<dyn Error + Send + Sync>>;
|
||||
|
||||
|
@ -23,7 +21,19 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId,
|
|||
let root = std::env::current_dir()?.join(root);
|
||||
let ws = ProjectWorkspace::discover(root.as_ref())?;
|
||||
let project_roots = ws.to_roots();
|
||||
let (mut vfs, roots) = Vfs::new(IncludeRustFiles::from_roots(project_roots.clone()).collect());
|
||||
let (mut vfs, roots) = Vfs::new(
|
||||
project_roots
|
||||
.iter()
|
||||
.map(|pkg_root| {
|
||||
RootEntry::new(
|
||||
pkg_root.path().clone(),
|
||||
RustPackageFilterBuilder::default()
|
||||
.set_member(pkg_root.is_member())
|
||||
.into_vfs_filter(),
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
let crate_graph = ws.to_crate_graph(&mut |path: &Path| {
|
||||
let vfs_file = vfs.load(path);
|
||||
log::debug!("vfs file {:?} -> {:?}", path, vfs_file);
|
||||
|
|
|
@ -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 From<PackageRoot> for IncludeRustFiles {
|
||||
fn from(v: PackageRoot) -> IncludeRustFiles {
|
||||
IncludeRustFiles { root: v }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IncludeRustFiles> for RootEntry {
|
||||
fn from(v: IncludeRustFiles) -> RootEntry {
|
||||
let path = v.root.path().clone();
|
||||
RootEntry::new(path, Box::new(v))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue