aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/completion_item.rs
blob: 7edb864363bcb42e8f516e7077234c5f561710e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#[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<String>,
    /// What is inserted, defaults to label.
    pub snippet: Option<String>,
}

impl CompletionItem {
    pub(crate) fn new(label: impl Into<String>) -> Builder {
        let label = label.into();
        Builder {
            label,
            lookup: None,
            snippet: None,
        }
    }
}

#[must_use]
pub(crate) struct Builder {
    label: String,
    lookup: Option<String>,
    snippet: Option<String>,
}

impl Builder {
    pub fn add_to(self, acc: &mut Vec<CompletionItem>) {
        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<String>) -> Builder {
        self.lookup = Some(lookup.into());
        self
    }
    pub fn snippet(mut self, snippet: impl Into<String>) -> Builder {
        self.snippet = Some(snippet.into());
        self
    }
}