diff options
-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 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/module.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/module/nameres.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/conv.rs | 2 |
7 files changed, 34 insertions, 7 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 { |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 5941a9ea3..f56214b47 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -39,7 +39,7 @@ use crate::{ | |||
39 | pub use self::{ | 39 | pub use self::{ |
40 | path::{Path, PathKind}, | 40 | path::{Path, PathKind}, |
41 | krate::Crate, | 41 | krate::Crate, |
42 | module::{Module, ModuleId, Problem, nameres::ItemMap}, | 42 | module::{Module, ModuleId, Problem, nameres::ItemMap, ModuleScope, Resolution}, |
43 | function::{Function, FnScopes}, | 43 | function::{Function, FnScopes}, |
44 | }; | 44 | }; |
45 | 45 | ||
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs index d5866f6ef..cd31e8cfe 100644 --- a/crates/ra_hir/src/module.rs +++ b/crates/ra_hir/src/module.rs | |||
@@ -16,7 +16,7 @@ use crate::{ | |||
16 | arena::{Arena, Id}, | 16 | arena::{Arena, Id}, |
17 | }; | 17 | }; |
18 | 18 | ||
19 | pub use self::nameres::ModuleScope; | 19 | pub use self::nameres::{ModuleScope, Resolution}; |
20 | 20 | ||
21 | /// `Module` is API entry point to get all the information | 21 | /// `Module` is API entry point to get all the information |
22 | /// about a particular module. | 22 | /// about a particular module. |
diff --git a/crates/ra_hir/src/module/nameres.rs b/crates/ra_hir/src/module/nameres.rs index f44abc730..39e891cda 100644 --- a/crates/ra_hir/src/module/nameres.rs +++ b/crates/ra_hir/src/module/nameres.rs | |||
@@ -49,7 +49,7 @@ pub struct ModuleScope { | |||
49 | } | 49 | } |
50 | 50 | ||
51 | impl ModuleScope { | 51 | impl ModuleScope { |
52 | pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a SmolStr, &Resolution)> + 'a { | 52 | pub fn entries<'a>(&'a self) -> impl Iterator<Item = (&'a SmolStr, &'a Resolution)> + 'a { |
53 | self.items.iter() | 53 | self.items.iter() |
54 | } | 54 | } |
55 | pub fn get(&self, name: &SmolStr) -> Option<&Resolution> { | 55 | pub fn get(&self, name: &SmolStr) -> Option<&Resolution> { |
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 6f770ec69..9320f147a 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs | |||
@@ -53,6 +53,8 @@ impl Conv for CompletionItemKind { | |||
53 | match self { | 53 | match self { |
54 | CompletionItemKind::Keyword => Keyword, | 54 | CompletionItemKind::Keyword => Keyword, |
55 | CompletionItemKind::Snippet => Snippet, | 55 | CompletionItemKind::Snippet => Snippet, |
56 | CompletionItemKind::Module => Module, | ||
57 | CompletionItemKind::Function => Function, | ||
56 | } | 58 | } |
57 | } | 59 | } |
58 | } | 60 | } |