aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_vfs/src/io.rs7
-rw-r--r--crates/ra_vfs/src/io/watcher.rs22
-rw-r--r--crates/ra_vfs/tests/vfs.rs23
3 files changed, 30 insertions, 22 deletions
diff --git a/crates/ra_vfs/src/io.rs b/crates/ra_vfs/src/io.rs
index 3ab52ac3d..335f4f2e1 100644
--- a/crates/ra_vfs/src/io.rs
+++ b/crates/ra_vfs/src/io.rs
@@ -55,7 +55,12 @@ pub enum TaskResult {
55 55
56impl fmt::Debug for TaskResult { 56impl fmt::Debug for TaskResult {
57 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 57 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58 f.write_str("TaskResult { ... }") 58 match self {
59 TaskResult::AddRoot(..) => f.write_str("TaskResult::AddRoot(..)"),
60 TaskResult::HandleChange(c) => write!(f, "TaskResult::HandleChange({:?})", c),
61 TaskResult::LoadChange(c) => write!(f, "TaskResult::LoadChange({:?})", c),
62 TaskResult::NoOp => f.write_str("TaskResult::NoOp"),
63 }
59 } 64 }
60} 65}
61 66
diff --git a/crates/ra_vfs/src/io/watcher.rs b/crates/ra_vfs/src/io/watcher.rs
index b370c5fbc..68bb6b692 100644
--- a/crates/ra_vfs/src/io/watcher.rs
+++ b/crates/ra_vfs/src/io/watcher.rs
@@ -100,16 +100,18 @@ impl Watcher {
100 log::warn!("could not watch \"{}\": {}", entry.path().display(), e) 100 log::warn!("could not watch \"{}\": {}", entry.path().display(), e)
101 } 101 }
102 } 102 }
103 } 103 } else {
104 if emit_for_contents && entry.depth() > 0 { 104 if emit_for_contents && entry.depth() > 0 {
105 // emit as create because we haven't seen it yet 105 // emit only for files otherwise we will cause watch_recursive to be called again with a dir that we are already watching
106 if let Err(e) = 106 // emit as create because we haven't seen it yet
107 self.sender 107 if let Err(e) =
108 .send(io::Task::HandleChange(WatcherChange::Create( 108 self.sender
109 entry.path().to_path_buf(), 109 .send(io::Task::HandleChange(WatcherChange::Create(
110 ))) 110 entry.path().to_path_buf(),
111 { 111 )))
112 log::warn!("watcher error: {}", e) 112 {
113 log::warn!("watcher error: {}", e)
114 }
113 } 115 }
114 } 116 }
115 } 117 }
diff --git a/crates/ra_vfs/tests/vfs.rs b/crates/ra_vfs/tests/vfs.rs
index b18ea74a3..d3271570a 100644
--- a/crates/ra_vfs/tests/vfs.rs
+++ b/crates/ra_vfs/tests/vfs.rs
@@ -1,12 +1,13 @@
1use std::{collections::HashSet, fs}; 1use std::{collections::HashSet, fs};
2 2
3// use flexi_logger::Logger; 3use flexi_logger::Logger;
4use ra_vfs::{Vfs, VfsChange}; 4use ra_vfs::{Vfs, VfsChange};
5use tempfile::tempdir; 5use tempfile::tempdir;
6 6
7fn process_tasks(vfs: &mut Vfs, num_tasks: u32) { 7fn process_tasks(vfs: &mut Vfs, num_tasks: u32) {
8 for _ in 0..num_tasks { 8 for _ in 0..num_tasks {
9 let task = vfs.task_receiver().recv().unwrap(); 9 let task = vfs.task_receiver().recv().unwrap();
10 log::debug!("{:?}", task);
10 vfs.handle_task(task); 11 vfs.handle_task(task);
11 } 12 }
12} 13}
@@ -25,7 +26,7 @@ macro_rules! assert_match {
25 26
26#[test] 27#[test]
27fn test_vfs_works() -> std::io::Result<()> { 28fn test_vfs_works() -> std::io::Result<()> {
28 // Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap(); 29 Logger::with_str("vfs=debug,ra_vfs=debug").start().unwrap();
29 30
30 let files = [ 31 let files = [
31 ("a/foo.rs", "hello"), 32 ("a/foo.rs", "hello"),
@@ -114,21 +115,21 @@ fn test_vfs_works() -> std::io::Result<()> {
114 assert_eq!(path, "spam.rs") 115 assert_eq!(path, "spam.rs")
115 ); 116 );
116 117
117 fs::create_dir_all(dir.path().join("a/c")).unwrap(); 118 fs::create_dir_all(dir.path().join("a/sub1/sub2")).unwrap();
118 fs::write(dir.path().join("a/c/new.rs"), "new hello").unwrap(); 119 fs::write(dir.path().join("a/sub1/sub2/new.rs"), "new hello").unwrap();
119 process_tasks(&mut vfs, 4); 120 process_tasks(&mut vfs, 4);
120 assert_match!( 121 assert_match!(
121 vfs.commit_changes().as_slice(), 122 vfs.commit_changes().as_slice(),
122 [VfsChange::AddFile { text, path, .. }], 123 [VfsChange::AddFile { text, path, .. }],
123 { 124 {
124 assert_eq!(text.as_str(), "new hello"); 125 assert_eq!(text.as_str(), "new hello");
125 assert_eq!(path, "c/new.rs"); 126 assert_eq!(path, "sub1/sub2/new.rs");
126 } 127 }
127 ); 128 );
128 129
129 fs::rename( 130 fs::rename(
130 &dir.path().join("a/c/new.rs"), 131 &dir.path().join("a/sub1/sub2/new.rs"),
131 &dir.path().join("a/c/new1.rs"), 132 &dir.path().join("a/sub1/sub2/new1.rs"),
132 ) 133 )
133 .unwrap(); 134 .unwrap();
134 process_tasks(&mut vfs, 4); 135 process_tasks(&mut vfs, 4);
@@ -142,18 +143,18 @@ fn test_vfs_works() -> std::io::Result<()> {
142 .. 143 ..
143 }], 144 }],
144 { 145 {
145 assert_eq!(removed_path, "c/new.rs"); 146 assert_eq!(removed_path, "sub1/sub2/new.rs");
146 assert_eq!(added_path, "c/new1.rs"); 147 assert_eq!(added_path, "sub1/sub2/new1.rs");
147 assert_eq!(text.as_str(), "new hello"); 148 assert_eq!(text.as_str(), "new hello");
148 } 149 }
149 ); 150 );
150 151
151 fs::remove_file(&dir.path().join("a/c/new1.rs")).unwrap(); 152 fs::remove_file(&dir.path().join("a/sub1/sub2/new1.rs")).unwrap();
152 process_tasks(&mut vfs, 2); 153 process_tasks(&mut vfs, 2);
153 assert_match!( 154 assert_match!(
154 vfs.commit_changes().as_slice(), 155 vfs.commit_changes().as_slice(),
155 [VfsChange::RemoveFile { path, .. }], 156 [VfsChange::RemoveFile { path, .. }],
156 assert_eq!(path, "c/new1.rs") 157 assert_eq!(path, "sub1/sub2/new1.rs")
157 ); 158 );
158 159
159 fs::create_dir_all(dir.path().join("a/target")).unwrap(); 160 fs::create_dir_all(dir.path().join("a/target")).unwrap();