summaryrefslogtreecommitdiff
path: root/support/texlab/src/workspace/watch.rs
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-02-27 03:01:13 +0000
committerNorbert Preining <norbert@preining.info>2022-02-27 03:01:13 +0000
commita911d39178540078c8ff5bc880418478d7433c40 (patch)
treef23b6a0f6bf9f548e7e43cf2405e864eba99b21e /support/texlab/src/workspace/watch.rs
parent740a11f29a3551babe3d7edbb57ac3baa2280a3f (diff)
CTAN sync 202202270301
Diffstat (limited to 'support/texlab/src/workspace/watch.rs')
-rw-r--r--support/texlab/src/workspace/watch.rs31
1 files changed, 16 insertions, 15 deletions
diff --git a/support/texlab/src/workspace/watch.rs b/support/texlab/src/workspace/watch.rs
index 655872f603..4cc1834620 100644
--- a/support/texlab/src/workspace/watch.rs
+++ b/support/texlab/src/workspace/watch.rs
@@ -32,7 +32,7 @@ where
}
fn create_watcher(workspace: Arc<W>) -> Result<RecommendedWatcher> {
- let watcher = Watcher::new_immediate(move |event: notify::Result<notify::Event>| {
+ let watcher = notify::recommended_watcher(move |event: notify::Result<notify::Event>| {
if let Ok(event) = event {
if event.kind.is_modify() {
for path in event.paths {
@@ -57,20 +57,11 @@ impl<W: Workspace> Workspace for DocumentWatcher<W> {
if document.uri.scheme() == "file" {
if let Ok(mut path) = document.uri.to_file_path() {
path.pop();
- let mut watched_paths = self.watched_paths.lock().unwrap();
- if !watched_paths.contains(&path) {
- if let Err(why) = self
- .watcher
- .lock()
- .unwrap()
- .watch(&path, RecursiveMode::NonRecursive)
- {
- warn!(
- "Failed to watch folder of document \"{}\": {}",
- document.uri, why
- );
- }
- watched_paths.insert(path);
+ if let Err(why) = self.watch(path, RecursiveMode::NonRecursive) {
+ warn!(
+ "Failed to watch folder of document \"{}\": {}",
+ document.uri, why
+ );
}
}
}
@@ -104,4 +95,14 @@ impl<W: Workspace> Workspace for DocumentWatcher<W> {
fn subset(&self, uri: Arc<Uri>) -> Option<WorkspaceSubset> {
self.workspace.subset(uri)
}
+
+ fn watch(&self, path: PathBuf, mode: RecursiveMode) -> Result<()> {
+ let mut watched_paths = self.watched_paths.lock().unwrap();
+ if !watched_paths.contains(&path) {
+ self.watcher.lock().unwrap().watch(&path, mode)?;
+ watched_paths.insert(path);
+ }
+
+ Ok(())
+ }
}