Add proc-macro cli command for rust-analyzer

This commit is contained in:
Edwin Cheng
2020-04-16 21:13:57 +08:00
parent ca7dc69a8e
commit 177becea98
14 changed files with 47 additions and 26 deletions

View File

@@ -45,6 +45,7 @@ pub(crate) enum Command {
/// this would include the parser test files.
all: bool,
},
ProcMacro,
RunServer,
Version,
}
@@ -264,6 +265,7 @@ ARGS:
Command::Diagnostics { path, load_output_dirs, with_proc_macro, all }
}
"proc-macro" => Command::ProcMacro,
_ => {
eprintln!(
"\

View File

@@ -51,6 +51,7 @@ fn main() -> Result<()> {
cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)?
}
args::Command::ProcMacro => run_proc_macro_sv()?,
args::Command::RunServer => run_server()?,
args::Command::Version => println!("rust-analyzer {}", env!("REV")),
}
@@ -64,6 +65,11 @@ fn setup_logging() -> Result<()> {
Ok(())
}
fn run_proc_macro_sv() -> Result<()> {
ra_proc_macro_srv::cli::run();
Ok(())
}
fn run_server() -> Result<()> {
log::info!("lifecycle: server started");

View File

@@ -73,7 +73,10 @@ pub(crate) fn load_cargo(
let proc_macro_client = if !with_proc_macro {
ProcMacroClient::dummy()
} else {
ProcMacroClient::extern_process(Path::new("ra_proc_macro_srv")).unwrap()
let mut path = std::env::current_exe()?;
path.pop();
path.push("rust-analyzer");
ProcMacroClient::extern_process(&path, &["proc-macro"]).unwrap()
};
let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client);
Ok((host, source_roots))

View File

@@ -20,7 +20,7 @@ pub struct Config {
pub with_sysroot: bool,
pub publish_diagnostics: bool,
pub lru_capacity: Option<usize>,
pub proc_macro_srv: Option<String>,
pub proc_macro_srv: Option<(String, Vec<String>)>,
pub files: FilesConfig,
pub notifications: NotificationsConfig,
@@ -134,7 +134,11 @@ impl Config {
match get::<bool>(value, "/procMacro/enabled") {
Some(true) => {
set(value, "/procMacro/serverPath", &mut self.proc_macro_srv);
if let Ok(mut path) = std::env::current_exe() {
path.pop();
path.push("rust-analyzer");
self.proc_macro_srv = Some((path.to_string_lossy().to_string(), vec!["proc-macro".to_string()]));
}
}
_ => self.proc_macro_srv = None,
}

View File

@@ -148,9 +148,9 @@ impl WorldState {
let proc_macro_client = match &config.proc_macro_srv {
None => ProcMacroClient::dummy(),
Some(srv) => {
let path = Path::new(&srv);
match ProcMacroClient::extern_process(path) {
Some((path, args)) => {
let path = std::path::Path::new(path);
match ProcMacroClient::extern_process(path, args) {
Ok(it) => it,
Err(err) => {
log::error!(