diff options
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r-- | crates/ra_analysis/src/completion/completion_item.rs | 44 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/reference_completion.rs | 8 |
2 files changed, 47 insertions, 5 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 | } | ||
diff --git a/crates/ra_analysis/src/completion/reference_completion.rs b/crates/ra_analysis/src/completion/reference_completion.rs index f483ed045..457ca13cc 100644 --- a/crates/ra_analysis/src/completion/reference_completion.rs +++ b/crates/ra_analysis/src/completion/reference_completion.rs | |||
@@ -6,11 +6,9 @@ use ra_syntax::{ | |||
6 | ast::{self, LoopBodyOwner}, | 6 | ast::{self, LoopBodyOwner}, |
7 | SyntaxKind::*, | 7 | SyntaxKind::*, |
8 | }; | 8 | }; |
9 | use hir::{ | 9 | use hir::{ |
10 | self, | 10 | self, |
11 | FnScopes, | 11 | FnScopes, Def, Path |
12 | Def, | ||
13 | Path, | ||
14 | }; | 12 | }; |
15 | 13 | ||
16 | use crate::{ | 14 | use crate::{ |