diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-03 23:12:27 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-03 23:12:27 +0000 |
commit | ce69561be32421868e0f1ddb537f6f0a596d5610 (patch) | |
tree | 8b1ebffb9a0cf053f6228ba9a878b32bbbba24b4 /crates/ra_ide | |
parent | 5abc45982b5558d4c5f8753cb531a4a0858faa0f (diff) | |
parent | e55fc286fc60a32ff0b6d9e0dd56719e685af180 (diff) |
Merge #3430
3430: Fix completion snippet for reexported functions r=matklad a=flodiebold
Fixes #3356.
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/completion/complete_path.rs | 51 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 7 |
2 files changed, 54 insertions, 4 deletions
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index c626e90cc..1a9699466 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs | |||
@@ -784,4 +784,55 @@ mod tests { | |||
784 | "### | 784 | "### |
785 | ); | 785 | ); |
786 | } | 786 | } |
787 | |||
788 | #[test] | ||
789 | fn completes_reexported_items_under_correct_name() { | ||
790 | assert_debug_snapshot!( | ||
791 | do_reference_completion( | ||
792 | r" | ||
793 | fn foo() { | ||
794 | self::m::<|> | ||
795 | } | ||
796 | |||
797 | mod m { | ||
798 | pub use super::p::wrong_fn as right_fn; | ||
799 | pub use super::p::WRONG_CONST as RIGHT_CONST; | ||
800 | pub use super::p::WrongType as RightType; | ||
801 | } | ||
802 | mod p { | ||
803 | fn wrong_fn() {} | ||
804 | const WRONG_CONST: u32 = 1; | ||
805 | struct WrongType {}; | ||
806 | } | ||
807 | " | ||
808 | ), | ||
809 | @r###" | ||
810 | [ | ||
811 | CompletionItem { | ||
812 | label: "RIGHT_CONST", | ||
813 | source_range: [57; 57), | ||
814 | delete: [57; 57), | ||
815 | insert: "RIGHT_CONST", | ||
816 | kind: Const, | ||
817 | }, | ||
818 | CompletionItem { | ||
819 | label: "RightType", | ||
820 | source_range: [57; 57), | ||
821 | delete: [57; 57), | ||
822 | insert: "RightType", | ||
823 | kind: Struct, | ||
824 | }, | ||
825 | CompletionItem { | ||
826 | label: "right_fn()", | ||
827 | source_range: [57; 57), | ||
828 | delete: [57; 57), | ||
829 | insert: "right_fn()$0", | ||
830 | kind: Function, | ||
831 | lookup: "right_fn", | ||
832 | detail: "fn wrong_fn()", | ||
833 | }, | ||
834 | ] | ||
835 | "### | ||
836 | ); | ||
837 | } | ||
787 | } | 838 | } |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index a524987fd..ae9344a44 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -193,11 +193,10 @@ impl Completions { | |||
193 | name: Option<String>, | 193 | name: Option<String>, |
194 | func: hir::Function, | 194 | func: hir::Function, |
195 | ) { | 195 | ) { |
196 | let func_name = func.name(ctx.db); | ||
197 | let has_self_param = func.has_self_param(ctx.db); | 196 | let has_self_param = func.has_self_param(ctx.db); |
198 | let params = func.params(ctx.db); | 197 | let params = func.params(ctx.db); |
199 | 198 | ||
200 | let name = name.unwrap_or_else(|| func_name.to_string()); | 199 | let name = name.unwrap_or_else(|| func.name(ctx.db).to_string()); |
201 | let ast_node = func.source(ctx.db).value; | 200 | let ast_node = func.source(ctx.db).value; |
202 | let detail = function_label(&ast_node); | 201 | let detail = function_label(&ast_node); |
203 | 202 | ||
@@ -219,9 +218,9 @@ impl Completions { | |||
219 | { | 218 | { |
220 | tested_by!(inserts_parens_for_function_calls); | 219 | tested_by!(inserts_parens_for_function_calls); |
221 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { | 220 | let (snippet, label) = if params.is_empty() || has_self_param && params.len() == 1 { |
222 | (format!("{}()$0", func_name), format!("{}()", name)) | 221 | (format!("{}()$0", name), format!("{}()", name)) |
223 | } else { | 222 | } else { |
224 | (format!("{}($0)", func_name), format!("{}(…)", name)) | 223 | (format!("{}($0)", name), format!("{}(…)", name)) |
225 | }; | 224 | }; |
226 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); | 225 | builder = builder.lookup_by(name).label(label).insert_snippet(snippet); |
227 | } | 226 | } |