aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/completion
diff options
context:
space:
mode:
authorgfreezy <[email protected]>2019-01-01 15:00:29 +0000
committergfreezy <[email protected]>2019-01-01 15:00:29 +0000
commit9895529d5c7223e572f04ec424d94a187b4983a1 (patch)
tree7aed703921e1952f0f1ab0e44d74a3d6a7f46b59 /crates/ra_analysis/src/completion
parent22ea00d5ff2a993735702ec8e28fecfcbf4ffc4f (diff)
move to a seperate complete_use_tree_keyword mod
Diffstat (limited to 'crates/ra_analysis/src/completion')
-rw-r--r--crates/ra_analysis/src/completion/complete_keyword.rs64
-rw-r--r--crates/ra_analysis/src/completion/complete_use_tree.rs75
2 files changed, 75 insertions, 64 deletions
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs
index dd81fc008..a381046e9 100644
--- a/crates/ra_analysis/src/completion/complete_keyword.rs
+++ b/crates/ra_analysis/src/completion/complete_keyword.rs
@@ -15,36 +15,6 @@ fn keyword(kw: &str, snippet: &str) -> CompletionItem {
15} 15}
16 16
17pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) { 17pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionContext) {
18 // complete keyword "crate" in use stmt
19 match (ctx.use_item_syntax.as_ref(), ctx.path_prefix.as_ref()) {
20 (Some(_), None) => {
21 CompletionItem::new(CompletionKind::Keyword, "crate")
22 .kind(CompletionItemKind::Keyword)
23 .lookup_by("crate")
24 .snippet("crate::")
25 .add_to(acc);
26 CompletionItem::new(CompletionKind::Keyword, "self")
27 .kind(CompletionItemKind::Keyword)
28 .lookup_by("self")
29 .add_to(acc);
30 CompletionItem::new(CompletionKind::Keyword, "super")
31 .kind(CompletionItemKind::Keyword)
32 .lookup_by("super")
33 .add_to(acc);
34 }
35 (Some(_), Some(_)) => {
36 CompletionItem::new(CompletionKind::Keyword, "self")
37 .kind(CompletionItemKind::Keyword)
38 .lookup_by("self")
39 .add_to(acc);
40 CompletionItem::new(CompletionKind::Keyword, "super")
41 .kind(CompletionItemKind::Keyword)
42 .lookup_by("super")
43 .add_to(acc);
44 }
45 _ => {}
46 }
47
48 if !ctx.is_trivial_path { 18 if !ctx.is_trivial_path {
49 return; 19 return;
50 } 20 }
@@ -300,38 +270,4 @@ mod tests {
300 "#, 270 "#,
301 ) 271 )
302 } 272 }
303
304 #[test]
305 fn completes_keywords_in_use_stmt() {
306 check_keyword_completion(
307 r"
308 use <|>
309 ",
310 r#"
311 crate "crate" "crate::"
312 self "self"
313 super "super"
314 "#,
315 );
316
317 check_keyword_completion(
318 r"
319 use a::<|>
320 ",
321 r#"
322 self "self"
323 super "super"
324 "#,
325 );
326
327 check_keyword_completion(
328 r"
329 use a::{b, <|>}
330 ",
331 r#"
332 self "self"
333 super "super"
334 "#,
335 );
336 }
337} 273}
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 @@
1use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind};
2
3pub(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)]
36mod 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}