aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-21 11:02:14 +0000
committerAleksey Kladov <[email protected]>2018-12-21 11:02:14 +0000
commit74406ca8ea45df8b44cb38ecba4a5b561038c4a0 (patch)
treefcff4bfc73f566fc958862e5491d434d2fff0176 /crates/ra_analysis/src/completion
parent463e5af3f2ff54b74e4aeb73e75047c00b6339be (diff)
introduce completion_item module
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs44
-rw-r--r--crates/ra_analysis/src/completion/reference_completion.rs8
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)]
2pub 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
11impl 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
22pub(crate) struct Builder {
23 label: String,
24 lookup: Option<String>,
25 snippet: Option<String>,
26}
27
28impl 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};
9use hir::{ 9use hir::{
10 self, 10 self,
11 FnScopes, 11 FnScopes, Def, Path
12 Def,
13 Path,
14}; 12};
15 13
16use crate::{ 14use crate::{