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.rs35
1 files changed, 25 insertions, 10 deletions
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs
index 911f08468..6d466c8bd 100644
--- a/crates/ra_analysis/src/completion/completion_item.rs
+++ b/crates/ra_analysis/src/completion/completion_item.rs
@@ -1,5 +1,7 @@
1use crate::db; 1use crate::db;
2 2
3use hir::PerNs;
4
3/// `CompletionItem` describes a single completion variant in the editor pop-up. 5/// `CompletionItem` describes a single completion variant in the editor pop-up.
4/// It is basically a POD with various properties. To construct a 6/// It is basically a POD with various properties. To construct a
5/// `CompletionItem`, use `new` method and the `Builder` struct. 7/// `CompletionItem`, use `new` method and the `Builder` struct.
@@ -25,6 +27,8 @@ pub enum CompletionItemKind {
25 Keyword, 27 Keyword,
26 Module, 28 Module,
27 Function, 29 Function,
30 Struct,
31 Enum,
28 Binding, 32 Binding,
29} 33}
30 34
@@ -117,16 +121,27 @@ impl Builder {
117 db: &db::RootDatabase, 121 db: &db::RootDatabase,
118 resolution: &hir::Resolution, 122 resolution: &hir::Resolution,
119 ) -> Builder { 123 ) -> Builder {
120 if let Some(def_id) = resolution.def_id { 124 let resolved = resolution.def_id.and_then(|d| d.resolve(db).ok());
121 if let Ok(def) = def_id.resolve(db) { 125 let kind = match resolved {
122 let kind = match def { 126 PerNs {
123 hir::Def::Module(..) => CompletionItemKind::Module, 127 types: Some(hir::Def::Module(..)),
124 hir::Def::Function(..) => CompletionItemKind::Function, 128 ..
125 _ => return self, 129 } => CompletionItemKind::Module,
126 }; 130 PerNs {
127 self.kind = Some(kind); 131 types: Some(hir::Def::Struct(..)),
128 } 132 ..
129 } 133 } => CompletionItemKind::Struct,
134 PerNs {
135 types: Some(hir::Def::Enum(..)),
136 ..
137 } => CompletionItemKind::Enum,
138 PerNs {
139 values: Some(hir::Def::Function(..)),
140 ..
141 } => CompletionItemKind::Function,
142 _ => return self,
143 };
144 self.kind = Some(kind);
130 self 145 self
131 } 146 }
132} 147}