diff options
Diffstat (limited to 'crates/completion/src/completions.rs')
-rw-r--r-- | crates/completion/src/completions.rs | 36 |
1 files changed, 36 insertions, 0 deletions
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; | |||
11 | pub(crate) mod macro_in_item_position; | 11 | pub(crate) mod macro_in_item_position; |
12 | pub(crate) mod trait_impl; | 12 | pub(crate) mod trait_impl; |
13 | pub(crate) mod mod_; | 13 | pub(crate) mod mod_; |
14 | |||
15 | use crate::item::{Builder, CompletionItem}; | ||
16 | |||
17 | /// Represents an in-progress set of completions being built. | ||
18 | #[derive(Debug, Default)] | ||
19 | pub struct Completions { | ||
20 | buf: Vec<CompletionItem>, | ||
21 | } | ||
22 | |||
23 | impl Completions { | ||
24 | pub fn add(&mut self, item: CompletionItem) { | ||
25 | self.buf.push(item.into()) | ||
26 | } | ||
27 | |||
28 | pub fn add_all<I>(&mut self, items: I) | ||
29 | where | ||
30 | I: IntoIterator, | ||
31 | I::Item: Into<CompletionItem>, | ||
32 | { | ||
33 | items.into_iter().for_each(|item| self.add(item.into())) | ||
34 | } | ||
35 | } | ||
36 | |||
37 | impl Into<Vec<CompletionItem>> for Completions { | ||
38 | fn into(self) -> Vec<CompletionItem> { | ||
39 | self.buf | ||
40 | } | ||
41 | } | ||
42 | |||
43 | impl Builder { | ||
44 | /// Convenience method, which allows to add a freshly created completion into accumulator | ||
45 | /// without binding it to the variable. | ||
46 | pub(crate) fn add_to(self, acc: &mut Completions) { | ||
47 | acc.add(self.build()) | ||
48 | } | ||
49 | } | ||