From 97cb463c9be3c21931d0e284603238ce3cb02b2a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 02:20:14 +0300 Subject: moar icons --- crates/ra_analysis/src/completion/complete_path.rs | 6 ++++-- crates/ra_analysis/src/completion/complete_scope.rs | 6 ++++-- .../ra_analysis/src/completion/completion_item.rs | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) (limited to 'crates/ra_analysis/src') 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 _ => return Ok(()), }; let module_scope = target_module.scope(ctx.db)?; - module_scope.entries().for_each(|(name, _res)| { - CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) + module_scope.entries().for_each(|(name, res)| { + CompletionItem::new(CompletionKind::Reference, name.to_string()) + .from_resolution(ctx.db, res) + .add_to(acc) }); Ok(()) } 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) -> } } }) - .for_each(|(name, _res)| { - CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) + .for_each(|(name, res)| { + CompletionItem::new(CompletionKind::Reference, name.to_string()) + .from_resolution(ctx.db, res) + .add_to(acc) }); } 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 @@ +use crate::db; + /// `CompletionItem` describes a single completion variant in the editor pop-up. /// It is basically a POD with various properties. To construct a /// `CompletionItem`, use `new` method and the `Builder` struct. @@ -21,6 +23,8 @@ pub enum InsertText { pub enum CompletionItemKind { Snippet, Keyword, + Module, + Function, } #[derive(Debug, PartialEq, Eq)] @@ -107,6 +111,23 @@ impl Builder { self.kind = Some(kind); self } + pub(crate) fn from_resolution( + mut self, + db: &db::RootDatabase, + resolution: &hir::Resolution, + ) -> Builder { + if let Some(def_id) = resolution.def_id { + if let Ok(def) = def_id.resolve(db) { + let kind = match def { + hir::Def::Module(..) => CompletionItemKind::Module, + hir::Def::Function(..) => CompletionItemKind::Function, + _ => return self, + }; + self.kind = Some(kind); + } + } + self + } } impl Into for Builder { -- cgit v1.2.3