aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_proc_macro_srv/Cargo.toml1
-rw-r--r--crates/ra_proc_macro_srv/src/dylib.rs7
-rw-r--r--crates/rust-analyzer/src/cli/load_cargo.rs4
-rw-r--r--crates/rust-analyzer/src/config.rs4
4 files changed, 8 insertions, 8 deletions
diff --git a/crates/ra_proc_macro_srv/Cargo.toml b/crates/ra_proc_macro_srv/Cargo.toml
index 1e0f50339..ac2d156dc 100644
--- a/crates/ra_proc_macro_srv/Cargo.toml
+++ b/crates/ra_proc_macro_srv/Cargo.toml
@@ -14,6 +14,7 @@ ra_mbe = { path = "../ra_mbe" }
14ra_proc_macro = { path = "../ra_proc_macro" } 14ra_proc_macro = { path = "../ra_proc_macro" }
15goblin = "0.2.1" 15goblin = "0.2.1"
16libloading = "0.6.0" 16libloading = "0.6.0"
17memmap = "0.7"
17test_utils = { path = "../test_utils" } 18test_utils = { path = "../test_utils" }
18 19
19[dev-dependencies] 20[dev-dependencies]
diff --git a/crates/ra_proc_macro_srv/src/dylib.rs b/crates/ra_proc_macro_srv/src/dylib.rs
index 7d6e5d323..16bd7466e 100644
--- a/crates/ra_proc_macro_srv/src/dylib.rs
+++ b/crates/ra_proc_macro_srv/src/dylib.rs
@@ -1,10 +1,12 @@
1//! Handles dynamic library loading for proc macro 1//! Handles dynamic library loading for proc macro
2 2
3use crate::{proc_macro::bridge, rustc_server::TokenStream}; 3use crate::{proc_macro::bridge, rustc_server::TokenStream};
4use std::fs::File;
4use std::path::Path; 5use std::path::Path;
5 6
6use goblin::{mach::Mach, Object}; 7use goblin::{mach::Mach, Object};
7use libloading::Library; 8use libloading::Library;
9use memmap::Mmap;
8use ra_proc_macro::ProcMacroKind; 10use ra_proc_macro::ProcMacroKind;
9 11
10use std::io::Error as IoError; 12use std::io::Error as IoError;
@@ -21,7 +23,8 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool {
21} 23}
22 24
23fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> { 25fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> {
24 let buffer = std::fs::read(file)?; 26 let file = File::open(file)?;
27 let buffer = unsafe { Mmap::map(&file)? };
25 let object = Object::parse(&buffer).map_err(invalid_data_err)?; 28 let object = Object::parse(&buffer).map_err(invalid_data_err)?;
26 29
27 match object { 30 match object {
@@ -55,7 +58,7 @@ fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> {
55 &s.name 58 &s.name
56 } 59 }
57 }) 60 })
58 .find(|s| is_derive_registrar_symbol(&s)) 61 .find(|s| is_derive_registrar_symbol(s))
59 .map(|s| s.to_string()); 62 .map(|s| s.to_string());
60 Ok(name) 63 Ok(name)
61 } 64 }
diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs
index eb9ac32c3..762f776fe 100644
--- a/crates/rust-analyzer/src/cli/load_cargo.rs
+++ b/crates/rust-analyzer/src/cli/load_cargo.rs
@@ -75,9 +75,7 @@ pub(crate) fn load_cargo(
75 let proc_macro_client = if !with_proc_macro { 75 let proc_macro_client = if !with_proc_macro {
76 ProcMacroClient::dummy() 76 ProcMacroClient::dummy()
77 } else { 77 } else {
78 let mut path = std::env::current_exe()?; 78 let path = std::env::current_exe()?;
79 path.pop();
80 path.push("rust-analyzer");
81 ProcMacroClient::extern_process(&path, &["proc-macro"]).unwrap() 79 ProcMacroClient::extern_process(&path, &["proc-macro"]).unwrap()
82 }; 80 };
83 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);
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 2b45f1310..3597a14e3 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -134,9 +134,7 @@ 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 if let Ok(mut path) = std::env::current_exe() { 137 if let Ok(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()])); 138 self.proc_macro_srv = Some((path.to_string_lossy().to_string(), vec!["proc-macro".to_string()]));
141 } 139 }
142 } 140 }