Skip to content

Commit bf3ba48

Browse files
committed
Match watch_patterns with project-relative paths
1 parent 21cdf26 commit bf3ba48

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/app.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,19 +375,27 @@ fn create_watcher(
375375
) -> notify::Result<notify::RecommendedWatcher> {
376376
let mut config_patterns = GlobSetBuilder::new();
377377
for filename in CONFIG_FILENAMES {
378-
config_patterns.add(Glob::new(&format!("**/{filename}")).unwrap());
378+
config_patterns.add(Glob::new(filename).unwrap());
379379
}
380380
let config_patterns = config_patterns.build().unwrap();
381381

382+
let base_dir = project_dir.to_owned();
382383
let mut watcher =
383384
notify::recommended_watcher(move |res: notify::Result<notify::Event>| match res {
384385
Ok(event) => {
385-
if matches!(event.kind, notify::EventKind::Modify(..)) {
386+
if matches!(
387+
event.kind,
388+
notify::EventKind::Modify(..)
389+
| notify::EventKind::Create(..)
390+
| notify::EventKind::Remove(..)
391+
) {
386392
for path in &event.paths {
393+
let Ok(path) = path.strip_prefix(&base_dir) else {
394+
continue;
395+
};
387396
if config_patterns.is_match(path) {
388397
config_modified.store(true, Ordering::Relaxed);
389-
}
390-
if patterns.is_match(path) {
398+
} else if patterns.is_match(path) {
391399
modified.store(true, Ordering::Relaxed);
392400
}
393401
}

0 commit comments

Comments
 (0)