From 74406ca8ea45df8b44cb38ecba4a5b561038c4a0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 21 Dec 2018 14:02:14 +0300 Subject: introduce completion_item module --- .../ra_analysis/src/completion/completion_item.rs | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 crates/ra_analysis/src/completion/completion_item.rs (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 new file mode 100644 index 000000000..309b0108d --- /dev/null +++ b/crates/ra_analysis/src/completion/completion_item.rs @@ -0,0 +1,44 @@ +#[derive(Debug)] +pub struct CompletionItem { + /// What user sees in pop-up in the UI. + pub label: String, + /// What string is used for filtering, defaults to label. + pub lookup: Option, + /// What is inserted, defaults to label. + pub snippet: Option, +} + +impl CompletionItem { + pub(crate) fn new(label: impl Into) -> Builder { + let label = label.into(); + Builder { + label, + lookup: None, + snippet: None, + } + } +} + +pub(crate) struct Builder { + label: String, + lookup: Option, + snippet: Option, +} + +impl Builder { + pub fn add_to(self, acc: &mut Vec) { + acc.push(self.build()) + } + + pub fn build(self) -> CompletionItem { + CompletionItem { + label: self.label, + lookup: self.lookup, + snippet: self.snippet, + } + } + pub fn lookup_by(mut self, lookup: impl Into) -> Builder { + self.lookup = Some(lookup.into()); + self + } +} -- cgit v1.2.3