diff options
-rw-r--r-- | crates/ide_completion/src/render.rs | 60 | ||||
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 17 | ||||
-rw-r--r-- | crates/proc_macro_api/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/proc_macro_api/src/version.rs | 13 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/mod.rs | 7 | ||||
-rw-r--r-- | crates/proc_macro_srv/src/tests/utils.rs | 2 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 2 | ||||
-rw-r--r-- | docs/user/generated_config.adoc | 2 | ||||
-rw-r--r-- | editors/code/package.json | 2 |
9 files changed, 96 insertions, 12 deletions
diff --git a/crates/ide_completion/src/render.rs b/crates/ide_completion/src/render.rs index 670563e50..2514dda7c 100644 --- a/crates/ide_completion/src/render.rs +++ b/crates/ide_completion/src/render.rs | |||
@@ -928,6 +928,66 @@ fn f(foo: &Foo) { f(foo, w$0) } | |||
928 | } | 928 | } |
929 | 929 | ||
930 | #[test] | 930 | #[test] |
931 | fn score_fn_type_and_name_match() { | ||
932 | check_relevance( | ||
933 | r#" | ||
934 | struct A { bar: u8 } | ||
935 | fn baz() -> u8 { 0 } | ||
936 | fn bar() -> u8 { 0 } | ||
937 | fn f() { A { bar: b$0 }; } | ||
938 | "#, | ||
939 | expect![[r#" | ||
940 | fn baz() [type] | ||
941 | st A [] | ||
942 | fn bar() [type+name] | ||
943 | fn f() [] | ||
944 | "#]], | ||
945 | ); | ||
946 | } | ||
947 | |||
948 | #[test] | ||
949 | fn score_method_type_and_name_match() { | ||
950 | check_relevance( | ||
951 | r#" | ||
952 | fn baz(aaa: u32){} | ||
953 | struct Foo; | ||
954 | impl Foo { | ||
955 | fn aaa(&self) -> u32 { 0 } | ||
956 | fn bbb(&self) -> u32 { 0 } | ||
957 | fn ccc(&self) -> u64 { 0 } | ||
958 | } | ||
959 | fn f() { | ||
960 | baz(Foo.$0 | ||
961 | } | ||
962 | "#, | ||
963 | expect![[r#" | ||
964 | me aaa() [type+name] | ||
965 | me bbb() [type] | ||
966 | me ccc() [] | ||
967 | "#]], | ||
968 | ); | ||
969 | } | ||
970 | |||
971 | #[test] | ||
972 | fn score_method_name_match_only() { | ||
973 | check_relevance( | ||
974 | r#" | ||
975 | fn baz(aaa: u32){} | ||
976 | struct Foo; | ||
977 | impl Foo { | ||
978 | fn aaa(&self) -> u64 { 0 } | ||
979 | } | ||
980 | fn f() { | ||
981 | baz(Foo.$0 | ||
982 | } | ||
983 | "#, | ||
984 | expect![[r#" | ||
985 | me aaa() [name] | ||
986 | "#]], | ||
987 | ); | ||
988 | } | ||
989 | |||
990 | #[test] | ||
931 | fn suggest_ref_mut() { | 991 | fn suggest_ref_mut() { |
932 | cov_mark::check!(suggest_ref); | 992 | cov_mark::check!(suggest_ref); |
933 | check( | 993 | check( |
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index f4dabe3d1..47e26a5d8 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs | |||
@@ -5,7 +5,7 @@ use ide_db::SymbolKind; | |||
5 | use syntax::ast::Fn; | 5 | use syntax::ast::Fn; |
6 | 6 | ||
7 | use crate::{ | 7 | use crate::{ |
8 | item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit}, | 8 | item::{CompletionItem, CompletionItemKind, CompletionKind, CompletionRelevance, ImportEdit}, |
9 | render::{builder_ext::Params, RenderContext}, | 9 | render::{builder_ext::Params, RenderContext}, |
10 | }; | 10 | }; |
11 | 11 | ||
@@ -55,6 +55,21 @@ impl<'a> FunctionRender<'a> { | |||
55 | .add_call_parens(self.ctx.completion, self.name, params) | 55 | .add_call_parens(self.ctx.completion, self.name, params) |
56 | .add_import(import_to_add); | 56 | .add_import(import_to_add); |
57 | 57 | ||
58 | let mut relevance = CompletionRelevance::default(); | ||
59 | if let Some(expected_type) = &self.ctx.completion.expected_type { | ||
60 | let ret_ty = self.func.ret_type(self.ctx.db()); | ||
61 | |||
62 | // We don't ever consider a function which returns unit type to be an | ||
63 | // exact type match, since nearly always this is not meaningful to the | ||
64 | // user. | ||
65 | relevance.exact_type_match = &ret_ty == expected_type && !ret_ty.is_unit(); | ||
66 | } | ||
67 | if let Some(expected_name) = &self.ctx.completion.expected_name { | ||
68 | relevance.exact_name_match = | ||
69 | expected_name == &self.func.name(self.ctx.db()).to_string(); | ||
70 | } | ||
71 | item.set_relevance(relevance); | ||
72 | |||
58 | item.build() | 73 | item.build() |
59 | } | 74 | } |
60 | 75 | ||
diff --git a/crates/proc_macro_api/src/lib.rs b/crates/proc_macro_api/src/lib.rs index 941d0fe9e..2dd2a8541 100644 --- a/crates/proc_macro_api/src/lib.rs +++ b/crates/proc_macro_api/src/lib.rs | |||
@@ -23,6 +23,7 @@ use tt::{SmolStr, Subtree}; | |||
23 | use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; | 23 | use crate::process::{ProcMacroProcessSrv, ProcMacroProcessThread}; |
24 | 24 | ||
25 | pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; | 25 | pub use rpc::{ExpansionResult, ExpansionTask, ListMacrosResult, ListMacrosTask, ProcMacroKind}; |
26 | pub use version::{read_dylib_info, RustCInfo}; | ||
26 | 27 | ||
27 | #[derive(Debug, Clone)] | 28 | #[derive(Debug, Clone)] |
28 | struct ProcMacroProcessExpander { | 29 | struct ProcMacroProcessExpander { |
@@ -76,7 +77,7 @@ impl ProcMacroClient { | |||
76 | } | 77 | } |
77 | 78 | ||
78 | pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> { | 79 | pub fn by_dylib_path(&self, dylib_path: &Path) -> Vec<ProcMacro> { |
79 | match version::read_info(dylib_path) { | 80 | match version::read_dylib_info(dylib_path) { |
80 | Ok(info) => { | 81 | Ok(info) => { |
81 | if info.version.0 < 1 || info.version.1 < 47 { | 82 | if info.version.0 < 1 || info.version.1 < 47 { |
82 | eprintln!("proc-macro {} built by {:#?} is not supported by Rust Analyzer, please update your rust version.", dylib_path.to_string_lossy(), info); | 83 | eprintln!("proc-macro {} built by {:#?} is not supported by Rust Analyzer, please update your rust version.", dylib_path.to_string_lossy(), info); |
diff --git a/crates/proc_macro_api/src/version.rs b/crates/proc_macro_api/src/version.rs index b903658fb..dcf8fae8f 100644 --- a/crates/proc_macro_api/src/version.rs +++ b/crates/proc_macro_api/src/version.rs | |||
@@ -11,14 +11,15 @@ use object::read::{File as BinaryFile, Object, ObjectSection}; | |||
11 | use snap::read::FrameDecoder as SnapDecoder; | 11 | use snap::read::FrameDecoder as SnapDecoder; |
12 | 12 | ||
13 | #[derive(Debug)] | 13 | #[derive(Debug)] |
14 | pub(crate) struct RustCInfo { | 14 | pub struct RustCInfo { |
15 | pub(crate) version: (usize, usize, usize), | 15 | pub version: (usize, usize, usize), |
16 | pub(crate) channel: String, | 16 | pub channel: String, |
17 | pub(crate) commit: String, | 17 | pub commit: String, |
18 | pub(crate) date: String, | 18 | pub date: String, |
19 | } | 19 | } |
20 | 20 | ||
21 | pub(crate) fn read_info(dylib_path: &Path) -> io::Result<RustCInfo> { | 21 | /// Read rustc dylib information |
22 | pub fn read_dylib_info(dylib_path: &Path) -> io::Result<RustCInfo> { | ||
22 | macro_rules! err { | 23 | macro_rules! err { |
23 | ($e:literal) => { | 24 | ($e:literal) => { |
24 | io::Error::new(io::ErrorKind::InvalidData, $e) | 25 | io::Error::new(io::ErrorKind::InvalidData, $e) |
diff --git a/crates/proc_macro_srv/src/tests/mod.rs b/crates/proc_macro_srv/src/tests/mod.rs index fd54f8dfd..b4ab4c077 100644 --- a/crates/proc_macro_srv/src/tests/mod.rs +++ b/crates/proc_macro_srv/src/tests/mod.rs | |||
@@ -56,3 +56,10 @@ DummyTrait [CustomDerive]"#, | |||
56 | &res | 56 | &res |
57 | ); | 57 | ); |
58 | } | 58 | } |
59 | |||
60 | #[test] | ||
61 | fn test_version_check() { | ||
62 | let path = fixtures::dylib_path("proc_macro_test", "0.0.0"); | ||
63 | let info = proc_macro_api::read_dylib_info(&path).unwrap(); | ||
64 | assert!(info.version.1 >= 50); | ||
65 | } | ||
diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs index 0484c3af4..f15381f0f 100644 --- a/crates/proc_macro_srv/src/tests/utils.rs +++ b/crates/proc_macro_srv/src/tests/utils.rs | |||
@@ -6,7 +6,7 @@ use proc_macro_api::ListMacrosTask; | |||
6 | use std::str::FromStr; | 6 | use std::str::FromStr; |
7 | use test_utils::assert_eq_text; | 7 | use test_utils::assert_eq_text; |
8 | 8 | ||
9 | mod fixtures { | 9 | pub mod fixtures { |
10 | use cargo_metadata::Message; | 10 | use cargo_metadata::Message; |
11 | use std::path::PathBuf; | 11 | use std::path::PathBuf; |
12 | use std::process::Command; | 12 | use std::process::Command; |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 8af7871ac..8f541976e 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -172,7 +172,7 @@ config_data! { | |||
172 | notifications_cargoTomlNotFound: bool = "true", | 172 | notifications_cargoTomlNotFound: bool = "true", |
173 | 173 | ||
174 | /// Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`. | 174 | /// Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`. |
175 | procMacro_enable: bool = "false", | 175 | procMacro_enable: bool = "true", |
176 | /// Internal config, path to proc-macro server executable (typically, | 176 | /// Internal config, path to proc-macro server executable (typically, |
177 | /// this is rust-analyzer itself, but we override this in tests). | 177 | /// this is rust-analyzer itself, but we override this in tests). |
178 | procMacro_server: Option<PathBuf> = "null", | 178 | procMacro_server: Option<PathBuf> = "null", |
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index 042ba2d54..c2521289c 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc | |||
@@ -276,7 +276,7 @@ Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. | |||
276 | -- | 276 | -- |
277 | Whether to show `can't find Cargo.toml` error message. | 277 | Whether to show `can't find Cargo.toml` error message. |
278 | -- | 278 | -- |
279 | [[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `false`):: | 279 | [[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `true`):: |
280 | + | 280 | + |
281 | -- | 281 | -- |
282 | Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`. | 282 | Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`. |
diff --git a/editors/code/package.json b/editors/code/package.json index 923e9b35a..a2ed9b2d5 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -690,7 +690,7 @@ | |||
690 | }, | 690 | }, |
691 | "rust-analyzer.procMacro.enable": { | 691 | "rust-analyzer.procMacro.enable": { |
692 | "markdownDescription": "Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.", | 692 | "markdownDescription": "Enable support for procedural macros, implies `#rust-analyzer.cargo.runBuildScripts#`.", |
693 | "default": false, | 693 | "default": true, |
694 | "type": "boolean" | 694 | "type": "boolean" |
695 | }, | 695 | }, |
696 | "rust-analyzer.procMacro.server": { | 696 | "rust-analyzer.procMacro.server": { |