mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +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,
|
path: PathBuf,
|
||||||
filter: Box<Fn(&DirEntry) -> bool + Send>,
|
filter: Box<Fn(&DirEntry) -> bool + Send>,
|
||||||
},
|
},
|
||||||
LoadChange(crate::watcher::WatcherChange),
|
HandleChange(WatcherChange),
|
||||||
|
LoadChange(WatcherChange),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -63,6 +64,10 @@ fn handle_task(task: Task) -> TaskResult {
|
||||||
log::debug!("... loaded {}", path.as_path().display());
|
log::debug!("... loaded {}", path.as_path().display());
|
||||||
TaskResult::AddRoot(AddRootResult { root, files })
|
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) => {
|
Task::LoadChange(change) => {
|
||||||
log::debug!("loading {:?} ...", change);
|
log::debug!("loading {:?} ...", change);
|
||||||
let data = load_change(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) {
|
let text = match fs::read_to_string(&path) {
|
||||||
Ok(text) => text,
|
Ok(text) => text,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("watcher error: {}", e);
|
log::warn!("watcher error \"{}\": {}", path.display(), e);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -117,7 +122,7 @@ fn load_change(change: WatcherChange) -> Option<WatcherChangeData> {
|
||||||
let text = match fs::read_to_string(&path) {
|
let text = match fs::read_to_string(&path) {
|
||||||
Ok(text) => text,
|
Ok(text) => text,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("watcher error: {}", e);
|
log::warn!("watcher error \"{}\": {}", path.display(), e);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -266,6 +266,7 @@ impl Vfs {
|
||||||
if let Some(file) = file {
|
if let Some(file) = file {
|
||||||
if self.files[file].is_overlayed {
|
if self.files[file].is_overlayed {
|
||||||
// file is overlayed
|
// file is overlayed
|
||||||
|
log::debug!("skipping overlayed \"{}\"", path.display());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,24 +35,24 @@ fn send_change_events(
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
DebouncedEvent::Rescan => {
|
DebouncedEvent::Rescan => {
|
||||||
sender.send(io::Task::LoadChange(WatcherChange::Rescan))?;
|
sender.send(io::Task::HandleChange(WatcherChange::Rescan))?;
|
||||||
}
|
}
|
||||||
DebouncedEvent::Create(path) => {
|
DebouncedEvent::Create(path) => {
|
||||||
sender.send(io::Task::LoadChange(WatcherChange::Create(path)))?;
|
sender.send(io::Task::HandleChange(WatcherChange::Create(path)))?;
|
||||||
}
|
}
|
||||||
DebouncedEvent::Write(path) => {
|
DebouncedEvent::Write(path) => {
|
||||||
sender.send(io::Task::LoadChange(WatcherChange::Write(path)))?;
|
sender.send(io::Task::HandleChange(WatcherChange::Write(path)))?;
|
||||||
}
|
}
|
||||||
DebouncedEvent::Remove(path) => {
|
DebouncedEvent::Remove(path) => {
|
||||||
sender.send(io::Task::LoadChange(WatcherChange::Remove(path)))?;
|
sender.send(io::Task::HandleChange(WatcherChange::Remove(path)))?;
|
||||||
}
|
}
|
||||||
DebouncedEvent::Rename(src, dst) => {
|
DebouncedEvent::Rename(src, dst) => {
|
||||||
sender.send(io::Task::LoadChange(WatcherChange::Remove(src)))?;
|
sender.send(io::Task::HandleChange(WatcherChange::Remove(src)))?;
|
||||||
sender.send(io::Task::LoadChange(WatcherChange::Create(dst)))?;
|
sender.send(io::Task::HandleChange(WatcherChange::Create(dst)))?;
|
||||||
}
|
}
|
||||||
DebouncedEvent::Error(err, path) => {
|
DebouncedEvent::Error(err, path) => {
|
||||||
// TODO should we reload the file contents?
|
// TODO should we reload the file contents?
|
||||||
log::warn!("watcher error {}, {:?}", err, path);
|
log::warn!("watcher error \"{}\", {:?}", err, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -62,23 +62,24 @@ fn test_vfs_works() -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::write(&dir.path().join("a/b/baz.rs"), "quux").unwrap();
|
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() {
|
match vfs.commit_changes().as_slice() {
|
||||||
[VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"),
|
[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());
|
vfs.change_file_overlay(&dir.path().join("a/b/baz.rs"), "m".to_string());
|
||||||
match vfs.commit_changes().as_slice() {
|
match vfs.commit_changes().as_slice() {
|
||||||
[VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "m"),
|
[VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "m"),
|
||||||
_ => panic!("unexpected changes"),
|
xs => panic!("unexpected changes {:?}", xs),
|
||||||
}
|
}
|
||||||
|
|
||||||
// removing overlay restores data on disk
|
// removing overlay restores data on disk
|
||||||
vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs"));
|
vfs.remove_file_overlay(&dir.path().join("a/b/baz.rs"));
|
||||||
match vfs.commit_changes().as_slice() {
|
match vfs.commit_changes().as_slice() {
|
||||||
[VfsChange::ChangeFile { text, .. }] => assert_eq!(text.as_str(), "quux"),
|
[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());
|
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!(text.as_str(), "spam");
|
||||||
assert_eq!(path, "spam.rs");
|
assert_eq!(path, "spam.rs");
|
||||||
}
|
}
|
||||||
_ => panic!("unexpected changes"),
|
xs => panic!("unexpected changes {:?}", xs),
|
||||||
}
|
}
|
||||||
|
|
||||||
vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs"));
|
vfs.remove_file_overlay(&dir.path().join("a/b/spam.rs"));
|
||||||
match vfs.commit_changes().as_slice() {
|
match vfs.commit_changes().as_slice() {
|
||||||
[VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "spam.rs"),
|
[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();
|
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() {
|
match vfs.commit_changes().as_slice() {
|
||||||
[VfsChange::AddFile { text, path, .. }] => {
|
[VfsChange::AddFile { text, path, .. }] => {
|
||||||
assert_eq!(text.as_str(), "new hello");
|
assert_eq!(text.as_str(), "new hello");
|
||||||
assert_eq!(path, "new.rs");
|
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();
|
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() {
|
match vfs.commit_changes().as_slice() {
|
||||||
[VfsChange::RemoveFile {
|
[VfsChange::RemoveFile {
|
||||||
path: removed_path, ..
|
path: removed_path, ..
|
||||||
|
@ -124,10 +125,10 @@ fn test_vfs_works() -> std::io::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::remove_file(&dir.path().join("a/new1.rs")).unwrap();
|
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() {
|
match vfs.commit_changes().as_slice() {
|
||||||
[VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "new1.rs"),
|
[VfsChange::RemoveFile { path, .. }] => assert_eq!(path, "new1.rs"),
|
||||||
_ => panic!("unexpected changes"),
|
xs => panic!("unexpected changes {:?}", xs),
|
||||||
}
|
}
|
||||||
|
|
||||||
match vfs.task_receiver().try_recv() {
|
match vfs.task_receiver().try_recv() {
|
||||||
|
|
Loading…
Reference in a new issue