From 83934679b94907213909063c8300bf896f387e30 Mon Sep 17 00:00:00 2001 From: Damien Radtke Date: Fri, 5 Jun 2020 16:20:41 +0000 Subject: [PATCH] Fix recursive notify This commit attempts to fix filesystem notifications for recursive paths that also specify an extension, such as "**/*.java". --- src/language_server_protocol.rs | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/language_server_protocol.rs b/src/language_server_protocol.rs index 24732189c..dacc0ae11 100644 --- a/src/language_server_protocol.rs +++ b/src/language_server_protocol.rs @@ -12,6 +12,7 @@ use crate::{ viewport, }; use anyhow::{anyhow, Context, Error, Result}; +use glob::glob; use itertools::Itertools; use jsonrpc_core::Value; use log::{debug, error, info, warn}; @@ -2724,13 +2725,27 @@ impl LanguageClient { self.update(|state| { if let Some(ref mut watcher) = state.watchers.get_mut(language_id) { for w in &opt.watchers { - let recursive_mode = if w.glob_pattern.ends_with("**") { - notify::RecursiveMode::Recursive - } else { - notify::RecursiveMode::NonRecursive - }; - watcher - .watch(w.glob_pattern.trim_end_matches("**"), recursive_mode)?; + info!("Watching glob pattern: {}", &w.glob_pattern); + for entry in glob(&w.glob_pattern)? { + match entry { + Ok(path) => { + let mode = if path.is_dir() { + notify::RecursiveMode::Recursive + } else { + notify::RecursiveMode::NonRecursive + }; + debug!( + "Watching path {} with mode {:?}", + path.display(), + mode + ); + watcher.watch(path, mode)?; + } + Err(e) => { + warn!("Error globbing for {}: {}", w.glob_pattern, e) + } + } + } } } Ok(())