diff options
Diffstat (limited to 'crates/ra_analysis/src/completion/completion_item.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/completion_item.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index 89fbe62d8..cbd42a44e 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use crate::db; | ||
2 | |||
1 | /// `CompletionItem` describes a single completion variant in the editor pop-up. | 3 | /// `CompletionItem` describes a single completion variant in the editor pop-up. |
2 | /// It is basically a POD with various properties. To construct a | 4 | /// It is basically a POD with various properties. To construct a |
3 | /// `CompletionItem`, use `new` method and the `Builder` struct. | 5 | /// `CompletionItem`, use `new` method and the `Builder` struct. |
@@ -21,6 +23,8 @@ pub enum InsertText { | |||
21 | pub enum CompletionItemKind { | 23 | pub enum CompletionItemKind { |
22 | Snippet, | 24 | Snippet, |
23 | Keyword, | 25 | Keyword, |
26 | Module, | ||
27 | Function, | ||
24 | } | 28 | } |
25 | 29 | ||
26 | #[derive(Debug, PartialEq, Eq)] | 30 | #[derive(Debug, PartialEq, Eq)] |
@@ -107,6 +111,23 @@ impl Builder { | |||
107 | self.kind = Some(kind); | 111 | self.kind = Some(kind); |
108 | self | 112 | self |
109 | } | 113 | } |
114 | pub(crate) fn from_resolution( | ||
115 | mut self, | ||
116 | db: &db::RootDatabase, | ||
117 | resolution: &hir::Resolution, | ||
118 | ) -> Builder { | ||
119 | if let Some(def_id) = resolution.def_id { | ||
120 | if let Ok(def) = def_id.resolve(db) { | ||
121 | let kind = match def { | ||
122 | hir::Def::Module(..) => CompletionItemKind::Module, | ||
123 | hir::Def::Function(..) => CompletionItemKind::Function, | ||
124 | _ => return self, | ||
125 | }; | ||
126 | self.kind = Some(kind); | ||
127 | } | ||
128 | } | ||
129 | self | ||
130 | } | ||
110 | } | 131 | } |
111 | 132 | ||
112 | impl Into<CompletionItem> for Builder { | 133 | impl Into<CompletionItem> for Builder { |