diff options
Diffstat (limited to 'crates/ide_completion/src/completions/keyword.rs')
-rw-r--r-- | crates/ide_completion/src/completions/keyword.rs | 64 |
1 files changed, 18 insertions, 46 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index 73bbc4345..9754122a0 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs | |||
@@ -18,17 +18,24 @@ pub(crate) fn complete_use_tree_keyword(acc: &mut Completions, ctx: &CompletionC | |||
18 | item | 18 | item |
19 | }; | 19 | }; |
20 | 20 | ||
21 | if ctx.use_item_syntax.is_some() { | 21 | if ctx.in_use_tree() { |
22 | let qual = ctx.path_qual(); | 22 | match &ctx.path_context { |
23 | if qual.is_none() { | 23 | Some(PathCompletionContext { qualifier: Some(qual), use_tree_parent, .. }) => { |
24 | kw_completion("crate::").add_to(acc); | 24 | if iter::successors(Some(qual.clone()), |p| p.qualifier()) |
25 | } | 25 | .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) |
26 | kw_completion("self").add_to(acc); | 26 | { |
27 | if iter::successors(qual.cloned(), |p| p.qualifier()) | 27 | kw_completion("super::").add_to(acc); |
28 | .all(|p| p.segment().and_then(|s| s.super_token()).is_some()) | 28 | } |
29 | { | 29 | if *use_tree_parent { |
30 | kw_completion("super::").add_to(acc); | 30 | kw_completion("self").add_to(acc); |
31 | } | 31 | } |
32 | } | ||
33 | _ => { | ||
34 | kw_completion("crate::").add_to(acc); | ||
35 | kw_completion("self::").add_to(acc); | ||
36 | kw_completion("super::").add_to(acc); | ||
37 | } | ||
38 | }; | ||
32 | } | 39 | } |
33 | 40 | ||
34 | // Suggest .await syntax for types that implement Future trait | 41 | // Suggest .await syntax for types that implement Future trait |
@@ -200,41 +207,6 @@ mod tests { | |||
200 | } | 207 | } |
201 | 208 | ||
202 | #[test] | 209 | #[test] |
203 | fn test_keywords_in_use_stmt() { | ||
204 | check( | ||
205 | r"use $0", | ||
206 | expect![[r#" | ||
207 | kw crate:: | ||
208 | kw self | ||
209 | kw super:: | ||
210 | "#]], | ||
211 | ); | ||
212 | |||
213 | // FIXME: `self` shouldn't be shown here and the check below | ||
214 | check( | ||
215 | r"use a::$0", | ||
216 | expect![[r#" | ||
217 | kw self | ||
218 | "#]], | ||
219 | ); | ||
220 | |||
221 | check( | ||
222 | r"use super::$0", | ||
223 | expect![[r#" | ||
224 | kw self | ||
225 | kw super:: | ||
226 | "#]], | ||
227 | ); | ||
228 | |||
229 | check( | ||
230 | r"use a::{b, $0}", | ||
231 | expect![[r#" | ||
232 | kw self | ||
233 | "#]], | ||
234 | ); | ||
235 | } | ||
236 | |||
237 | #[test] | ||
238 | fn test_keywords_in_function() { | 210 | fn test_keywords_in_function() { |
239 | check( | 211 | check( |
240 | r"fn quux() { $0 }", | 212 | r"fn quux() { $0 }", |