mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
add missing Task::HandleChange
This commit is contained in:
parent
abd8ccefa4
commit
e69b620f0d
4 changed files with 28 additions and 21 deletions
|
@ -15,7 +15,8 @@ pub(crate) enum Task {
|
|||
path: PathBuf,
|
||||
filter: Box<Fn(&DirEntry) -> 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<WatcherChangeData> {
|
|||
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<WatcherChangeData> {
|
|||
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;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(())
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue