aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/presentation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion/presentation.rs')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 97475fc0b..d0a43261f 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -129,6 +129,39 @@ impl Completions {
129 self.add_function_with_name(ctx, None, func) 129 self.add_function_with_name(ctx, None, func)
130 } 130 }
131 131
132 pub(crate) fn add_function_impl(&mut self, ctx: &CompletionContext, func: hir::Function) {
133 use crate::display::FunctionSignature;
134
135 let display = FunctionSignature::from_hir(ctx.db, func.clone());
136
137 let func_name = func.name(ctx.db);
138
139 let mut builder = CompletionItem::new(
140 CompletionKind::Reference,
141 ctx.source_range(),
142 format!("fn {}()", func_name.to_string()))
143 .set_documentation(func.docs(ctx.db));
144
145 let completion_kind = if func.has_self_param(ctx.db) {
146 CompletionItemKind::Method
147 } else {
148 CompletionItemKind::Function
149 };
150
151 let snippet = {
152 let mut s = format!("{}", display);
153 s.push_str(" { $0 }");
154 s
155 };
156
157 builder = builder
158 .insert_text(snippet)
159 .kind(completion_kind)
160 .lookup_by(func_name.to_string());
161
162 self.add(builder.build());
163 }
164
132 fn guess_macro_braces(&self, macro_name: &str, docs: &str) -> &'static str { 165 fn guess_macro_braces(&self, macro_name: &str, docs: &str) -> &'static str {
133 let mut votes = [0, 0, 0]; 166 let mut votes = [0, 0, 0];
134 for (idx, s) in docs.match_indices(&macro_name) { 167 for (idx, s) in docs.match_indices(&macro_name) {