From f731d910cbfe36bbdfa3a3f1415d5c48c4a79238 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Sun, 25 Oct 2020 11:26:38 +0300 Subject: Move Completions structure definition into completions module --- crates/completion/src/completions.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'crates/completion/src/completions.rs') diff --git a/crates/completion/src/completions.rs b/crates/completion/src/completions.rs index 5b280c5ba..db27bdd9c 100644 --- a/crates/completion/src/completions.rs +++ b/crates/completion/src/completions.rs @@ -11,3 +11,39 @@ pub(crate) mod postfix; pub(crate) mod macro_in_item_position; pub(crate) mod trait_impl; pub(crate) mod mod_; + +use crate::item::{Builder, CompletionItem}; + +/// Represents an in-progress set of completions being built. +#[derive(Debug, Default)] +pub struct Completions { + buf: Vec, +} + +impl Completions { + pub fn add(&mut self, item: CompletionItem) { + self.buf.push(item.into()) + } + + pub fn add_all(&mut self, items: I) + where + I: IntoIterator, + I::Item: Into, + { + items.into_iter().for_each(|item| self.add(item.into())) + } +} + +impl Into> for Completions { + fn into(self) -> Vec { + self.buf + } +} + +impl Builder { + /// Convenience method, which allows to add a freshly created completion into accumulator + /// without binding it to the variable. + pub(crate) fn add_to(self, acc: &mut Completions) { + acc.add(self.build()) + } +} -- cgit v1.2.3