aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2018-12-24 19:32:39 +0000
committerFlorian Diebold <[email protected]>2018-12-25 14:16:42 +0000
commit4ff161852016c6c15954d6f30bd637834a2b2b68 (patch)
tree7ea2d34a8f58f5a242481e6d6294bef22546fcaf /crates/ra_analysis/src
parentb5b68f2094d49cacde6d7f0c49f521a0b25f34bd (diff)
Do name resolution by namespace (types/values)
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/completion/complete_path.rs2
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs35
-rw-r--r--crates/ra_analysis/src/db.rs4
3 files changed, 28 insertions, 13 deletions
diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs
index ad4d68a33..8c00be499 100644
--- a/crates/ra_analysis/src/completion/complete_path.rs
+++ b/crates/ra_analysis/src/completion/complete_path.rs
@@ -8,7 +8,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C
8 (Some(path), Some(module)) => (path.clone(), module), 8 (Some(path), Some(module)) => (path.clone(), module),
9 _ => return Ok(()), 9 _ => return Ok(()),
10 }; 10 };
11 let def_id = match module.resolve_path(ctx.db, path)? { 11 let def_id = match module.resolve_path(ctx.db, path)?.take_types() {
12 Some(it) => it, 12 Some(it) => it,
13 None => return Ok(()), 13 None => return Ok(()),
14 }; 14 };
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}
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index 7043a0f4d..677745d57 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -95,8 +95,8 @@ salsa::database_storage! {
95 fn submodules() for hir::db::SubmodulesQuery; 95 fn submodules() for hir::db::SubmodulesQuery;
96 fn infer() for hir::db::InferQuery; 96 fn infer() for hir::db::InferQuery;
97 fn type_for_def() for hir::db::TypeForDefQuery; 97 fn type_for_def() for hir::db::TypeForDefQuery;
98 fn struct_data() for db::StructDataQuery; 98 fn struct_data() for hir::db::StructDataQuery;
99 fn enum_data() for db::EnumDataQuery; 99 fn enum_data() for hir::db::EnumDataQuery;
100 } 100 }
101 } 101 }
102} 102}