From e69b620f0d1e90afcc14dc7cf07ed0b828d8ec96 Mon Sep 17 00:00:00 2001 From: Bernardo Date: Wed, 16 Jan 2019 19:30:20 +0100 Subject: add missing Task::HandleChange --- crates/ra_vfs/src/io.rs | 11 ++++++++--- crates/ra_vfs/src/lib.rs | 1 + crates/ra_vfs/src/watcher.rs | 14 +++++++------- crates/ra_vfs/tests/vfs.rs | 23 ++++++++++++----------- 4 files changed, 28 insertions(+), 21 deletions(-) (limited to 'crates') diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs index a0c87fb25..e5d5c6463 100644 --- a/crates/ra_vfs/src/io.rs +++ b/crates/ra_vfs/src/io.rs @@ -15,7 +15,8 @@ pub(crate) enum Task { path: PathBuf, filter: Box bool + Send>, }, - LoadChange(crate::watcher::WatcherChange), + HandleChange(WatcherChange), + LoadChange(WatcherChange), } #[derive(Debug)] @@ -63,6 +64,10 @@ fn handle_task(task: Task) -> TaskResult { log::debug!("... loaded {}", path.as_path().display()); TaskResult::AddRoot(AddRootResult { root, files }) } + Task::HandleChange(change) => { + // forward as is because Vfs has to decide if we should load it + TaskResult::HandleChange(change) + } Task::LoadChange(change) => { log::debug!("loading {:?} ...", change); let data = load_change(change); @@ -107,7 +112,7 @@ fn load_change(change: WatcherChange) -> Option { let text = match fs::read_to_string(&path) { Ok(text) => text, Err(e) => { - log::warn!("watcher error: {}", e); + log::warn!("watcher error \"{}\": {}", path.display(), e); return None; } }; @@ -117,7 +122,7 @@ fn load_change(change: WatcherChange) -> Option { let text = match fs::read_to_string(&path) { Ok(text) => text, Err(e) => { - log::warn!("watcher error: {}", e); + log::warn!("watcher error \"{}\": {}", path.display(), e); return None; } }; diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index f698e3e86..48a46d210 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs @@ -266,6 +266,7 @@ impl Vfs { if let Some(file) = file { if self.files[file].is_overlayed { // file is overlayed + log::debug!("skipping overlayed \"{}\"", path.display()); return false; } } diff --git a/crates/ra_vfs/src/watcher.rs b/crates/ra_vfs/src/watcher.rs index 3bd0e7da2..dfbbcbfe6 100644 --- a/crates/ra_vfs/src/watcher.rs +++ b/crates/ra_vfs/src/watcher.rs @@ -35,24 +35,24 @@ fn send_change_events( // ignore } DebouncedEvent::Rescan => { - sender.send(io::Task::LoadChange(WatcherChange::Rescan))?; + sender.send(io::Task::HandleChange(WatcherChange::Rescan))?; } DebouncedEvent::Create(path) => { - sender.send(io::Task::LoadChange(WatcherChange::Create(path)))?; + sender.send(io::Task::HandleChange(WatcherChange::Create(path)))?; } DebouncedEvent::Write(path) => { - sender.send(io::Task::LoadChange(WatcherChange::Write(path)))?; + sender.send(io::Task::HandleChange(WatcherChange::Write(path)))?; } DebouncedEvent::Remove(path) => { - sender.send(io::Task::LoadChange(WatcherChange::Remove(path)))?; + sender.send(io::Task::HandleChange(WatcherChange::Remove(path)))?; } DebouncedEvent::Rename(src, dst) => { - sender.send(io::Task::LoadChange(WatcherChange::Remove(src)))?; - sender.send(io::Task::LoadChange(WatcherChange::Create(dst)))?; + sender.send(io::Task::HandleChange(WatcherChange::Remove(src)))?; + sender.send(io::Task::HandleChange(WatcherChange::Create(dst)))?; } DebouncedEvent::Error(err, path) => { // TODO should we reload the file contents? - log::warn!("watcher error {}, {:?}", err, path); + log::warn!("watcher error \"{}\", {:?}", err, path); } } Ok(()) diff --git a/crates/ra_vfs/tests/vfs.rs b/crates/ra_vfs/tests/vfs.rs index 87fb5a092..8266a0bd5 100644 --- a/crates/ra_vfs/tests/vfs.rs +++ b/crates/ra_vfs/tests/vfs.rs @@ -62,23 +62,24 @@ fn test_vfs_works() -> std::io::Result<()> { } fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap(); - process_tasks(&mut vfs, 1); + // 2 tasks per watcher change, first for HandleChange then for LoadChange + process_tasks(&mut vfs, 2); match vfs.commit_changes().as_slice() { [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"), - _ => panic!("unexpected changes"), + xs => panic!("unexpected changes {:?}", xs), } vfs.change_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string()); match vfs.commit_changes().as_slice() { [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "m"), - _ => panic!("unexpected changes"), + xs => panic!("unexpected changes {:?}", xs), } // removing overlay restores data on disk vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs")); match vfs.commit_changes().as_slice() { [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"), - _ => panic!("unexpected changes"), + xs => panic!("unexpected changes {:?}", xs), } vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string()); @@ -87,27 +88,27 @@ fn test_vfs_works() -> std::io::Result<()> { assert_eq!(text.as_str(), "spam"); assert_eq!(path, "spam.rs"); } - _ => panic!("unexpected changes"), + xs => panic!("unexpected changes {:?}", xs), } vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs")); match vfs.commit_changes().as_slice() { [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "spam.rs"), - _ => panic!("unexpected changes"), + xs => panic!("unexpected changes {:?}", xs), } fs::write(&dir.path().join("a/new.rs"), "new hello").unwrap(); - process_tasks(&mut vfs, 1); + process_tasks(&mut vfs, 2); match vfs.commit_changes().as_slice() { [VfsChange::AddFile { text, path, .. }] => { assert_eq!(text.as_str(), "new hello"); assert_eq!(path, "new.rs"); } - _ => panic!("unexpected changes"), + xs => panic!("unexpected changes {:?}", xs), } fs::rename(&dir.path().join("a/new.rs"), &dir.path().join("a/new1.rs")).unwrap(); - process_tasks(&mut vfs, 2); + process_tasks(&mut vfs, 4); match vfs.commit_changes().as_slice() { [VfsChange::RemoveFile { path: removed_path, .. @@ -124,10 +125,10 @@ fn test_vfs_works() -> std::io::Result<()> { } fs::remove_file(&dir.path().join("a/new1.rs")).unwrap(); - process_tasks(&mut vfs, 1); + process_tasks(&mut vfs, 2); match vfs.commit_changes().as_slice() { [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "new1.rs"), - _ => panic!("unexpected changes"), + xs => panic!("unexpected changes {:?}", xs), } match vfs.task_receiver().try_recv() { -- cgit v1.2.3