diff options
-rw-r--r-- | Cargo.lock | 11 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_trait_impl.rs | 19 | ||||
-rw-r--r-- | crates/ra_proc_macro_srv/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_proc_macro_srv/src/dylib.rs | 7 | ||||
-rw-r--r-- | crates/rust-analyzer/src/cli/load_cargo.rs | 4 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 4 |
6 files changed, 29 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock index 89a734c9b..3826ae1c6 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -676,6 +676,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
676 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" | 676 | checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" |
677 | 677 | ||
678 | [[package]] | 678 | [[package]] |
679 | name = "memmap" | ||
680 | version = "0.7.0" | ||
681 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
682 | checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" | ||
683 | dependencies = [ | ||
684 | "libc", | ||
685 | "winapi 0.3.8", | ||
686 | ] | ||
687 | |||
688 | [[package]] | ||
679 | name = "memoffset" | 689 | name = "memoffset" |
680 | version = "0.5.4" | 690 | version = "0.5.4" |
681 | source = "registry+https://github.com/rust-lang/crates.io-index" | 691 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -1112,6 +1122,7 @@ dependencies = [ | |||
1112 | "difference", | 1122 | "difference", |
1113 | "goblin", | 1123 | "goblin", |
1114 | "libloading", | 1124 | "libloading", |
1125 | "memmap", | ||
1115 | "ra_mbe", | 1126 | "ra_mbe", |
1116 | "ra_proc_macro", | 1127 | "ra_proc_macro", |
1117 | "ra_tt", | 1128 | "ra_tt", |
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index fab02945c..2ec0e7ce9 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs | |||
@@ -142,11 +142,11 @@ fn add_function_impl( | |||
142 | CompletionItemKind::Function | 142 | CompletionItemKind::Function |
143 | }; | 143 | }; |
144 | 144 | ||
145 | let snippet = format!("{} {{}}", display); | 145 | let snippet = format!("{} {{\n $0\n}}", display); |
146 | 146 | ||
147 | let range = TextRange::from_to(fn_def_node.text_range().start(), ctx.source_range().end()); | 147 | let range = TextRange::from_to(fn_def_node.text_range().start(), ctx.source_range().end()); |
148 | 148 | ||
149 | builder.text_edit(TextEdit::replace(range, snippet)).kind(completion_kind).add_to(acc); | 149 | builder.snippet_edit(TextEdit::replace(range, snippet)).kind(completion_kind).add_to(acc); |
150 | } | 150 | } |
151 | 151 | ||
152 | fn add_type_alias_impl( | 152 | fn add_type_alias_impl( |
@@ -217,9 +217,10 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { | |||
217 | 217 | ||
218 | #[cfg(test)] | 218 | #[cfg(test)] |
219 | mod tests { | 219 | mod tests { |
220 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | ||
221 | use insta::assert_debug_snapshot; | 220 | use insta::assert_debug_snapshot; |
222 | 221 | ||
222 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | ||
223 | |||
223 | fn complete(code: &str) -> Vec<CompletionItem> { | 224 | fn complete(code: &str) -> Vec<CompletionItem> { |
224 | do_completion(code, CompletionKind::Magic) | 225 | do_completion(code, CompletionKind::Magic) |
225 | } | 226 | } |
@@ -255,7 +256,7 @@ mod tests { | |||
255 | label: "fn test()", | 256 | label: "fn test()", |
256 | source_range: [209; 210), | 257 | source_range: [209; 210), |
257 | delete: [209; 210), | 258 | delete: [209; 210), |
258 | insert: "fn test() {}", | 259 | insert: "fn test() {\n $0\n}", |
259 | kind: Function, | 260 | kind: Function, |
260 | lookup: "test", | 261 | lookup: "test", |
261 | }, | 262 | }, |
@@ -313,7 +314,7 @@ mod tests { | |||
313 | label: "fn test()", | 314 | label: "fn test()", |
314 | source_range: [139; 140), | 315 | source_range: [139; 140), |
315 | delete: [139; 140), | 316 | delete: [139; 140), |
316 | insert: "fn test() {}", | 317 | insert: "fn test() {\n $0\n}", |
317 | kind: Function, | 318 | kind: Function, |
318 | lookup: "test", | 319 | lookup: "test", |
319 | }, | 320 | }, |
@@ -342,7 +343,7 @@ mod tests { | |||
342 | label: "fn foo()", | 343 | label: "fn foo()", |
343 | source_range: [141; 142), | 344 | source_range: [141; 142), |
344 | delete: [138; 142), | 345 | delete: [138; 142), |
345 | insert: "fn foo() {}", | 346 | insert: "fn foo() {\n $0\n}", |
346 | kind: Function, | 347 | kind: Function, |
347 | lookup: "foo", | 348 | lookup: "foo", |
348 | }, | 349 | }, |
@@ -374,7 +375,7 @@ mod tests { | |||
374 | label: "fn foo_bar()", | 375 | label: "fn foo_bar()", |
375 | source_range: [200; 201), | 376 | source_range: [200; 201), |
376 | delete: [197; 201), | 377 | delete: [197; 201), |
377 | insert: "fn foo_bar() {}", | 378 | insert: "fn foo_bar() {\n $0\n}", |
378 | kind: Function, | 379 | kind: Function, |
379 | lookup: "foo_bar", | 380 | lookup: "foo_bar", |
380 | }, | 381 | }, |
@@ -425,7 +426,7 @@ mod tests { | |||
425 | label: "fn foo()", | 426 | label: "fn foo()", |
426 | source_range: [144; 145), | 427 | source_range: [144; 145), |
427 | delete: [141; 145), | 428 | delete: [141; 145), |
428 | insert: "fn foo<T>() {}", | 429 | insert: "fn foo<T>() {\n $0\n}", |
429 | kind: Function, | 430 | kind: Function, |
430 | lookup: "foo", | 431 | lookup: "foo", |
431 | }, | 432 | }, |
@@ -454,7 +455,7 @@ mod tests { | |||
454 | label: "fn foo()", | 455 | label: "fn foo()", |
455 | source_range: [166; 167), | 456 | source_range: [166; 167), |
456 | delete: [163; 167), | 457 | delete: [163; 167), |
457 | insert: "fn foo<T>()\nwhere T: Into<String> {}", | 458 | insert: "fn foo<T>()\nwhere T: Into<String> {\n $0\n}", |
458 | kind: Function, | 459 | kind: Function, |
459 | lookup: "foo", | 460 | lookup: "foo", |
460 | }, | 461 | }, |
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" } | |||
14 | ra_proc_macro = { path = "../ra_proc_macro" } | 14 | ra_proc_macro = { path = "../ra_proc_macro" } |
15 | goblin = "0.2.1" | 15 | goblin = "0.2.1" |
16 | libloading = "0.6.0" | 16 | libloading = "0.6.0" |
17 | memmap = "0.7" | ||
17 | test_utils = { path = "../test_utils" } | 18 | test_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 | ||
3 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; | 3 | use crate::{proc_macro::bridge, rustc_server::TokenStream}; |
4 | use std::fs::File; | ||
4 | use std::path::Path; | 5 | use std::path::Path; |
5 | 6 | ||
6 | use goblin::{mach::Mach, Object}; | 7 | use goblin::{mach::Mach, Object}; |
7 | use libloading::Library; | 8 | use libloading::Library; |
9 | use memmap::Mmap; | ||
8 | use ra_proc_macro::ProcMacroKind; | 10 | use ra_proc_macro::ProcMacroKind; |
9 | 11 | ||
10 | use std::io::Error as IoError; | 12 | use std::io::Error as IoError; |
@@ -21,7 +23,8 @@ fn is_derive_registrar_symbol(symbol: &str) -> bool { | |||
21 | } | 23 | } |
22 | 24 | ||
23 | fn find_registrar_symbol(file: &Path) -> Result<Option<String>, IoError> { | 25 | fn 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 | } |