aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion/completion_item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/completion/completion_item.rs')
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs34
1 files changed, 28 insertions, 6 deletions
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs
index 7edb86436..4280976e7 100644
--- a/crates/ra_analysis/src/completion/completion_item.rs
+++ b/crates/ra_analysis/src/completion/completion_item.rs
@@ -1,11 +1,13 @@
1#[derive(Debug)] 1#[derive(Debug)]
2pub struct CompletionItem { 2pub struct CompletionItem {
3 /// What user sees in pop-up in the UI. 3 label: String,
4 pub label: String, 4 lookup: Option<String>,
5 /// What string is used for filtering, defaults to label. 5 snippet: Option<String>,
6 pub lookup: Option<String>, 6}
7 /// What is inserted, defaults to label. 7
8 pub snippet: Option<String>, 8pub enum InsertText {
9 PlainText { text: String },
10 Snippet { text: String },
9} 11}
10 12
11impl CompletionItem { 13impl CompletionItem {
@@ -17,6 +19,26 @@ impl CompletionItem {
17 snippet: None, 19 snippet: None,
18 } 20 }
19 } 21 }
22 /// What user sees in pop-up in the UI.
23 pub fn label(&self) -> &str {
24 &self.label
25 }
26 /// What string is used for filtering.
27 pub fn lookup(&self) -> &str {
28 self.lookup
29 .as_ref()
30 .map(|it| it.as_str())
31 .unwrap_or(self.label())
32 }
33 /// What is inserted.
34 pub fn insert_text(&self) -> InsertText {
35 match &self.snippet {
36 None => InsertText::PlainText {
37 text: self.label.clone(),
38 },
39 Some(it) => InsertText::Snippet { text: it.clone() },
40 }
41 }
20} 42}
21 43
22#[must_use] 44#[must_use]