diff options
Diffstat (limited to 'crates/ra_analysis/src/completion/completion_item.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/completion_item.rs | 44 |
1 files changed, 44 insertions, 0 deletions
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 @@ | |||
1 | #[derive(Debug)] | ||
2 | pub struct CompletionItem { | ||
3 | /// What user sees in pop-up in the UI. | ||
4 | pub label: String, | ||
5 | /// What string is used for filtering, defaults to label. | ||
6 | pub lookup: Option<String>, | ||
7 | /// What is inserted, defaults to label. | ||
8 | pub snippet: Option<String>, | ||
9 | } | ||
10 | |||
11 | impl CompletionItem { | ||
12 | pub(crate) fn new(label: impl Into<String>) -> Builder { | ||
13 | let label = label.into(); | ||
14 | Builder { | ||
15 | label, | ||
16 | lookup: None, | ||
17 | snippet: None, | ||
18 | } | ||
19 | } | ||
20 | } | ||
21 | |||
22 | pub(crate) struct Builder { | ||
23 | label: String, | ||
24 | lookup: Option<String>, | ||
25 | snippet: Option<String>, | ||
26 | } | ||
27 | |||
28 | impl Builder { | ||
29 | pub fn add_to(self, acc: &mut Vec<CompletionItem>) { | ||
30 | acc.push(self.build()) | ||
31 | } | ||
32 | |||
33 | pub fn build(self) -> CompletionItem { | ||
34 | CompletionItem { | ||
35 | label: self.label, | ||
36 | lookup: self.lookup, | ||
37 | snippet: self.snippet, | ||
38 | } | ||
39 | } | ||
40 | pub fn lookup_by(mut self, lookup: impl Into<String>) -> Builder { | ||
41 | self.lookup = Some(lookup.into()); | ||
42 | self | ||
43 | } | ||
44 | } | ||