diff options
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_path.rs | 6 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/complete_scope.rs | 6 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/completion_item.rs | 21 |
3 files changed, 29 insertions, 4 deletions
diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs index 802f4abe4..ad4d68a33 100644 --- a/crates/ra_analysis/src/completion/complete_path.rs +++ b/crates/ra_analysis/src/completion/complete_path.rs | |||
@@ -17,8 +17,10 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C | |||
17 | _ => return Ok(()), | 17 | _ => return Ok(()), |
18 | }; | 18 | }; |
19 | let module_scope = target_module.scope(ctx.db)?; | 19 | let module_scope = target_module.scope(ctx.db)?; |
20 | module_scope.entries().for_each(|(name, _res)| { | 20 | module_scope.entries().for_each(|(name, res)| { |
21 | CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) | 21 | CompletionItem::new(CompletionKind::Reference, name.to_string()) |
22 | .from_resolution(ctx.db, res) | ||
23 | .add_to(acc) | ||
22 | }); | 24 | }); |
23 | Ok(()) | 25 | Ok(()) |
24 | } | 26 | } |
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index fb87be4b1..4f27ad9eb 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs | |||
@@ -29,8 +29,10 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
29 | } | 29 | } |
30 | } | 30 | } |
31 | }) | 31 | }) |
32 | .for_each(|(name, _res)| { | 32 | .for_each(|(name, res)| { |
33 | CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) | 33 | CompletionItem::new(CompletionKind::Reference, name.to_string()) |
34 | .from_resolution(ctx.db, res) | ||
35 | .add_to(acc) | ||
34 | }); | 36 | }); |
35 | } | 37 | } |
36 | 38 | ||
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 { |