diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/completion.rs | 1 | ||||
-rw-r--r-- | crates/ra_analysis/src/completion/complete_keyword.rs | 67 |
2 files changed, 68 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/completion.rs b/crates/ra_analysis/src/completion.rs index fe580700f..b4ee092b5 100644 --- a/crates/ra_analysis/src/completion.rs +++ b/crates/ra_analysis/src/completion.rs | |||
@@ -40,6 +40,7 @@ pub(crate) fn completions( | |||
40 | 40 | ||
41 | complete_fn_param::complete_fn_param(&mut acc, &ctx); | 41 | complete_fn_param::complete_fn_param(&mut acc, &ctx); |
42 | 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); | ||
43 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); | 44 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); |
44 | complete_snippet::complete_item_snippet(&mut acc, &ctx); | 45 | complete_snippet::complete_item_snippet(&mut acc, &ctx); |
45 | complete_path::complete_path(&mut acc, &ctx)?; | 46 | complete_path::complete_path(&mut acc, &ctx)?; |
diff --git a/crates/ra_analysis/src/completion/complete_keyword.rs b/crates/ra_analysis/src/completion/complete_keyword.rs index d70fdaada..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) |
@@ -18,6 +50,7 @@ pub(super) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
18 | if !ctx.is_trivial_path { | 50 | if !ctx.is_trivial_path { |
19 | return; | 51 | return; |
20 | } | 52 | } |
53 | |||
21 | let fn_def = match ctx.function_syntax { | 54 | let fn_def = match ctx.function_syntax { |
22 | Some(it) => it, | 55 | Some(it) => it, |
23 | None => return, | 56 | None => return, |
@@ -80,6 +113,40 @@ mod tests { | |||
80 | } | 113 | } |
81 | 114 | ||
82 | #[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] | ||
83 | fn completes_various_keywords_in_function() { | 150 | fn completes_various_keywords_in_function() { |
84 | check_keyword_completion( | 151 | check_keyword_completion( |
85 | r" | 152 | r" |