mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
New VFS
This commit is contained in:
parent
7aa66371ee
commit
dad1333b48
46 changed files with 1028 additions and 1001 deletions
43
crates/vfs-notify/src/include.rs
Normal file
43
crates/vfs-notify/src/include.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
//! See `Include`.
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
use paths::{RelPath, RelPathBuf};
|
||||
|
||||
/// `Include` is the opposite of .gitignore.
|
||||
///
|
||||
/// It describes the set of files inside some directory.
|
||||
///
|
||||
/// The current implementation is very limited, it allows white-listing file
|
||||
/// globs and black-listing directories.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Include {
|
||||
include_files: GlobSet,
|
||||
exclude_dirs: Vec<RelPathBuf>,
|
||||
}
|
||||
|
||||
impl Include {
|
||||
pub(crate) fn new(include: Vec<String>) -> Include {
|
||||
let mut include_files = GlobSetBuilder::new();
|
||||
let mut exclude_dirs = Vec::new();
|
||||
|
||||
for glob in include {
|
||||
if glob.starts_with("!/") {
|
||||
if let Ok(path) = RelPathBuf::try_from(&glob["!/".len()..]) {
|
||||
exclude_dirs.push(path)
|
||||
}
|
||||
} else {
|
||||
include_files.add(Glob::new(&glob).unwrap());
|
||||
}
|
||||
}
|
||||
let include_files = include_files.build().unwrap();
|
||||
Include { include_files, exclude_dirs }
|
||||
}
|
||||
pub(crate) fn include_file(&self, path: &RelPath) -> bool {
|
||||
self.include_files.is_match(path)
|
||||
}
|
||||
pub(crate) fn exclude_dir(&self, path: &RelPath) -> bool {
|
||||
self.exclude_dirs.iter().any(|excluded| path.starts_with(excluded))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue