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.rs36
1 files changed, 26 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..c9f9f495d 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,7 +27,10 @@ pub enum CompletionItemKind {
25 Keyword, 27 Keyword,
26 Module, 28 Module,
27 Function, 29 Function,
30 Struct,
31 Enum,
28 Binding, 32 Binding,
33 Field,
29} 34}
30 35
31#[derive(Debug, PartialEq, Eq)] 36#[derive(Debug, PartialEq, Eq)]
@@ -117,16 +122,27 @@ impl Builder {
117 db: &db::RootDatabase, 122 db: &db::RootDatabase,
118 resolution: &hir::Resolution, 123 resolution: &hir::Resolution,
119 ) -> Builder { 124 ) -> Builder {
120 if let Some(def_id) = resolution.def_id { 125 let resolved = resolution.def_id.and_then(|d| d.resolve(db).ok());
121 if let Ok(def) = def_id.resolve(db) { 126 let kind = match resolved {
122 let kind = match def { 127 PerNs {
123 hir::Def::Module(..) => CompletionItemKind::Module, 128 types: Some(hir::Def::Module(..)),
124 hir::Def::Function(..) => CompletionItemKind::Function, 129 ..
125 _ => return self, 130 } => CompletionItemKind::Module,
126 }; 131 PerNs {
127 self.kind = Some(kind); 132 types: Some(hir::Def::Struct(..)),
128 } 133 ..
129 } 134 } => CompletionItemKind::Struct,
135 PerNs {
136 types: Some(hir::Def::Enum(..)),
137 ..
138 } => CompletionItemKind::Enum,
139 PerNs {
140 values: Some(hir::Def::Function(..)),
141 ..
142 } => CompletionItemKind::Function,
143 _ => return self,
144 };
145 self.kind = Some(kind);
130 self 146 self
131 } 147 }
132} 148}