diff options
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 3 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/complete_keyword.rs | 66 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/complete_use_tree.rs | 75 |
3 files changed, 67 insertions, 77 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index a795dd767..b4ee092b5 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -7,7 +7,6 @@ mod complete_keyword; | |||
7 | mod complete_snippet; | 7 | mod complete_snippet; |
8 | mod complete_path; | 8 | mod complete_path; |
9 | mod complete_scope; | 9 | mod complete_scope; |
10 | mod complete_use_tree; | ||
11 | 10 | ||
12 | use ra_db::SyntaxDatabase; | 11 | use ra_db::SyntaxDatabase; |
13 | 12 | ||
@@ -41,12 +40,12 @@ pub(crate) fn completions( | |||
41 | 40 | ||
42 | complete_fn_param::complete_fn_param(&mut acc, &ctx); | 41 | complete_fn_param::complete_fn_param(&mut acc, &ctx); |
43 | complete_keyword::complete_expr_keyword(&mut acc, &ctx); | 42 | complete_keyword::complete_expr_keyword(&mut acc, &ctx); |
43 | complete_keyword::complete_use_tree_keyword(&mut acc, &ctx); | ||
44 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); | 44 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); |
45 | complete_snippet::complete_item_snippet(&mut acc, &ctx); | 45 | complete_snippet::complete_item_snippet(&mut acc, &ctx); |
46 | complete_path::complete_path(&mut acc, &ctx)?; | 46 | complete_path::complete_path(&mut acc, &ctx)?; |
47 | complete_scope::complete_scope(&mut acc, &ctx)?; | 47 | complete_scope::complete_scope(&mut acc, &ctx)?; |
48 | complete_dot::complete_dot(&mut acc, &ctx)?; | 48 | complete_dot::complete_dot(&mut acc, &ctx)?; |
49 | complete_use_tree::complete_use_tree_keyword(&mut acc, &ctx); | ||
50 | 49 | ||
51 | Ok(Some(acc)) | 50 | Ok(Some(acc)) |
52 | } | 51 | } |
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index a381046e9..28194c908 100644 --- a/crates/ra_analysis/src/completion/complete_keyword.rs +++ b/crates/ra_analysis/src/completion/complete_keyword.rs | |||
@@ -7,6 +7,38 @@ use ra_syntax::{ | |||
7 | 7 | ||
8 | use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; | 8 | use crate::completion::{CompletionContext, CompletionItem, Completions, CompletionKind, CompletionItemKind}; |
9 | 9 | ||
10 | pub(super) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionContext) { | ||
11 | // complete keyword "crate" in use stmt | ||
12 | match (ctx.use_item_syntax.as_ref(), ctx.path_prefix.as_ref()) { | ||
13 | (Some(_), None) => { | ||
14 | CompletionItem::new(CompletionKind::Keyword, "crate") | ||
15 | .kind(CompletionItemKind::Keyword) | ||
16 | .lookup_by("crate") | ||
17 | .snippet("crate::") | ||
18 | .add_to(acc); | ||
19 | CompletionItem::new(CompletionKind::Keyword, "self") | ||
20 | .kind(CompletionItemKind::Keyword) | ||
21 | .lookup_by("self") | ||
22 | .add_to(acc); | ||
23 | CompletionItem::new(CompletionKind::Keyword, "super") | ||
24 | .kind(CompletionItemKind::Keyword) | ||
25 | .lookup_by("super") | ||
26 | .add_to(acc); | ||
27 | } | ||
28 | (Some(_), Some(_)) => { | ||
29 | CompletionItem::new(CompletionKind::Keyword, "self") | ||
30 | .kind(CompletionItemKind::Keyword) | ||
31 | .lookup_by("self") | ||
32 | .add_to(acc); | ||
33 | CompletionItem::new(CompletionKind::Keyword, "super") | ||
34 | .kind(CompletionItemKind::Keyword) | ||
35 | .lookup_by("super") | ||
36 | .add_to(acc); | ||
37 | } | ||
38 | _ => {} | ||
39 | } | ||
40 | } | ||
41 | |||
10 | fn keyword(kw: &str, snippet: &str) -> CompletionItem { | 42 | fn keyword(kw: &str, snippet: &str) -> CompletionItem { |
11 | CompletionItem::new(CompletionKind::Keyword, kw) | 43 | CompletionItem::new(CompletionKind::Keyword, kw) |
12 | .kind(CompletionItemKind::Keyword) | 44 | .kind(CompletionItemKind::Keyword) |
@@ -81,6 +113,40 @@ mod tests { | |||
81 | } | 113 | } |
82 | 114 | ||
83 | #[test] | 115 | #[test] |
116 | fn completes_keywords_in_use_stmt() { | ||
117 | check_keyword_completion( | ||
118 | r" | ||
119 | use <|> | ||
120 | ", | ||
121 | r#" | ||
122 | crate "crate" "crate::" | ||
123 | self "self" | ||
124 | super "super" | ||
125 | "#, | ||
126 | ); | ||
127 | |||
128 | check_keyword_completion( | ||
129 | r" | ||
130 | use a::<|> | ||
131 | ", | ||
132 | r#" | ||
133 | self "self" | ||
134 | super "super" | ||
135 | "#, | ||
136 | ); | ||
137 | |||
138 | check_keyword_completion( | ||
139 | r" | ||
140 | use a::{b, <|>} | ||
141 | ", | ||
142 | r#" | ||
143 | self "self" | ||
144 | super "super" | ||
145 | "#, | ||
146 | ); | ||
147 | } | ||
148 | |||
149 | #[test] | ||
84 | fn completes_various_keywords_in_function() { | 150 | fn completes_various_keywords_in_function() { |
85 | check_keyword_completion( | 151 | check_keyword_completion( |
86 | r" | 152 | r" |
diff --git a/crates/ra_analysis/src/completion/complete_use_tree.rs b/crates/ra_analysis/src/completion/complete_use_tree.rs deleted file mode 100644 index 5f2f6e449..000000000 --- a/crates/ra_analysis/src/completion/complete_use_tree.rs +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
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 | } | ||