aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r--crates/ra_analysis/src/completion/complete_path.rs12
-rw-r--r--crates/ra_analysis/src/completion/completion_context.rs4
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs26
3 files changed, 32 insertions, 10 deletions
diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs
index 99fe9aa94..4723a65a6 100644
--- a/crates/ra_analysis/src/completion/complete_path.rs
+++ b/crates/ra_analysis/src/completion/complete_path.rs
@@ -113,4 +113,16 @@ mod tests {
113 "Foo;Bar", 113 "Foo;Bar",
114 ); 114 );
115 } 115 }
116
117 #[test]
118 fn dont_render_function_parens_in_use_item() {
119 check_reference_completion(
120 "
121 //- /lib.rs
122 mod m { pub fn foo() {} }
123 use crate::m::f<|>;
124 ",
125 "foo",
126 )
127 }
116} 128}
diff --git a/crates/ra_analysis/src/completion/completion_context.rs b/crates/ra_analysis/src/completion/completion_context.rs
index 71bf7fd32..949b8135e 100644
--- a/crates/ra_analysis/src/completion/completion_context.rs
+++ b/crates/ra_analysis/src/completion/completion_context.rs
@@ -24,6 +24,7 @@ pub(super) struct CompletionContext<'a> {
24 pub(super) module: Option<hir::Module>, 24 pub(super) module: Option<hir::Module>,
25 pub(super) function: Option<hir::Function>, 25 pub(super) function: Option<hir::Function>,
26 pub(super) function_syntax: Option<ast::FnDef<'a>>, 26 pub(super) function_syntax: Option<ast::FnDef<'a>>,
27 pub(super) use_item_syntax: Option<ast::UseItem<'a>>,
27 pub(super) is_param: bool, 28 pub(super) is_param: bool,
28 /// A single-indent path, like `foo`. 29 /// A single-indent path, like `foo`.
29 pub(super) is_trivial_path: bool, 30 pub(super) is_trivial_path: bool,
@@ -55,6 +56,7 @@ impl<'a> CompletionContext<'a> {
55 module, 56 module,
56 function: None, 57 function: None,
57 function_syntax: None, 58 function_syntax: None,
59 use_item_syntax: None,
58 is_param: false, 60 is_param: false,
59 is_trivial_path: false, 61 is_trivial_path: false,
60 path_prefix: None, 62 path_prefix: None,
@@ -114,6 +116,8 @@ impl<'a> CompletionContext<'a> {
114 _ => (), 116 _ => (),
115 } 117 }
116 118
119 self.use_item_syntax = self.leaf.ancestors().find_map(ast::UseItem::cast);
120
117 self.function_syntax = self 121 self.function_syntax = self
118 .leaf 122 .leaf
119 .ancestors() 123 .ancestors()
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs
index a3d947e5b..cd4d529f9 100644
--- a/crates/ra_analysis/src/completion/completion_item.rs
+++ b/crates/ra_analysis/src/completion/completion_item.rs
@@ -140,21 +140,27 @@ impl Builder {
140 PerNs { 140 PerNs {
141 values: Some(hir::Def::Function(function)), 141 values: Some(hir::Def::Function(function)),
142 .. 142 ..
143 } => { 143 } => return self.from_function(ctx, function),
144 if let Some(sig_info) = function.signature_info(ctx.db) {
145 if sig_info.params.is_empty() {
146 self.snippet = Some(format!("{}()$0", self.label));
147 } else {
148 self.snippet = Some(format!("{}($0)", self.label));
149 }
150 }
151 CompletionItemKind::Function
152 }
153 _ => return self, 144 _ => return self,
154 }; 145 };
155 self.kind = Some(kind); 146 self.kind = Some(kind);
156 self 147 self
157 } 148 }
149
150 fn from_function(mut self, ctx: &CompletionContext, function: hir::Function) -> Builder {
151 // If not an import, add parenthesis automatically.
152 if ctx.use_item_syntax.is_none() {
153 if let Some(sig_info) = function.signature_info(ctx.db) {
154 if sig_info.params.is_empty() {
155 self.snippet = Some(format!("{}()$0", self.label));
156 } else {
157 self.snippet = Some(format!("{}($0)", self.label));
158 }
159 }
160 }
161 self.kind = Some(CompletionItemKind::Function);
162 self
163 }
158} 164}
159 165
160impl Into<CompletionItem> for Builder { 166impl Into<CompletionItem> for Builder {