mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-31 07:37:30 +00:00
internal: cleanup proc macro server error handlig
When dealing with proc macros, there are two very different kinds of errors: * first, usual errors of "proc macro panicked on this particular input" * second, the proc macro server might day if the user, eg, kills it First kind of errors are expected and are a normal output, while the second kind are genuine IO-errors. For this reason, we use a curious nested result here: `Result<Result<T, E1>, E2>` pattern, which is 100% inspired by http://sled.rs/errors.html
This commit is contained in:
parent
722a2a4690
commit
d8a3d6f378
12 changed files with 242 additions and 271 deletions
|
@ -1,8 +1,9 @@
|
|||
//! Driver for proc macro server
|
||||
use std::io;
|
||||
|
||||
use proc_macro_api::msg::{self, Message};
|
||||
|
||||
use crate::ProcMacroSrv;
|
||||
use proc_macro_api::msg::{self, Message};
|
||||
use std::io;
|
||||
|
||||
pub fn run() -> io::Result<()> {
|
||||
let mut srv = ProcMacroSrv::default();
|
||||
|
@ -10,22 +11,12 @@ pub fn run() -> io::Result<()> {
|
|||
|
||||
while let Some(req) = read_request(&mut buf)? {
|
||||
let res = match req {
|
||||
msg::Request::ListMacro(task) => srv.list_macros(&task).map(msg::Response::ListMacro),
|
||||
msg::Request::ExpansionMacro(task) => {
|
||||
srv.expand(task).map(msg::Response::ExpansionMacro)
|
||||
msg::Request::ListMacros { dylib_path } => {
|
||||
msg::Response::ListMacros(srv.list_macros(&dylib_path))
|
||||
}
|
||||
msg::Request::ExpandMacro(task) => msg::Response::ExpandMacro(srv.expand(task)),
|
||||
};
|
||||
|
||||
let msg = res.unwrap_or_else(|err| {
|
||||
msg::Response::Error(msg::ResponseError {
|
||||
code: msg::ErrorCode::ExpansionError,
|
||||
message: err,
|
||||
})
|
||||
});
|
||||
|
||||
if let Err(err) = write_response(msg) {
|
||||
eprintln!("Write message error: {}", err);
|
||||
}
|
||||
write_response(res)?
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue