diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_proc_macro/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_proc_macro/src/process.rs | 8 | ||||
-rw-r--r-- | crates/ra_proc_macro_srv/src/cli.rs (renamed from crates/ra_proc_macro_srv/src/main.rs) | 5 | ||||
-rw-r--r-- | crates/ra_proc_macro_srv/src/lib.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/args.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/bin/main.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 5 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/src/world.rs | 6 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/main.rs | 6 |
11 files changed, 43 insertions, 18 deletions
diff --git a/crates/ra_proc_macro/src/lib.rs b/crates/ra_proc_macro/src/lib.rs index 63da9f1b4..14a675db2 100644 --- a/crates/ra_proc_macro/src/lib.rs +++ b/crates/ra_proc_macro/src/lib.rs | |||
@@ -56,8 +56,11 @@ pub struct ProcMacroClient { | |||
56 | } | 56 | } |
57 | 57 | ||
58 | impl ProcMacroClient { | 58 | impl ProcMacroClient { |
59 | pub fn extern_process(process_path: &Path) -> Result<ProcMacroClient, std::io::Error> { | 59 | pub fn extern_process<T: AsRef<str>>( |
60 | let (thread, process) = ProcMacroProcessSrv::run(process_path)?; | 60 | process_path: &Path, |
61 | args: &[T], | ||
62 | ) -> Result<ProcMacroClient, std::io::Error> { | ||
63 | let (thread, process) = ProcMacroProcessSrv::run(process_path, args)?; | ||
61 | Ok(ProcMacroClient { | 64 | Ok(ProcMacroClient { |
62 | kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, | 65 | kind: ProcMacroClientKind::Process { process: Arc::new(process), thread }, |
63 | }) | 66 | }) |
diff --git a/crates/ra_proc_macro/src/process.rs b/crates/ra_proc_macro/src/process.rs index e8c85be38..b5e8493ac 100644 --- a/crates/ra_proc_macro/src/process.rs +++ b/crates/ra_proc_macro/src/process.rs | |||
@@ -44,8 +44,9 @@ impl Drop for Process { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | impl Process { | 46 | impl Process { |
47 | fn run(process_path: &Path) -> Result<Process, io::Error> { | 47 | fn run<T: AsRef<str>>(process_path: &Path, args: &[T]) -> Result<Process, io::Error> { |
48 | let child = Command::new(process_path.clone()) | 48 | let child = Command::new(process_path.clone()) |
49 | .args(args.iter().map(|it| it.as_ref())) | ||
49 | .stdin(Stdio::piped()) | 50 | .stdin(Stdio::piped()) |
50 | .stdout(Stdio::piped()) | 51 | .stdout(Stdio::piped()) |
51 | .stderr(Stdio::null()) | 52 | .stderr(Stdio::null()) |
@@ -74,10 +75,11 @@ impl Process { | |||
74 | } | 75 | } |
75 | 76 | ||
76 | impl ProcMacroProcessSrv { | 77 | impl ProcMacroProcessSrv { |
77 | pub fn run( | 78 | pub fn run<T: AsRef<str>>( |
78 | process_path: &Path, | 79 | process_path: &Path, |
80 | args: &[T], | ||
79 | ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> { | 81 | ) -> Result<(ProcMacroProcessThread, ProcMacroProcessSrv), io::Error> { |
80 | let process = Process::run(process_path)?; | 82 | let process = Process::run(process_path, args)?; |
81 | 83 | ||
82 | let (task_tx, task_rx) = bounded(0); | 84 | let (task_tx, task_rx) = bounded(0); |
83 | let handle = jod_thread::spawn(move || { | 85 | let handle = jod_thread::spawn(move || { |
diff --git a/crates/ra_proc_macro_srv/src/main.rs b/crates/ra_proc_macro_srv/src/cli.rs index 70743c1f4..c771f2b38 100644 --- a/crates/ra_proc_macro_srv/src/main.rs +++ b/crates/ra_proc_macro_srv/src/cli.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! Driver for proc macro server | 1 | //! Driver for proc macro server |
2 | 2 | ||
3 | use crate::{expand_task, list_macros}; | ||
3 | use ra_proc_macro::msg::{self, Message}; | 4 | use ra_proc_macro::msg::{self, Message}; |
4 | use ra_proc_macro_srv::{expand_task, list_macros}; | ||
5 | 5 | ||
6 | use std::io; | 6 | use std::io; |
7 | 7 | ||
@@ -24,7 +24,8 @@ fn write_response(res: Result<msg::Response, String>) -> Result<(), io::Error> { | |||
24 | let mut stdout = stdout.lock(); | 24 | let mut stdout = stdout.lock(); |
25 | msg.write(&mut stdout) | 25 | msg.write(&mut stdout) |
26 | } | 26 | } |
27 | fn main() { | 27 | |
28 | pub fn run() { | ||
28 | loop { | 29 | loop { |
29 | let req = match read_request() { | 30 | let req = match read_request() { |
30 | Err(err) => { | 31 | Err(err) => { |
diff --git a/crates/ra_proc_macro_srv/src/lib.rs b/crates/ra_proc_macro_srv/src/lib.rs index 59716cbb3..c62b0ed89 100644 --- a/crates/ra_proc_macro_srv/src/lib.rs +++ b/crates/ra_proc_macro_srv/src/lib.rs | |||
@@ -22,7 +22,7 @@ mod dylib; | |||
22 | use proc_macro::bridge::client::TokenStream; | 22 | use proc_macro::bridge::client::TokenStream; |
23 | use ra_proc_macro::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask}; | 23 | use ra_proc_macro::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask}; |
24 | 24 | ||
25 | pub fn expand_task(task: &ExpansionTask) -> Result<ExpansionResult, String> { | 25 | pub(crate) fn expand_task(task: &ExpansionTask) -> Result<ExpansionResult, String> { |
26 | let expander = dylib::Expander::new(&task.lib) | 26 | let expander = dylib::Expander::new(&task.lib) |
27 | .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); | 27 | .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); |
28 | 28 | ||
@@ -39,7 +39,7 @@ pub fn expand_task(task: &ExpansionTask) -> Result<ExpansionResult, String> { | |||
39 | } | 39 | } |
40 | } | 40 | } |
41 | 41 | ||
42 | pub fn list_macros(task: &ListMacrosTask) -> Result<ListMacrosResult, String> { | 42 | pub(crate) fn list_macros(task: &ListMacrosTask) -> Result<ListMacrosResult, String> { |
43 | let expander = dylib::Expander::new(&task.lib) | 43 | let expander = dylib::Expander::new(&task.lib) |
44 | .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); | 44 | .expect(&format!("Cannot expand with provided libraries: ${:?}", &task.lib)); |
45 | 45 | ||
@@ -53,5 +53,7 @@ pub fn list_macros(task: &ListMacrosTask) -> Result<ListMacrosResult, String> { | |||
53 | } | 53 | } |
54 | } | 54 | } |
55 | 55 | ||
56 | pub mod cli; | ||
57 | |||
56 | #[cfg(test)] | 58 | #[cfg(test)] |
57 | mod tests; | 59 | mod tests; |
diff --git a/crates/rust-analyzer/Cargo.toml b/crates/rust-analyzer/Cargo.toml index f5f773432..cee0248b6 100644 --- a/crates/rust-analyzer/Cargo.toml +++ b/crates/rust-analyzer/Cargo.toml | |||
@@ -46,7 +46,7 @@ ra_db = { path = "../ra_db" } | |||
46 | hir = { path = "../ra_hir", package = "ra_hir" } | 46 | hir = { path = "../ra_hir", package = "ra_hir" } |
47 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } | 47 | hir_def = { path = "../ra_hir_def", package = "ra_hir_def" } |
48 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } | 48 | hir_ty = { path = "../ra_hir_ty", package = "ra_hir_ty" } |
49 | 49 | ra_proc_macro_srv = { path = "../ra_proc_macro_srv" } | |
50 | 50 | ||
51 | [target.'cfg(windows)'.dependencies] | 51 | [target.'cfg(windows)'.dependencies] |
52 | winapi = "0.3.8" | 52 | winapi = "0.3.8" |
diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index ec93e9e4e..5e19253a6 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs | |||
@@ -45,6 +45,7 @@ pub(crate) enum Command { | |||
45 | /// this would include the parser test files. | 45 | /// this would include the parser test files. |
46 | all: bool, | 46 | all: bool, |
47 | }, | 47 | }, |
48 | ProcMacro, | ||
48 | RunServer, | 49 | RunServer, |
49 | Version, | 50 | Version, |
50 | } | 51 | } |
@@ -264,6 +265,7 @@ ARGS: | |||
264 | 265 | ||
265 | Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } | 266 | Command::Diagnostics { path, load_output_dirs, with_proc_macro, all } |
266 | } | 267 | } |
268 | "proc-macro" => Command::ProcMacro, | ||
267 | _ => { | 269 | _ => { |
268 | eprintln!( | 270 | eprintln!( |
269 | "\ | 271 | "\ |
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 5f614a013..28b67cfe2 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -51,6 +51,7 @@ fn main() -> Result<()> { | |||
51 | cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)? | 51 | cli::diagnostics(path.as_ref(), load_output_dirs, with_proc_macro, all)? |
52 | } | 52 | } |
53 | 53 | ||
54 | args::Command::ProcMacro => run_proc_macro_sv()?, | ||
54 | args::Command::RunServer => run_server()?, | 55 | args::Command::RunServer => run_server()?, |
55 | args::Command::Version => println!("rust-analyzer {}", env!("REV")), | 56 | args::Command::Version => println!("rust-analyzer {}", env!("REV")), |
56 | } | 57 | } |
@@ -64,6 +65,11 @@ fn setup_logging() -> Result<()> { | |||
64 | Ok(()) | 65 | Ok(()) |
65 | } | 66 | } |
66 | 67 | ||
68 | fn run_proc_macro_sv() -> Result<()> { | ||
69 | ra_proc_macro_srv::cli::run(); | ||
70 | Ok(()) | ||
71 | } | ||
72 | |||
67 | fn run_server() -> Result<()> { | 73 | fn run_server() -> Result<()> { |
68 | log::info!("lifecycle: server started"); | 74 | log::info!("lifecycle: server started"); |
69 | 75 | ||
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index dfda488fb..32a9ee339 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs | |||
@@ -73,7 +73,10 @@ pub(crate) fn load_cargo( | |||
73 | let proc_macro_client = if !with_proc_macro { | 73 | let proc_macro_client = if !with_proc_macro { |
74 | ProcMacroClient::dummy() | 74 | ProcMacroClient::dummy() |
75 | } else { | 75 | } else { |
76 | ProcMacroClient::extern_process(Path::new("ra_proc_macro_srv")).unwrap() | 76 | let mut path = std::env::current_exe()?; |
77 | path.pop(); | ||
78 | path.push("rust-analyzer"); | ||
79 | ProcMacroClient::extern_process(&path, &["proc-macro"]).unwrap() | ||
77 | }; | 80 | }; |
78 | let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client); | 81 | let host = load(&source_roots, ws, &mut vfs, receiver, extern_dirs, &proc_macro_client); |
79 | Ok((host, source_roots)) | 82 | Ok((host, source_roots)) |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 46a89b37e..2b45f1310 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -20,7 +20,7 @@ pub struct Config { | |||
20 | pub with_sysroot: bool, | 20 | pub with_sysroot: bool, |
21 | pub publish_diagnostics: bool, | 21 | pub publish_diagnostics: bool, |
22 | pub lru_capacity: Option<usize>, | 22 | pub lru_capacity: Option<usize>, |
23 | pub proc_macro_srv: Option<String>, | 23 | pub proc_macro_srv: Option<(String, Vec<String>)>, |
24 | pub files: FilesConfig, | 24 | pub files: FilesConfig, |
25 | pub notifications: NotificationsConfig, | 25 | pub notifications: NotificationsConfig, |
26 | 26 | ||
@@ -134,7 +134,11 @@ impl Config { | |||
134 | 134 | ||
135 | match get::<bool>(value, "/procMacro/enabled") { | 135 | match get::<bool>(value, "/procMacro/enabled") { |
136 | Some(true) => { | 136 | Some(true) => { |
137 | set(value, "/procMacro/serverPath", &mut self.proc_macro_srv); | 137 | if let Ok(mut path) = std::env::current_exe() { |
138 | path.pop(); | ||
139 | path.push("rust-analyzer"); | ||
140 | self.proc_macro_srv = Some((path.to_string_lossy().to_string(), vec!["proc-macro".to_string()])); | ||
141 | } | ||
138 | } | 142 | } |
139 | _ => self.proc_macro_srv = None, | 143 | _ => self.proc_macro_srv = None, |
140 | } | 144 | } |
diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index b7142e83b..f2ad453fa 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs | |||
@@ -148,9 +148,9 @@ impl WorldState { | |||
148 | 148 | ||
149 | let proc_macro_client = match &config.proc_macro_srv { | 149 | let proc_macro_client = match &config.proc_macro_srv { |
150 | None => ProcMacroClient::dummy(), | 150 | None => ProcMacroClient::dummy(), |
151 | Some(srv) => { | 151 | Some((path, args)) => { |
152 | let path = Path::new(&srv); | 152 | let path = std::path::Path::new(path); |
153 | match ProcMacroClient::extern_process(path) { | 153 | match ProcMacroClient::extern_process(path, args) { |
154 | Ok(it) => it, | 154 | Ok(it) => it, |
155 | Err(err) => { | 155 | Err(err) => { |
156 | log::error!( | 156 | log::error!( |
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index 26ab81a8f..1dd2676b6 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs | |||
@@ -692,13 +692,15 @@ pub fn foo(_input: TokenStream) -> TokenStream { | |||
692 | "###, | 692 | "###, |
693 | ) | 693 | ) |
694 | .with_config(|config| { | 694 | .with_config(|config| { |
695 | // FIXME: Use env!("CARGO_BIN_EXE_ra-analyzer") instead after | ||
696 | // https://github.com/rust-lang/cargo/pull/7697 landed | ||
695 | let macro_srv_path = std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")) | 697 | let macro_srv_path = std::path::Path::new(std::env!("CARGO_MANIFEST_DIR")) |
696 | .join("../../target/debug/ra_proc_macro_srv") | 698 | .join("../../target/debug/rust-analyzer") |
697 | .to_string_lossy() | 699 | .to_string_lossy() |
698 | .to_string(); | 700 | .to_string(); |
699 | 701 | ||
700 | config.cargo.load_out_dirs_from_check = true; | 702 | config.cargo.load_out_dirs_from_check = true; |
701 | config.proc_macro_srv = Some(macro_srv_path) | 703 | config.proc_macro_srv = Some((macro_srv_path, vec!["proc-macro".to_string()])); |
702 | }) | 704 | }) |
703 | .root("foo") | 705 | .root("foo") |
704 | .root("bar") | 706 | .root("bar") |