From ebb584ce669d04f109d5b21a08aca9d4e9acecc8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 01:14:15 +0300 Subject: rename completion kind --- crates/ra_analysis/src/completion/completion_item.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index d5d751759..30581c8a5 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs @@ -7,7 +7,7 @@ pub struct CompletionItem { lookup: Option, snippet: Option, /// Used only internally in test, to check only specific kind of completion. - kind: CompletionKind, + completion_kind: CompletionKind, } pub enum InsertText { @@ -34,7 +34,7 @@ impl CompletionItem { label, lookup: None, snippet: None, - kind: CompletionKind::Unspecified, + completion_kind: CompletionKind::Unspecified, } } /// What user sees in pop-up in the UI. @@ -65,7 +65,7 @@ pub(crate) struct Builder { label: String, lookup: Option, snippet: Option, - kind: CompletionKind, + completion_kind: CompletionKind, } impl Builder { @@ -78,7 +78,7 @@ impl Builder { label: self.label, lookup: self.lookup, snippet: self.snippet, - kind: self.kind, + completion_kind: self.completion_kind, } } pub(crate) fn lookup_by(mut self, lookup: impl Into) -> Builder { @@ -90,7 +90,7 @@ impl Builder { self } pub(crate) fn kind(mut self, kind: CompletionKind) -> Builder { - self.kind = kind; + self.completion_kind = kind; self } } @@ -154,7 +154,7 @@ impl Completions { fn debug_render(&self, kind: CompletionKind) -> String { let mut res = String::new(); for c in self.buf.iter() { - if c.kind == kind { + if c.completion_kind == kind { if let Some(lookup) = &c.lookup { res.push_str(lookup); res.push_str(&format!(" {:?}", c.label)); -- cgit v1.2.3 From 25dda42f3773b1d002a5809c0182c2adc6c47027 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 01:27:07 +0300 Subject: introduce ComletionItemKind --- .../ra_analysis/src/completion/complete_fn_param.rs | 3 +-- .../ra_analysis/src/completion/complete_keyword.rs | 5 +---- crates/ra_analysis/src/completion/complete_path.rs | 8 +++----- crates/ra_analysis/src/completion/complete_scope.rs | 14 +++----------- .../ra_analysis/src/completion/complete_snippet.rs | 12 ++++-------- crates/ra_analysis/src/completion/completion_item.rs | 20 ++++++++++++++++---- 6 files changed, 28 insertions(+), 34 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_fn_param.rs b/crates/ra_analysis/src/completion/complete_fn_param.rs index 6a6213e67..bb5fdfda0 100644 --- a/crates/ra_analysis/src/completion/complete_fn_param.rs +++ b/crates/ra_analysis/src/completion/complete_fn_param.rs @@ -34,9 +34,8 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) } }) .for_each(|(label, lookup)| { - CompletionItem::new(label) + CompletionItem::new(CompletionKind::Magic, label) .lookup_by(lookup) - .kind(CompletionKind::Magic) .add_to(acc) }); diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index dead15bb6..1e6d7008d 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs @@ -61,10 +61,7 @@ fn complete_return(fn_def: ast::FnDef, is_stmt: bool) -> Option } fn keyword(kw: &str, snippet: &str) -> CompletionItem { - CompletionItem::new(kw) - .kind(Keyword) - .snippet(snippet) - .build() + CompletionItem::new(Keyword, kw).snippet(snippet).build() } #[cfg(test)] diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs index 5fc24af72..692502bb2 100644 --- a/crates/ra_analysis/src/completion/complete_path.rs +++ b/crates/ra_analysis/src/completion/complete_path.rs @@ -17,11 +17,9 @@ 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(name.to_string()) - .kind(Reference) - .add_to(acc) - }); + module_scope + .entries() + .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).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 d07c0e46d..f39b98d62 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs @@ -29,11 +29,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> } } }) - .for_each(|(name, _res)| { - CompletionItem::new(name.to_string()) - .kind(Reference) - .add_to(acc) - }); + .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc)); } Ok(()) @@ -45,13 +41,9 @@ fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit) .scope_chain_for_offset(offset) .flat_map(|scope| scopes.entries(scope).iter()) .filter(|entry| shadowed.insert(entry.name())) - .for_each(|entry| { - CompletionItem::new(entry.name().to_string()) - .kind(Reference) - .add_to(acc) - }); + .for_each(|entry| CompletionItem::new(Reference, entry.name().to_string()).add_to(acc)); if scopes.self_param.is_some() { - CompletionItem::new("self").kind(Reference).add_to(acc); + CompletionItem::new(Reference, "self").add_to(acc); } } diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs index ccd68832b..f0ad45fec 100644 --- a/crates/ra_analysis/src/completion/complete_snippet.rs +++ b/crates/ra_analysis/src/completion/complete_snippet.rs @@ -4,13 +4,11 @@ pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) { return; } - CompletionItem::new("pd") + CompletionItem::new(Snippet, "pd") .snippet("eprintln!(\"$0 = {:?}\", $0);") - .kind(Snippet) .add_to(acc); - CompletionItem::new("ppd") + CompletionItem::new(Snippet, "ppd") .snippet("eprintln!(\"$0 = {:#?}\", $0);") - .kind(Snippet) .add_to(acc); } @@ -18,7 +16,7 @@ pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionConte if !ctx.is_new_item { return; } - CompletionItem::new("Test function") + CompletionItem::new(Snippet, "Test function") .lookup_by("tfn") .snippet( "\ @@ -27,11 +25,9 @@ fn ${1:feature}() { $0 }", ) - .kind(Snippet) .add_to(acc); - CompletionItem::new("pub(crate)") + CompletionItem::new(Snippet, "pub(crate)") .snippet("pub(crate) $0") - .kind(Snippet) .add_to(acc); } diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index 30581c8a5..423d5a48b 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs @@ -6,7 +6,9 @@ pub struct CompletionItem { label: String, lookup: Option, snippet: Option, - /// Used only internally in test, to check only specific kind of completion. + kind: Option, + /// Used only internally in tests, to check only specific kind of + /// completion. completion_kind: CompletionKind, } @@ -15,6 +17,12 @@ pub enum InsertText { Snippet { text: String }, } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum CompletionItemKind { + Snippet, + Keyword, +} + #[derive(Debug, PartialEq, Eq)] pub(crate) enum CompletionKind { /// Parser-based keyword completion. @@ -24,17 +32,16 @@ pub(crate) enum CompletionKind { /// "Secret sauce" completions. Magic, Snippet, - Unspecified, } impl CompletionItem { - pub(crate) fn new(label: impl Into) -> Builder { + pub(crate) fn new(completion_kind: CompletionKind, label: impl Into) -> Builder { let label = label.into(); Builder { label, lookup: None, snippet: None, - completion_kind: CompletionKind::Unspecified, + completion_kind, } } /// What user sees in pop-up in the UI. @@ -57,6 +64,10 @@ impl CompletionItem { Some(it) => InsertText::Snippet { text: it.clone() }, } } + + pub fn kind(&self) -> Option { + self.kind + } } /// A helper to make `CompletionItem`s. @@ -78,6 +89,7 @@ impl Builder { label: self.label, lookup: self.lookup, snippet: self.snippet, + kind: None, completion_kind: self.completion_kind, } } -- cgit v1.2.3 From 284e89406906b97eec8e0f91bce2955a5e94b880 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 01:34:22 +0300 Subject: cleanup --- .../ra_analysis/src/completion/complete_keyword.rs | 12 +++++---- crates/ra_analysis/src/completion/complete_path.rs | 8 +++--- .../ra_analysis/src/completion/complete_scope.rs | 12 ++++++--- .../ra_analysis/src/completion/complete_snippet.rs | 31 +++++++++++----------- 4 files changed, 34 insertions(+), 29 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index 1e6d7008d..2c7891920 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs @@ -5,7 +5,13 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNodeRef, }; -use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind::*}; +use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind}; + +fn keyword(kw: &str, snippet: &str) -> CompletionItem { + CompletionItem::new(CompletionKind::Keyword, kw) + .snippet(snippet) + .build() +} pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_trivial_path { @@ -60,10 +66,6 @@ fn complete_return(fn_def: ast::FnDef, is_stmt: bool) -> Option Some(keyword("return", snip)) } -fn keyword(kw: &str, snippet: &str) -> CompletionItem { - CompletionItem::new(Keyword, kw).snippet(snippet).build() -} - #[cfg(test)] mod tests { use crate::completion::{CompletionKind, check_completion}; diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs index 692502bb2..802f4abe4 100644 --- a/crates/ra_analysis/src/completion/complete_path.rs +++ b/crates/ra_analysis/src/completion/complete_path.rs @@ -1,6 +1,6 @@ use crate::{ Cancelable, - completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}, + completion::{CompletionItem, Completions, CompletionKind, CompletionContext}, }; pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { @@ -17,9 +17,9 @@ 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(Reference, name.to_string()).add_to(acc)); + module_scope.entries().for_each(|(name, _res)| { + CompletionItem::new(CompletionKind::Reference, name.to_string()).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 f39b98d62..fb87be4b1 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs @@ -3,7 +3,7 @@ use ra_syntax::TextUnit; use crate::{ Cancelable, - completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}, + completion::{CompletionItem, Completions, CompletionKind, CompletionContext}, }; pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { @@ -29,7 +29,9 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> } } }) - .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc)); + .for_each(|(name, _res)| { + CompletionItem::new(CompletionKind::Reference, name.to_string()).add_to(acc) + }); } Ok(()) @@ -41,9 +43,11 @@ fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit) .scope_chain_for_offset(offset) .flat_map(|scope| scopes.entries(scope).iter()) .filter(|entry| shadowed.insert(entry.name())) - .for_each(|entry| CompletionItem::new(Reference, entry.name().to_string()).add_to(acc)); + .for_each(|entry| { + CompletionItem::new(CompletionKind::Reference, entry.name().to_string()).add_to(acc) + }); if scopes.self_param.is_some() { - CompletionItem::new(Reference, "self").add_to(acc); + CompletionItem::new(CompletionKind::Reference, "self").add_to(acc); } } diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs index f0ad45fec..1feb332b9 100644 --- a/crates/ra_analysis/src/completion/complete_snippet.rs +++ b/crates/ra_analysis/src/completion/complete_snippet.rs @@ -1,34 +1,33 @@ -use crate::completion::{CompletionItem, Completions, CompletionKind::*, CompletionContext}; +use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext, completion_item::Builder}; + +fn snippet(label: &str, snippet: &str) -> Builder { + CompletionItem::new(CompletionKind::Snippet, label).snippet(snippet) +} pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) { return; } - CompletionItem::new(Snippet, "pd") - .snippet("eprintln!(\"$0 = {:?}\", $0);") - .add_to(acc); - CompletionItem::new(Snippet, "ppd") - .snippet("eprintln!(\"$0 = {:#?}\", $0);") - .add_to(acc); + snippet("pd", "eprintln!(\"$0 = {:?}\", $0);").add_to(acc); + snippet("ppd", "eprintln!(\"$0 = {:#?}\", $0);").add_to(acc); } pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_new_item { return; } - CompletionItem::new(Snippet, "Test function") - .lookup_by("tfn") - .snippet( - "\ + snippet( + "Test function", + "\ #[test] fn ${1:feature}() { $0 }", - ) - .add_to(acc); - CompletionItem::new(Snippet, "pub(crate)") - .snippet("pub(crate) $0") - .add_to(acc); + ) + .lookup_by("tfn") + .add_to(acc); + + snippet("pub(crate)", "pub(crate) $0").add_to(acc); } #[cfg(test)] -- cgit v1.2.3 From 328d123f5baeab8ff9a1f63a6744f6eec89818ab Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 01:37:11 +0300 Subject: specify completion item kind --- crates/ra_analysis/src/completion.rs | 2 +- crates/ra_analysis/src/completion/complete_keyword.rs | 3 ++- crates/ra_analysis/src/completion/complete_snippet.rs | 6 ++++-- crates/ra_analysis/src/completion/completion_item.rs | 18 ++++++++++-------- 4 files changed, 17 insertions(+), 12 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index 2d61a3aef..d742d6295 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs @@ -18,7 +18,7 @@ use crate::{ }, }; -pub use crate::completion::completion_item::{CompletionItem, InsertText}; +pub use crate::completion::completion_item::{CompletionItem, InsertText, CompletionItemKind}; /// Main entry point for copmletion. We run comletion as a two-phase process. /// diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index 2c7891920..5427fcb11 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs @@ -5,10 +5,11 @@ use ra_syntax::{ SyntaxKind::*, SyntaxNodeRef, }; -use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind}; +use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; fn keyword(kw: &str, snippet: &str) -> CompletionItem { CompletionItem::new(CompletionKind::Keyword, kw) + .kind(CompletionItemKind::Keyword) .snippet(snippet) .build() } diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs index 1feb332b9..91de8ca37 100644 --- a/crates/ra_analysis/src/completion/complete_snippet.rs +++ b/crates/ra_analysis/src/completion/complete_snippet.rs @@ -1,7 +1,9 @@ -use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext, completion_item::Builder}; +use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionItemKind, CompletionContext, completion_item::Builder}; fn snippet(label: &str, snippet: &str) -> Builder { - CompletionItem::new(CompletionKind::Snippet, label).snippet(snippet) + CompletionItem::new(CompletionKind::Snippet, label) + .snippet(snippet) + .kind(CompletionItemKind::Keyword) } pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index 423d5a48b..89fbe62d8 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs @@ -3,13 +3,13 @@ /// `CompletionItem`, use `new` method and the `Builder` struct. #[derive(Debug)] pub struct CompletionItem { + /// Used only internally in tests, to check only specific kind of + /// completion. + completion_kind: CompletionKind, label: String, lookup: Option, snippet: Option, kind: Option, - /// Used only internally in tests, to check only specific kind of - /// completion. - completion_kind: CompletionKind, } pub enum InsertText { @@ -38,10 +38,11 @@ impl CompletionItem { pub(crate) fn new(completion_kind: CompletionKind, label: impl Into) -> Builder { let label = label.into(); Builder { + completion_kind, label, lookup: None, snippet: None, - completion_kind, + kind: None, } } /// What user sees in pop-up in the UI. @@ -73,10 +74,11 @@ impl CompletionItem { /// A helper to make `CompletionItem`s. #[must_use] pub(crate) struct Builder { + completion_kind: CompletionKind, label: String, lookup: Option, snippet: Option, - completion_kind: CompletionKind, + kind: Option, } impl Builder { @@ -89,7 +91,7 @@ impl Builder { label: self.label, lookup: self.lookup, snippet: self.snippet, - kind: None, + kind: self.kind, completion_kind: self.completion_kind, } } @@ -101,8 +103,8 @@ impl Builder { self.snippet = Some(snippet.into()); self } - pub(crate) fn kind(mut self, kind: CompletionKind) -> Builder { - self.completion_kind = kind; + pub(crate) fn kind(mut self, kind: CompletionItemKind) -> Builder { + self.kind = Some(kind); self } } -- cgit v1.2.3 From 238b52358d0d6109c89d1288b12bfa0aa71790de Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 02:02:47 +0300 Subject: more icons --- crates/ra_analysis/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index b2f4cd228..6fd157880 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -30,7 +30,7 @@ use crate::{ }; pub use crate::{ - completion::{CompletionItem, InsertText}, + completion::{CompletionItem, CompletionItemKind, InsertText}, }; pub use ra_editor::{ FileSymbol, Fold, FoldKind, HighlightedRange, LineIndex, Runnable, RunnableKind, StructureNode, -- cgit v1.2.3 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 From 498e3a6846602b9f2cd40c093007071b4df35817 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 02:24:59 +0300 Subject: binding icon --- crates/ra_analysis/src/completion/complete_scope.rs | 6 ++++-- crates/ra_analysis/src/completion/completion_item.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs index 4f27ad9eb..82610d63f 100644 --- a/crates/ra_analysis/src/completion/complete_scope.rs +++ b/crates/ra_analysis/src/completion/complete_scope.rs @@ -3,7 +3,7 @@ use ra_syntax::TextUnit; use crate::{ Cancelable, - completion::{CompletionItem, Completions, CompletionKind, CompletionContext}, + completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, }; pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { @@ -46,7 +46,9 @@ fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit) .flat_map(|scope| scopes.entries(scope).iter()) .filter(|entry| shadowed.insert(entry.name())) .for_each(|entry| { - CompletionItem::new(CompletionKind::Reference, entry.name().to_string()).add_to(acc) + CompletionItem::new(CompletionKind::Reference, entry.name().to_string()) + .kind(CompletionItemKind::Binding) + .add_to(acc) }); if scopes.self_param.is_some() { CompletionItem::new(CompletionKind::Reference, "self").add_to(acc); diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs index cbd42a44e..911f08468 100644 --- a/crates/ra_analysis/src/completion/completion_item.rs +++ b/crates/ra_analysis/src/completion/completion_item.rs @@ -25,6 +25,7 @@ pub enum CompletionItemKind { Keyword, Module, Function, + Binding, } #[derive(Debug, PartialEq, Eq)] -- cgit v1.2.3 From ea763c73b8d89edbf716805c62cf31b00e2e1a4f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 02:28:09 +0300 Subject: fix snippet icon --- crates/ra_analysis/src/completion/complete_snippet.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs index 91de8ca37..fb9da0a4f 100644 --- a/crates/ra_analysis/src/completion/complete_snippet.rs +++ b/crates/ra_analysis/src/completion/complete_snippet.rs @@ -3,7 +3,7 @@ use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionI fn snippet(label: &str, snippet: &str) -> Builder { CompletionItem::new(CompletionKind::Snippet, label) .snippet(snippet) - .kind(CompletionItemKind::Keyword) + .kind(CompletionItemKind::Snippet) } pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionContext) { -- cgit v1.2.3