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/completion/completion_item.rs') 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 --- crates/ra_analysis/src/completion/completion_item.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'crates/ra_analysis/src/completion/completion_item.rs') 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 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/completion_item.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'crates/ra_analysis/src/completion/completion_item.rs') 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 97cb463c9be3c21931d0e284603238ce3cb02b2a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 02:20:14 +0300 Subject: moar icons --- .../ra_analysis/src/completion/completion_item.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'crates/ra_analysis/src/completion/completion_item.rs') 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/completion_item.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ra_analysis/src/completion/completion_item.rs') 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