Skip to content

Commit a98835f

Browse files
authored
Fix recursive notify (#1047)
This commit attempts to fix filesystem notifications for recursive paths that also specify an extension, such as "**/*.java".
1 parent b47cc8f commit a98835f

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/language_server_protocol.rs

+22-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
viewport,
1313
};
1414
use anyhow::{anyhow, Context, Error, Result};
15+
use glob::glob;
1516
use itertools::Itertools;
1617
use jsonrpc_core::Value;
1718
use log::{debug, error, info, warn};
@@ -2769,13 +2770,27 @@ impl LanguageClient {
27692770
self.update(|state| {
27702771
if let Some(ref mut watcher) = state.watchers.get_mut(language_id) {
27712772
for w in &opt.watchers {
2772-
let recursive_mode = if w.glob_pattern.ends_with("**") {
2773-
notify::RecursiveMode::Recursive
2774-
} else {
2775-
notify::RecursiveMode::NonRecursive
2776-
};
2777-
watcher
2778-
.watch(w.glob_pattern.trim_end_matches("**"), recursive_mode)?;
2773+
info!("Watching glob pattern: {}", &w.glob_pattern);
2774+
for entry in glob(&w.glob_pattern)? {
2775+
match entry {
2776+
Ok(path) => {
2777+
let mode = if path.is_dir() {
2778+
notify::RecursiveMode::Recursive
2779+
} else {
2780+
notify::RecursiveMode::NonRecursive
2781+
};
2782+
debug!(
2783+
"Watching path {} with mode {:?}",
2784+
path.display(),
2785+
mode
2786+
);
2787+
watcher.watch(path, mode)?;
2788+
}
2789+
Err(e) => {
2790+
warn!("Error globbing for {}: {}", w.glob_pattern, e)
2791+
}
2792+
}
2793+
}
27792794
}
27802795
}
27812796
Ok(())

0 commit comments

Comments
 (0)