diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/completion_item.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_item.rs | 73 |
1 files changed, 1 insertions, 72 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 91e32b3c8..cb880d92c 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs | |||
@@ -1,13 +1,11 @@ | |||
1 | use std::fmt; | 1 | use std::fmt; |
2 | 2 | ||
3 | use hir::{Docs, Documentation, PerNs, Resolution}; | 3 | use hir::{Docs, Documentation}; |
4 | use ra_syntax::TextRange; | 4 | use ra_syntax::TextRange; |
5 | use ra_text_edit::{ TextEditBuilder, TextEdit}; | 5 | use ra_text_edit::{ TextEditBuilder, TextEdit}; |
6 | use test_utils::tested_by; | ||
7 | 6 | ||
8 | use crate::completion::{ | 7 | use crate::completion::{ |
9 | completion_context::CompletionContext, | 8 | completion_context::CompletionContext, |
10 | function_label, | ||
11 | const_label, | 9 | const_label, |
12 | type_label | 10 | type_label |
13 | }; | 11 | }; |
@@ -255,70 +253,6 @@ impl Builder { | |||
255 | self.documentation = docs.map(Into::into); | 253 | self.documentation = docs.map(Into::into); |
256 | self | 254 | self |
257 | } | 255 | } |
258 | pub(super) fn from_resolution( | ||
259 | mut self, | ||
260 | ctx: &CompletionContext, | ||
261 | resolution: &PerNs<Resolution>, | ||
262 | ) -> Builder { | ||
263 | use hir::ModuleDef::*; | ||
264 | |||
265 | let def = resolution.as_ref().take_types().or_else(|| resolution.as_ref().take_values()); | ||
266 | let def = match def { | ||
267 | None => return self, | ||
268 | Some(it) => it, | ||
269 | }; | ||
270 | let (kind, docs) = match def { | ||
271 | Resolution::Def(Module(it)) => (CompletionItemKind::Module, it.docs(ctx.db)), | ||
272 | Resolution::Def(Function(func)) => return self.from_function(ctx, *func), | ||
273 | Resolution::Def(Struct(it)) => (CompletionItemKind::Struct, it.docs(ctx.db)), | ||
274 | Resolution::Def(Enum(it)) => (CompletionItemKind::Enum, it.docs(ctx.db)), | ||
275 | Resolution::Def(EnumVariant(it)) => (CompletionItemKind::EnumVariant, it.docs(ctx.db)), | ||
276 | Resolution::Def(Const(it)) => (CompletionItemKind::Const, it.docs(ctx.db)), | ||
277 | Resolution::Def(Static(it)) => (CompletionItemKind::Static, it.docs(ctx.db)), | ||
278 | Resolution::Def(Trait(it)) => (CompletionItemKind::Trait, it.docs(ctx.db)), | ||
279 | Resolution::Def(Type(it)) => (CompletionItemKind::TypeAlias, it.docs(ctx.db)), | ||
280 | Resolution::GenericParam(..) => (CompletionItemKind::TypeParam, None), | ||
281 | Resolution::LocalBinding(..) => (CompletionItemKind::Binding, None), | ||
282 | Resolution::SelfType(..) => ( | ||
283 | CompletionItemKind::TypeParam, // (does this need its own kind?) | ||
284 | None, | ||
285 | ), | ||
286 | }; | ||
287 | self.kind = Some(kind); | ||
288 | self.documentation = docs; | ||
289 | |||
290 | self | ||
291 | } | ||
292 | |||
293 | pub(super) fn from_function( | ||
294 | mut self, | ||
295 | ctx: &CompletionContext, | ||
296 | function: hir::Function, | ||
297 | ) -> Builder { | ||
298 | // If not an import, add parenthesis automatically. | ||
299 | if ctx.use_item_syntax.is_none() && !ctx.is_call { | ||
300 | tested_by!(inserts_parens_for_function_calls); | ||
301 | let sig = function.signature(ctx.db); | ||
302 | if sig.params().is_empty() || sig.has_self_param() && sig.params().len() == 1 { | ||
303 | self.insert_text = Some(format!("{}()$0", self.label)); | ||
304 | } else { | ||
305 | self.insert_text = Some(format!("{}($0)", self.label)); | ||
306 | } | ||
307 | self.insert_text_format = InsertTextFormat::Snippet; | ||
308 | } | ||
309 | |||
310 | if let Some(docs) = function.docs(ctx.db) { | ||
311 | self.documentation = Some(docs); | ||
312 | } | ||
313 | |||
314 | if let Some(label) = function_item_label(ctx, function) { | ||
315 | self.detail = Some(label); | ||
316 | } | ||
317 | |||
318 | self.kind = Some(CompletionItemKind::Function); | ||
319 | self | ||
320 | } | ||
321 | |||
322 | pub(super) fn from_const(mut self, ctx: &CompletionContext, ct: hir::Const) -> Builder { | 256 | pub(super) fn from_const(mut self, ctx: &CompletionContext, ct: hir::Const) -> Builder { |
323 | if let Some(docs) = ct.docs(ctx.db) { | 257 | if let Some(docs) = ct.docs(ctx.db) { |
324 | self.documentation = Some(docs); | 258 | self.documentation = Some(docs); |
@@ -373,11 +307,6 @@ impl Into<Vec<CompletionItem>> for Completions { | |||
373 | } | 307 | } |
374 | } | 308 | } |
375 | 309 | ||
376 | fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> { | ||
377 | let node = function.source(ctx.db).1; | ||
378 | function_label(&node) | ||
379 | } | ||
380 | |||
381 | fn const_item_label(ctx: &CompletionContext, ct: hir::Const) -> String { | 310 | fn const_item_label(ctx: &CompletionContext, ct: hir::Const) -> String { |
382 | let node = ct.source(ctx.db).1; | 311 | let node = ct.source(ctx.db).1; |
383 | const_label(&node) | 312 | const_label(&node) |