aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/completion_item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion/completion_item.rs')
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs
index 1d294c553..cd4d529f9 100644
--- a/crates/ra_analysis/src/completion/completion_item.rs
+++ b/crates/ra_analysis/src/completion/completion_item.rs
@@ -1,7 +1,7 @@
1use crate::db;
2
3use hir::PerNs; 1use hir::PerNs;
4 2
3use crate::completion::CompletionContext;
4
5/// `CompletionItem` describes a single completion variant in the editor pop-up. 5/// `CompletionItem` describes a single completion variant in the editor pop-up.
6/// It is basically a POD with various properties. To construct a 6/// It is basically a POD with various properties. To construct a
7/// `CompletionItem`, use `new` method and the `Builder` struct. 7/// `CompletionItem`, use `new` method and the `Builder` struct.
@@ -118,12 +118,12 @@ impl Builder {
118 self.kind = Some(kind); 118 self.kind = Some(kind);
119 self 119 self
120 } 120 }
121 pub(crate) fn from_resolution( 121 pub(super) fn from_resolution(
122 mut self, 122 mut self,
123 db: &db::RootDatabase, 123 ctx: &CompletionContext,
124 resolution: &hir::Resolution, 124 resolution: &hir::Resolution,
125 ) -> Builder { 125 ) -> Builder {
126 let resolved = resolution.def_id.and_then(|d| d.resolve(db).ok()); 126 let resolved = resolution.def_id.and_then(|d| d.resolve(ctx.db).ok());
127 let kind = match resolved { 127 let kind = match resolved {
128 PerNs { 128 PerNs {
129 types: Some(hir::Def::Module(..)), 129 types: Some(hir::Def::Module(..)),
@@ -138,14 +138,29 @@ impl Builder {
138 .. 138 ..
139 } => CompletionItemKind::Enum, 139 } => CompletionItemKind::Enum,
140 PerNs { 140 PerNs {
141 values: Some(hir::Def::Function(..)), 141 values: Some(hir::Def::Function(function)),
142 .. 142 ..
143 } => CompletionItemKind::Function, 143 } => return self.from_function(ctx, function),
144 _ => return self, 144 _ => return self,
145 }; 145 };
146 self.kind = Some(kind); 146 self.kind = Some(kind);
147 self 147 self
148 } 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 }
149} 164}
150 165
151impl Into<CompletionItem> for Builder { 166impl Into<CompletionItem> for Builder {