diff options
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r-- | crates/ide_completion/src/completions/keyword.rs | 15 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 30 |
2 files changed, 31 insertions, 14 deletions
diff --git a/crates/ide_completion/src/completions/keyword.rs b/crates/ide_completion/src/completions/keyword.rs index 96447a603..c9673df85 100644 --- a/crates/ide_completion/src/completions/keyword.rs +++ b/crates/ide_completion/src/completions/keyword.rs | |||
@@ -395,6 +395,21 @@ fn quux() -> i32 { | |||
395 | } | 395 | } |
396 | 396 | ||
397 | #[test] | 397 | #[test] |
398 | fn test_keywords_in_impl_def_with_attr() { | ||
399 | check( | ||
400 | r"impl My { #[foo] $0 }", | ||
401 | expect![[r#" | ||
402 | kw fn | ||
403 | kw const | ||
404 | kw type | ||
405 | kw unsafe | ||
406 | kw pub(crate) | ||
407 | kw pub | ||
408 | "#]], | ||
409 | ); | ||
410 | } | ||
411 | |||
412 | #[test] | ||
398 | fn test_keywords_in_loop() { | 413 | fn test_keywords_in_loop() { |
399 | check( | 414 | check( |
400 | r"fn my() { loop { $0 } }", | 415 | r"fn my() { loop { $0 } }", |
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index c901b358b..ede07f605 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -1,7 +1,6 @@ | |||
1 | //! Completion of names from the current scope, e.g. locals and imported items. | 1 | //! Completion of names from the current scope, e.g. locals and imported items. |
2 | 2 | ||
3 | use hir::ScopeDef; | 3 | use hir::ScopeDef; |
4 | use syntax::AstNode; | ||
5 | 4 | ||
6 | use crate::{CompletionContext, Completions}; | 5 | use crate::{CompletionContext, Completions}; |
7 | 6 | ||
@@ -24,6 +23,15 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
24 | return; | 23 | return; |
25 | } | 24 | } |
26 | 25 | ||
26 | if ctx.expects_use_tree() { | ||
27 | cov_mark::hit!(only_completes_modules_in_import); | ||
28 | ctx.scope.process_all_names(&mut |name, res| { | ||
29 | if let ScopeDef::ModuleDef(hir::ModuleDef::Module(_)) = res { | ||
30 | acc.add_resolution(ctx, name.to_string(), &res); | ||
31 | } | ||
32 | }); | ||
33 | return; | ||
34 | } | ||
27 | if let Some(hir::Adt::Enum(e)) = | 35 | if let Some(hir::Adt::Enum(e)) = |
28 | ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) | 36 | ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) |
29 | { | 37 | { |
@@ -37,14 +45,6 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
37 | cov_mark::hit!(skip_lifetime_completion); | 45 | cov_mark::hit!(skip_lifetime_completion); |
38 | return; | 46 | return; |
39 | } | 47 | } |
40 | if ctx.use_item_syntax.is_some() { | ||
41 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { | ||
42 | if name_ref.syntax().text() == name.to_string().as_str() { | ||
43 | cov_mark::hit!(self_fulfilling_completion); | ||
44 | return; | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | acc.add_resolution(ctx, name.to_string(), &res); | 48 | acc.add_resolution(ctx, name.to_string(), &res); |
49 | }); | 49 | }); |
50 | } | 50 | } |
@@ -68,15 +68,17 @@ mod tests { | |||
68 | } | 68 | } |
69 | 69 | ||
70 | #[test] | 70 | #[test] |
71 | fn self_fulfilling_completion() { | 71 | fn only_completes_modules_in_import() { |
72 | cov_mark::check!(self_fulfilling_completion); | 72 | cov_mark::check!(only_completes_modules_in_import); |
73 | check( | 73 | check( |
74 | r#" | 74 | r#" |
75 | use foo$0 | 75 | use f$0 |
76 | use std::collections; | 76 | |
77 | struct Foo; | ||
78 | mod foo {} | ||
77 | "#, | 79 | "#, |
78 | expect![[r#" | 80 | expect![[r#" |
79 | ?? collections | 81 | md foo |
80 | "#]], | 82 | "#]], |
81 | ); | 83 | ); |
82 | } | 84 | } |