1 //! A standalone binary for `proc-macro-srv`.
2 //! Driver for proc macro server
5 fn main() -> std
::io
::Result
<()> {
6 let v
= std
::env
::var("RUST_ANALYZER_INTERNALS_DO_NOT_USE");
8 Ok("this is unstable") => {
9 // very well, if you must
12 eprintln
!("If you're rust-analyzer, you can use this tool by exporting RUST_ANALYZER_INTERNALS_DO_NOT_USE='this is unstable'.");
13 eprintln
!("If not, you probably shouldn't use this tool. But do what you want: I'm an error message, not a cop.");
14 std
::process
::exit(122);
21 #[cfg(not(feature = "sysroot-abi"))]
22 fn run() -> io
::Result
<()> {
23 panic
!("proc-macro-srv-cli requires the `sysroot-abi` feature to be enabled");
26 #[cfg(feature = "sysroot-abi")]
27 fn run() -> io
::Result
<()> {
28 use proc_macro_api
::msg
::{self, Message}
;
30 let read_request
= |buf
: &mut String
| msg
::Request
::read(&mut io
::stdin().lock(), buf
);
32 let write_response
= |msg
: msg
::Response
| msg
.write(&mut io
::stdout().lock());
34 let mut srv
= proc_macro_srv
::ProcMacroSrv
::default();
35 let mut buf
= String
::new();
37 while let Some(req
) = read_request(&mut buf
)?
{
39 msg
::Request
::ListMacros { dylib_path }
=> {
40 msg
::Response
::ListMacros(srv
.list_macros(&dylib_path
))
42 msg
::Request
::ExpandMacro(task
) => msg
::Response
::ExpandMacro(srv
.expand(task
)),
43 msg
::Request
::ApiVersionCheck {}
=> {
44 msg
::Response
::ApiVersionCheck(proc_macro_api
::msg
::CURRENT_API_VERSION
)