aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_analysis/src/completion/complete_fn_param.rs3
-rw-r--r--crates/ra_analysis/src/completion/complete_keyword.rs5
-rw-r--r--crates/ra_analysis/src/completion/complete_path.rs8
-rw-r--r--crates/ra_analysis/src/completion/complete_scope.rs14
-rw-r--r--crates/ra_analysis/src/completion/complete_snippet.rs12
-rw-r--r--crates/ra_analysis/src/completion/completion_item.rs20
6 files changed, 28 insertions, 34 deletions
diff --git a/crates/ra_analysis/src/completion/complete_fn_param.rs b/crates/ra_analysis/src/completion/complete_fn_param.rs
index 6a6213e67..bb5fdfda0 100644
--- a/crates/ra_analysis/src/completion/complete_fn_param.rs
+++ b/crates/ra_analysis/src/completion/complete_fn_param.rs
@@ -34,9 +34,8 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
34 } 34 }
35 }) 35 })
36 .for_each(|(label, lookup)| { 36 .for_each(|(label, lookup)| {
37 CompletionItem::new(label) 37 CompletionItem::new(CompletionKind::Magic, label)
38 .lookup_by(lookup) 38 .lookup_by(lookup)
39 .kind(CompletionKind::Magic)
40 .add_to(acc) 39 .add_to(acc)
41 }); 40 });
42 41
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs
index dead15bb6..1e6d7008d 100644
--- a/crates/ra_analysis/src/completion/complete_keyword.rs
+++ b/crates/ra_analysis/src/completion/complete_keyword.rs
@@ -61,10 +61,7 @@ fn complete_return(fn_def: ast::FnDef, is_stmt: bool) -> Option<CompletionItem>
61} 61}
62 62
63fn keyword(kw: &str, snippet: &str) -> CompletionItem { 63fn keyword(kw: &str, snippet: &str) -> CompletionItem {
64 CompletionItem::new(kw) 64 CompletionItem::new(Keyword, kw).snippet(snippet).build()
65 .kind(Keyword)
66 .snippet(snippet)
67 .build()
68} 65}
69 66
70#[cfg(test)] 67#[cfg(test)]
diff --git a/crates/ra_analysis/src/completion/complete_path.rs b/crates/ra_analysis/src/completion/complete_path.rs
index 5fc24af72..692502bb2 100644
--- a/crates/ra_analysis/src/completion/complete_path.rs
+++ b/crates/ra_analysis/src/completion/complete_path.rs
@@ -17,11 +17,9 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C
17 _ => return Ok(()), 17 _ => return Ok(()),
18 }; 18 };
19 let module_scope = target_module.scope(ctx.db)?; 19 let module_scope = target_module.scope(ctx.db)?;
20 module_scope.entries().for_each(|(name, _res)| { 20 module_scope
21 CompletionItem::new(name.to_string()) 21 .entries()
22 .kind(Reference) 22 .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc));
23 .add_to(acc)
24 });
25 Ok(()) 23 Ok(())
26} 24}
27 25
diff --git a/crates/ra_analysis/src/completion/complete_scope.rs b/crates/ra_analysis/src/completion/complete_scope.rs
index d07c0e46d..f39b98d62 100644
--- a/crates/ra_analysis/src/completion/complete_scope.rs
+++ b/crates/ra_analysis/src/completion/complete_scope.rs
@@ -29,11 +29,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) ->
29 } 29 }
30 } 30 }
31 }) 31 })
32 .for_each(|(name, _res)| { 32 .for_each(|(name, _res)| CompletionItem::new(Reference, name.to_string()).add_to(acc));
33 CompletionItem::new(name.to_string())
34 .kind(Reference)
35 .add_to(acc)
36 });
37 } 33 }
38 34
39 Ok(()) 35 Ok(())
@@ -45,13 +41,9 @@ fn complete_fn(acc: &mut Completions, scopes: &hir::FnScopes, offset: TextUnit)
45 .scope_chain_for_offset(offset) 41 .scope_chain_for_offset(offset)
46 .flat_map(|scope| scopes.entries(scope).iter()) 42 .flat_map(|scope| scopes.entries(scope).iter())
47 .filter(|entry| shadowed.insert(entry.name())) 43 .filter(|entry| shadowed.insert(entry.name()))
48 .for_each(|entry| { 44 .for_each(|entry| CompletionItem::new(Reference, entry.name().to_string()).add_to(acc));
49 CompletionItem::new(entry.name().to_string())
50 .kind(Reference)
51 .add_to(acc)
52 });
53 if scopes.self_param.is_some() { 45 if scopes.self_param.is_some() {
54 CompletionItem::new("self").kind(Reference).add_to(acc); 46 CompletionItem::new(Reference, "self").add_to(acc);
55 } 47 }
56} 48}
57 49
diff --git a/crates/ra_analysis/src/completion/complete_snippet.rs b/crates/ra_analysis/src/completion/complete_snippet.rs
index ccd68832b..f0ad45fec 100644
--- a/crates/ra_analysis/src/completion/complete_snippet.rs
+++ b/crates/ra_analysis/src/completion/complete_snippet.rs
@@ -4,13 +4,11 @@ pub(super) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte
4 if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) { 4 if !(ctx.is_trivial_path && ctx.enclosing_fn.is_some()) {
5 return; 5 return;
6 } 6 }
7 CompletionItem::new("pd") 7 CompletionItem::new(Snippet, "pd")
8 .snippet("eprintln!(\"$0 = {:?}\", $0);") 8 .snippet("eprintln!(\"$0 = {:?}\", $0);")
9 .kind(Snippet)
10 .add_to(acc); 9 .add_to(acc);
11 CompletionItem::new("ppd") 10 CompletionItem::new(Snippet, "ppd")
12 .snippet("eprintln!(\"$0 = {:#?}\", $0);") 11 .snippet("eprintln!(\"$0 = {:#?}\", $0);")
13 .kind(Snippet)
14 .add_to(acc); 12 .add_to(acc);
15} 13}
16 14
@@ -18,7 +16,7 @@ pub(super) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionConte
18 if !ctx.is_new_item { 16 if !ctx.is_new_item {
19 return; 17 return;
20 } 18 }
21 CompletionItem::new("Test function") 19 CompletionItem::new(Snippet, "Test function")
22 .lookup_by("tfn") 20 .lookup_by("tfn")
23 .snippet( 21 .snippet(
24 "\ 22 "\
@@ -27,11 +25,9 @@ fn ${1:feature}() {
27 $0 25 $0
28}", 26}",
29 ) 27 )
30 .kind(Snippet)
31 .add_to(acc); 28 .add_to(acc);
32 CompletionItem::new("pub(crate)") 29 CompletionItem::new(Snippet, "pub(crate)")
33 .snippet("pub(crate) $0") 30 .snippet("pub(crate) $0")
34 .kind(Snippet)
35 .add_to(acc); 31 .add_to(acc);
36} 32}
37 33
diff --git a/crates/ra_analysis/src/completion/completion_item.rs b/crates/ra_analysis/src/completion/completion_item.rs
index 30581c8a5..423d5a48b 100644
--- a/crates/ra_analysis/src/completion/completion_item.rs
+++ b/crates/ra_analysis/src/completion/completion_item.rs
@@ -6,7 +6,9 @@ pub struct CompletionItem {
6 label: String, 6 label: String,
7 lookup: Option<String>, 7 lookup: Option<String>,
8 snippet: Option<String>, 8 snippet: Option<String>,
9 /// Used only internally in test, to check only specific kind of completion. 9 kind: Option<CompletionItemKind>,
10 /// Used only internally in tests, to check only specific kind of
11 /// completion.
10 completion_kind: CompletionKind, 12 completion_kind: CompletionKind,
11} 13}
12 14
@@ -15,6 +17,12 @@ pub enum InsertText {
15 Snippet { text: String }, 17 Snippet { text: String },
16} 18}
17 19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum CompletionItemKind {
22 Snippet,
23 Keyword,
24}
25
18#[derive(Debug, PartialEq, Eq)] 26#[derive(Debug, PartialEq, Eq)]
19pub(crate) enum CompletionKind { 27pub(crate) enum CompletionKind {
20 /// Parser-based keyword completion. 28 /// Parser-based keyword completion.
@@ -24,17 +32,16 @@ pub(crate) enum CompletionKind {
24 /// "Secret sauce" completions. 32 /// "Secret sauce" completions.
25 Magic, 33 Magic,
26 Snippet, 34 Snippet,
27 Unspecified,
28} 35}
29 36
30impl CompletionItem { 37impl CompletionItem {
31 pub(crate) fn new(label: impl Into<String>) -> Builder { 38 pub(crate) fn new(completion_kind: CompletionKind, label: impl Into<String>) -> Builder {
32 let label = label.into(); 39 let label = label.into();
33 Builder { 40 Builder {
34 label, 41 label,
35 lookup: None, 42 lookup: None,
36 snippet: None, 43 snippet: None,
37 completion_kind: CompletionKind::Unspecified, 44 completion_kind,
38 } 45 }
39 } 46 }
40 /// What user sees in pop-up in the UI. 47 /// What user sees in pop-up in the UI.
@@ -57,6 +64,10 @@ impl CompletionItem {
57 Some(it) => InsertText::Snippet { text: it.clone() }, 64 Some(it) => InsertText::Snippet { text: it.clone() },
58 } 65 }
59 } 66 }
67
68 pub fn kind(&self) -> Option<CompletionItemKind> {
69 self.kind
70 }
60} 71}
61 72
62/// A helper to make `CompletionItem`s. 73/// A helper to make `CompletionItem`s.
@@ -78,6 +89,7 @@ impl Builder {
78 label: self.label, 89 label: self.label,
79 lookup: self.lookup, 90 lookup: self.lookup,
80 snippet: self.snippet, 91 snippet: self.snippet,
92 kind: None,
81 completion_kind: self.completion_kind, 93 completion_kind: self.completion_kind,
82 } 94 }
83 } 95 }