diff options
author | gfreezy <[email protected]> | 2019-01-01 15:00:29 +0000 |
---|---|---|
committer | gfreezy <[email protected]> | 2019-01-01 15:00:29 +0000 |
commit | 9895529d5c7223e572f04ec424d94a187b4983a1 (patch) | |
tree | 7aed703921e1952f0f1ab0e44d74a3d6a7f46b59 /crates/ra_analysis/src/completion/complete_use_tree.rs | |
parent | 22ea00d5ff2a993735702ec8e28fecfcbf4ffc4f (diff) |
move to a seperate complete_use_tree_keyword mod
Diffstat (limited to 'crates/ra_analysis/src/completion/complete_use_tree.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_use_tree.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/completion/complete_use_tree.rs b/crates/ra_analysis/src/completion/complete_use_tree.rs new file mode 100644 index 000000000..5f2f6e449 --- /dev/null +++ b/crates/ra_analysis/src/completion/complete_use_tree.rs | |||
@@ -0,0 +1,75 @@ | |||
1 | use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; | ||
2 | |||
3 | pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) { | ||
4 | // complete keyword "crate" in use stmt | ||
5 | match (ctx.use_item_syntax.as_ref(), ctx.path_prefix.as_ref()) { | ||
6 | (Some(_), None) => { | ||
7 | CompletionItem::new(CompletionKind::Keyword, "crate") | ||
8 | .kind(CompletionItemKind::Keyword) | ||
9 | .lookup_by("crate") | ||
10 | .snippet("crate::") | ||
11 | .add_to(acc); | ||
12 | CompletionItem::new(CompletionKind::Keyword, "self") | ||
13 | .kind(CompletionItemKind::Keyword) | ||
14 | .lookup_by("self") | ||
15 | .add_to(acc); | ||
16 | CompletionItem::new(CompletionKind::Keyword, "super") | ||
17 | .kind(CompletionItemKind::Keyword) | ||
18 | .lookup_by("super") | ||
19 | .add_to(acc); | ||
20 | } | ||
21 | (Some(_), Some(_)) => { | ||
22 | CompletionItem::new(CompletionKind::Keyword, "self") | ||
23 | .kind(CompletionItemKind::Keyword) | ||
24 | .lookup_by("self") | ||
25 | .add_to(acc); | ||
26 | CompletionItem::new(CompletionKind::Keyword, "super") | ||
27 | .kind(CompletionItemKind::Keyword) | ||
28 | .lookup_by("super") | ||
29 | .add_to(acc); | ||
30 | } | ||
31 | _ => {} | ||
32 | } | ||
33 | } | ||
34 | |||
35 | #[cfg(test)] | ||
36 | mod tests { | ||
37 | use crate::completion::{CompletionKind, check_completion}; | ||
38 | fn check_keyword_completion(code: &str, expected_completions: &str) { | ||
39 | check_completion(code, expected_completions, CompletionKind::Keyword); | ||
40 | } | ||
41 | |||
42 | #[test] | ||
43 | fn completes_keywords_in_use_stmt() { | ||
44 | check_keyword_completion( | ||
45 | r" | ||
46 | use <|> | ||
47 | ", | ||
48 | r#" | ||
49 | crate "crate" "crate::" | ||
50 | self "self" | ||
51 | super "super" | ||
52 | "#, | ||
53 | ); | ||
54 | |||
55 | check_keyword_completion( | ||
56 | r" | ||
57 | use a::<|> | ||
58 | ", | ||
59 | r#" | ||
60 | self "self" | ||
61 | super "super" | ||
62 | "#, | ||
63 | ); | ||
64 | |||
65 | check_keyword_completion( | ||
66 | r" | ||
67 | use a::{b, <|>} | ||
68 | ", | ||
69 | r#" | ||
70 | self "self" | ||
71 | super "super" | ||
72 | "#, | ||
73 | ); | ||
74 | } | ||
75 | } | ||