Fix the regex matcher

This commit is contained in:
Kirill Bulatov 2023-12-04 23:00:01 +02:00
parent f0ca7141b8
commit 2c2c14a360
4 changed files with 41 additions and 17 deletions

View file

@ -371,15 +371,29 @@ impl SearchQuery {
pub fn file_matches(&self, file_path: Option<&Path>) -> bool {
match file_path {
Some(file_path) => {
!self
.files_to_exclude()
.iter()
.any(|exclude_glob| exclude_glob.is_match(file_path))
&& (self.files_to_include().is_empty()
|| self
.files_to_include()
.iter()
.any(|include_glob| include_glob.is_match(file_path)))
let mut path = file_path.to_path_buf();
let mut matches = false;
loop {
matches = !self
.files_to_exclude()
.iter()
.any(|exclude_glob| exclude_glob.is_match(&path))
&& (self.files_to_include().is_empty()
|| self
.files_to_include()
.iter()
.any(|include_glob| include_glob.is_match(&path)));
if matches || !path.pop() {
break;
}
}
let path_str = file_path.to_string_lossy();
if path_str.contains("node_modules") && path_str.contains("prettier") {
dbg!(path_str, path, matches);
}
matches
}
None => self.files_to_include().is_empty(),
}