aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernardo <[email protected]>2019-01-16 18:30:20 +0000
committerAleksey Kladov <[email protected]>2019-01-26 08:46:27 +0000
commite69b620f0d1e90afcc14dc7cf07ed0b828d8ec96 (patch)
tree89a499f4cd50e1d1ebadbf8c7a9f0a5e777cbc7b
parentabd8ccefa4fd1abbf674f479f0dd7d0457c94d2d (diff)
add missing Task::HandleChange
-rw-r--r--crates/ra_vfs/src/io.rs11
-rw-r--r--crates/ra_vfs/src/lib.rs1
-rw-r--r--crates/ra_vfs/src/watcher.rs14
-rw-r--r--crates/ra_vfs/tests/vfs.rs23
4 files changed, 28 insertions, 21 deletions
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 {
15 path: PathBuf, 15 path: PathBuf,
16 filter: Box<Fn(&DirEntry) -> bool + Send>, 16 filter: Box<Fn(&DirEntry) -> bool + Send>,
17 }, 17 },
18 LoadChange(crate::watcher::WatcherChange), 18 HandleChange(WatcherChange),
19 LoadChange(WatcherChange),
19} 20}
20 21
21#[derive(Debug)] 22#[derive(Debug)]
@@ -63,6 +64,10 @@ fn handle_task(task: Task) -> TaskResult {
63 log::debug!("... loaded {}", path.as_path().display()); 64 log::debug!("... loaded {}", path.as_path().display());
64 TaskResult::AddRoot(AddRootResult { root, files }) 65 TaskResult::AddRoot(AddRootResult { root, files })
65 } 66 }
67 Task::HandleChange(change) => {
68 // forward as is because Vfs has to decide if we should load it
69 TaskResult::HandleChange(change)
70 }
66 Task::LoadChange(change) => { 71 Task::LoadChange(change) => {
67 log::debug!("loading {:?} ...", change); 72 log::debug!("loading {:?} ...", change);
68 let data = load_change(change); 73 let data = load_change(change);
@@ -107,7 +112,7 @@ fn load_change(change: WatcherChange) -> Option<WatcherChangeData> {
107 let text = match fs::read_to_string(&path) { 112 let text = match fs::read_to_string(&path) {
108 Ok(text) => text, 113 Ok(text) => text,
109 Err(e) => { 114 Err(e) => {
110 log::warn!("watcher error: {}", e); 115 log::warn!("watcher error \"{}\": {}", path.display(), e);
111 return None; 116 return None;
112 } 117 }
113 }; 118 };
@@ -117,7 +122,7 @@ fn load_change(change: WatcherChange) -> Option<WatcherChangeData> {
117 let text = match fs::read_to_string(&path) { 122 let text = match fs::read_to_string(&path) {
118 Ok(text) => text, 123 Ok(text) => text,
119 Err(e) => { 124 Err(e) => {
120 log::warn!("watcher error: {}", e); 125 log::warn!("watcher error \"{}\": {}", path.display(), e);
121 return None; 126 return None;
122 } 127 }
123 }; 128 };
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 {
266 if let Some(file) = file { 266 if let Some(file) = file {
267 if self.files[file].is_overlayed { 267 if self.files[file].is_overlayed {
268 // file is overlayed 268 // file is overlayed
269 log::debug!("skipping overlayed \"{}\"", path.display());
269 return false; 270 return false;
270 } 271 }
271 } 272 }
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(
35 // ignore 35 // ignore
36 } 36 }
37 DebouncedEvent::Rescan => { 37 DebouncedEvent::Rescan => {
38 sender.send(io::Task::LoadChange(WatcherChange::Rescan))?; 38 sender.send(io::Task::HandleChange(WatcherChange::Rescan))?;
39 } 39 }
40 DebouncedEvent::Create(path) => { 40 DebouncedEvent::Create(path) => {
41 sender.send(io::Task::LoadChange(WatcherChange::Create(path)))?; 41 sender.send(io::Task::HandleChange(WatcherChange::Create(path)))?;
42 } 42 }
43 DebouncedEvent::Write(path) => { 43 DebouncedEvent::Write(path) => {
44 sender.send(io::Task::LoadChange(WatcherChange::Write(path)))?; 44 sender.send(io::Task::HandleChange(WatcherChange::Write(path)))?;
45 } 45 }
46 DebouncedEvent::Remove(path) => { 46 DebouncedEvent::Remove(path) => {
47 sender.send(io::Task::LoadChange(WatcherChange::Remove(path)))?; 47 sender.send(io::Task::HandleChange(WatcherChange::Remove(path)))?;
48 } 48 }
49 DebouncedEvent::Rename(src, dst) => { 49 DebouncedEvent::Rename(src, dst) => {
50 sender.send(io::Task::LoadChange(WatcherChange::Remove(src)))?; 50 sender.send(io::Task::HandleChange(WatcherChange::Remove(src)))?;
51 sender.send(io::Task::LoadChange(WatcherChange::Create(dst)))?; 51 sender.send(io::Task::HandleChange(WatcherChange::Create(dst)))?;
52 } 52 }
53 DebouncedEvent::Error(err, path) => { 53 DebouncedEvent::Error(err, path) => {
54 // TODO should we reload the file contents? 54 // TODO should we reload the file contents?
55 log::warn!("watcher error {}, {:?}", err, path); 55 log::warn!("watcher error \"{}\", {:?}", err, path);
56 } 56 }
57 } 57 }
58 Ok(()) 58 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<()> {
62 } 62 }
63 63
64 fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap(); 64 fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap();
65 process_tasks(&mut vfs, 1); 65 // 2 tasks per watcher change, first for HandleChange then for LoadChange
66 process_tasks(&mut vfs, 2);
66 match vfs.commit_changes().as_slice() { 67 match vfs.commit_changes().as_slice() {
67 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"), 68 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"),
68 _ => panic!("unexpected changes"), 69 xs => panic!("unexpected changes {:?}", xs),
69 } 70 }
70 71
71 vfs.change_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string()); 72 vfs.change_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string());
72 match vfs.commit_changes().as_slice() { 73 match vfs.commit_changes().as_slice() {
73 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "m"), 74 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "m"),
74 _ => panic!("unexpected changes"), 75 xs => panic!("unexpected changes {:?}", xs),
75 } 76 }
76 77
77 // removing overlay restores data on disk 78 // removing overlay restores data on disk
78 vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs")); 79 vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs"));
79 match vfs.commit_changes().as_slice() { 80 match vfs.commit_changes().as_slice() {
80 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"), 81 [VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"),
81 _ => panic!("unexpected changes"), 82 xs => panic!("unexpected changes {:?}", xs),
82 } 83 }
83 84
84 vfs.add_file_overlay(&dir.path().join("a/b/spam.rs"), "spam".to_string()); 85 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<()> {
87 assert_eq!(text.as_str(), "spam"); 88 assert_eq!(text.as_str(), "spam");
88 assert_eq!(path, "spam.rs"); 89 assert_eq!(path, "spam.rs");
89 } 90 }
90 _ => panic!("unexpected changes"), 91 xs => panic!("unexpected changes {:?}", xs),
91 } 92 }
92 93
93 vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs")); 94 vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs"));
94 match vfs.commit_changes().as_slice() { 95 match vfs.commit_changes().as_slice() {
95 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "spam.rs"), 96 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "spam.rs"),
96 _ => panic!("unexpected changes"), 97 xs => panic!("unexpected changes {:?}", xs),
97 } 98 }
98 99
99 fs::write(&dir.path().join("a/new.rs"), "new hello").unwrap(); 100 fs::write(&dir.path().join("a/new.rs"), "new hello").unwrap();
100 process_tasks(&mut vfs, 1); 101 process_tasks(&mut vfs, 2);
101 match vfs.commit_changes().as_slice() { 102 match vfs.commit_changes().as_slice() {
102 [VfsChange::AddFile { text, path, .. }] => { 103 [VfsChange::AddFile { text, path, .. }] => {
103 assert_eq!(text.as_str(), "new hello"); 104 assert_eq!(text.as_str(), "new hello");
104 assert_eq!(path, "new.rs"); 105 assert_eq!(path, "new.rs");
105 } 106 }
106 _ => panic!("unexpected changes"), 107 xs => panic!("unexpected changes {:?}", xs),
107 } 108 }
108 109
109 fs::rename(&dir.path().join("a/new.rs"), &dir.path().join("a/new1.rs")).unwrap(); 110 fs::rename(&dir.path().join("a/new.rs"), &dir.path().join("a/new1.rs")).unwrap();
110 process_tasks(&mut vfs, 2); 111 process_tasks(&mut vfs, 4);
111 match vfs.commit_changes().as_slice() { 112 match vfs.commit_changes().as_slice() {
112 [VfsChange::RemoveFile { 113 [VfsChange::RemoveFile {
113 path: removed_path, .. 114 path: removed_path, ..
@@ -124,10 +125,10 @@ fn test_vfs_works() -> std::io::Result<()> {
124 } 125 }
125 126
126 fs::remove_file(&dir.path().join("a/new1.rs")).unwrap(); 127 fs::remove_file(&dir.path().join("a/new1.rs")).unwrap();
127 process_tasks(&mut vfs, 1); 128 process_tasks(&mut vfs, 2);
128 match vfs.commit_changes().as_slice() { 129 match vfs.commit_changes().as_slice() {
129 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "new1.rs"), 130 [VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "new1.rs"),
130 _ => panic!("unexpected changes"), 131 xs => panic!("unexpected changes {:?}", xs),
131 } 132 }
132 133
133 match vfs.task_receiver().try_recv() { 134 match vfs.task_receiver().try_recv() {