rust-analyzer/crates/proc-macro-srv/src/cli.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
833 B
Rust
Raw Normal View History

2020-04-03 11:16:54 +00:00
//! Driver for proc macro server
use std::io;
2020-04-03 11:16:54 +00:00
2020-08-13 10:07:28 +00:00
use proc_macro_api::msg::{self, Message};
use crate::ProcMacroSrv;
2020-04-01 05:11:26 +00:00
2020-04-23 17:38:58 +00:00
pub fn run() -> io::Result<()> {
2020-04-24 02:23:01 +00:00
let mut srv = ProcMacroSrv::default();
let mut buf = String::new();
2020-04-24 02:23:01 +00:00
while let Some(req) = read_request(&mut buf)? {
2020-04-20 18:26:10 +00:00
let res = match req {
msg::Request::ListMacros { dylib_path } => {
msg::Response::ListMacros(srv.list_macros(&dylib_path))
2020-04-01 05:11:26 +00:00
}
msg::Request::ExpandMacro(task) => msg::Response::ExpandMacro(srv.expand(task)),
2020-04-20 18:26:10 +00:00
};
write_response(res)?
2020-04-01 05:11:26 +00:00
}
2020-04-24 01:27:37 +00:00
Ok(())
2020-04-01 05:11:26 +00:00
}
2020-04-20 18:26:10 +00:00
fn read_request(buf: &mut String) -> io::Result<Option<msg::Request>> {
msg::Request::read(&mut io::stdin().lock(), buf)
2020-04-20 18:26:10 +00:00
}
fn write_response(msg: msg::Response) -> io::Result<()> {
msg.write(&mut io::stdout().lock())
}