mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 14:21:44 +00:00
consolidate error handling
This commit is contained in:
parent
20d7a431fd
commit
390a20787e
1 changed files with 17 additions and 14 deletions
|
@ -123,9 +123,7 @@ fn watch_root(
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|path| {
|
.filter_map(|path| {
|
||||||
let abs_path = path.to_path(&config.root);
|
let abs_path = path.to_path(&config.root);
|
||||||
let text = fs::read_to_string(abs_path)
|
let text = read_to_string(&abs_path)?;
|
||||||
.map_err(|e| log::warn!("watcher error: {}", e))
|
|
||||||
.ok()?;
|
|
||||||
Some((path, text))
|
Some((path, text))
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -194,9 +192,7 @@ impl WatcherCtx {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|rel_path| {
|
.filter_map(|rel_path| {
|
||||||
let abs_path = rel_path.to_path(&config.root);
|
let abs_path = rel_path.to_path(&config.root);
|
||||||
let text = fs::read_to_string(&abs_path)
|
let text = read_to_string(&abs_path)?;
|
||||||
.map_err(|e| log::warn!("watcher failed {}", e))
|
|
||||||
.ok()?;
|
|
||||||
Some((rel_path, text))
|
Some((rel_path, text))
|
||||||
})
|
})
|
||||||
.try_for_each(|(path, text)| {
|
.try_for_each(|(path, text)| {
|
||||||
|
@ -204,14 +200,15 @@ impl WatcherCtx {
|
||||||
.send(TaskResult::AddSingleFile { root, path, text })
|
.send(TaskResult::AddSingleFile { root, path, text })
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
ChangeKind::Write => match fs::read_to_string(&path) {
|
ChangeKind::Write => {
|
||||||
Err(e) => log::warn!("watcher failed {}", e),
|
if let Some(text) = read_to_string(&path) {
|
||||||
Ok(text) => self.sender.send(TaskResult::ChangeSingleFile {
|
self.sender.send(TaskResult::ChangeSingleFile {
|
||||||
root,
|
root,
|
||||||
path: rel_path,
|
path: rel_path,
|
||||||
text,
|
text,
|
||||||
})?,
|
})?;
|
||||||
},
|
}
|
||||||
|
}
|
||||||
ChangeKind::Remove => self.sender.send(TaskResult::RemoveSingleFile {
|
ChangeKind::Remove => self.sender.send(TaskResult::RemoveSingleFile {
|
||||||
root,
|
root,
|
||||||
path: rel_path,
|
path: rel_path,
|
||||||
|
@ -250,3 +247,9 @@ fn watch_one(watcher: &mut RecommendedWatcher, dir: &Path) {
|
||||||
Err(e) => log::warn!("could not watch \"{}\": {}", dir.display(), e),
|
Err(e) => log::warn!("could not watch \"{}\": {}", dir.display(), e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_to_string(path: &Path) -> Option<String> {
|
||||||
|
fs::read_to_string(&path)
|
||||||
|
.map_err(|e| log::warn!("failed to read file {}", e))
|
||||||
|
.ok()
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue