diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/presentation.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index bc2cb4a0f..232ec80cd 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | //! This modules takes care of rendering various defenitions as completion items. | 1 | //! This modules takes care of rendering various defenitions as completion items. |
2 | use join_to_string::join; | 2 | use join_to_string::join; |
3 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
4 | use hir::Docs; | 4 | use hir::{Docs, PerNs, Resolution}; |
5 | use ra_syntax::ast::NameOwner; | ||
5 | 6 | ||
6 | use crate::completion::{ | 7 | use crate::completion::{ |
7 | Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, | 8 | Completions, CompletionKind, CompletionItemKind, CompletionContext, CompletionItem, |
@@ -33,6 +34,17 @@ impl Completions { | |||
33 | .add_to(self); | 34 | .add_to(self); |
34 | } | 35 | } |
35 | 36 | ||
37 | pub(crate) fn add_resolution( | ||
38 | &mut self, | ||
39 | ctx: &CompletionContext, | ||
40 | local_name: String, | ||
41 | res: &PerNs<Resolution>, | ||
42 | ) { | ||
43 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), local_name) | ||
44 | .from_resolution(ctx, res) | ||
45 | .add_to(self); | ||
46 | } | ||
47 | |||
36 | pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) { | 48 | pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) { |
37 | let sig = func.signature(ctx.db); | 49 | let sig = func.signature(ctx.db); |
38 | 50 | ||
@@ -62,6 +74,28 @@ impl Completions { | |||
62 | self.add(builder) | 74 | self.add(builder) |
63 | } | 75 | } |
64 | 76 | ||
77 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { | ||
78 | let (_file_id, cosnt_def) = constant.source(ctx.db); | ||
79 | let name = match cosnt_def.name() { | ||
80 | Some(name) => name, | ||
81 | _ => return, | ||
82 | }; | ||
83 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) | ||
84 | .from_const(ctx, constant) | ||
85 | .add_to(self); | ||
86 | } | ||
87 | |||
88 | pub(crate) fn add_type(&mut self, ctx: &CompletionContext, type_alias: hir::Type) { | ||
89 | let (_file_id, type_def) = type_alias.source(ctx.db); | ||
90 | let name = match type_def.name() { | ||
91 | Some(name) => name, | ||
92 | _ => return, | ||
93 | }; | ||
94 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) | ||
95 | .from_type(ctx, type_alias) | ||
96 | .add_to(self); | ||
97 | } | ||
98 | |||
65 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { | 99 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { |
66 | let name = match variant.name(ctx.db) { | 100 | let name = match variant.name(ctx.db) { |
67 | Some(it) => it, | 101 | Some(it) => it, |