From ddf2a8a948ed91bda14fef398c850c71c403ab59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Jan 2019 18:09:49 +0300 Subject: add completion detail --- crates/ra_ide_api/src/completion/completion_item.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index a25b87bee..d707a84ef 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -11,6 +11,7 @@ pub struct CompletionItem { /// completion. completion_kind: CompletionKind, label: String, + detail: Option, lookup: Option, snippet: Option, kind: Option, @@ -51,6 +52,7 @@ impl CompletionItem { Builder { completion_kind, label, + detail: None, lookup: None, snippet: None, kind: None, @@ -60,6 +62,10 @@ impl CompletionItem { pub fn label(&self) -> &str { &self.label } + /// Short one-line additional information, like a type + pub fn detail(&self) -> Option<&str> { + self.detail.as_ref().map(|it| it.as_str()) + } /// What string is used for filtering. pub fn lookup(&self) -> &str { self.lookup @@ -87,6 +93,7 @@ impl CompletionItem { pub(crate) struct Builder { completion_kind: CompletionKind, label: String, + detail: Option, lookup: Option, snippet: Option, kind: Option, @@ -100,6 +107,7 @@ impl Builder { pub(crate) fn build(self) -> CompletionItem { CompletionItem { label: self.label, + detail: self.detail, lookup: self.lookup, snippet: self.snippet, kind: self.kind, @@ -118,6 +126,10 @@ impl Builder { self.kind = Some(kind); self } + pub(crate) fn detail(mut self, detail: impl Into) -> Builder { + self.detail = Some(detail.into()); + self + } pub(super) fn from_resolution( mut self, ctx: &CompletionContext, -- cgit v1.2.3