diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/completion/complete_unqualified_path.rs | 40 | ||||
-rw-r--r-- | crates/ra_ide/src/marks.rs | 1 |
2 files changed, 40 insertions, 1 deletions
diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index 2d8e0776c..ad5fdcc4e 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs | |||
@@ -1,6 +1,10 @@ | |||
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; | ||
4 | use test_utils::tested_by; | ||
5 | |||
3 | use crate::completion::{CompletionContext, Completions}; | 6 | use crate::completion::{CompletionContext, Completions}; |
7 | use ra_syntax::AstNode; | ||
4 | 8 | ||
5 | pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { | 9 | pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { |
6 | if !ctx.is_trivial_path { | 10 | if !ctx.is_trivial_path { |
@@ -14,12 +18,23 @@ pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC | |||
14 | return; | 18 | return; |
15 | } | 19 | } |
16 | 20 | ||
17 | ctx.scope().process_all_names(&mut |name, res| acc.add_resolution(ctx, name.to_string(), &res)); | 21 | ctx.scope().process_all_names(&mut |name, res| { |
22 | if ctx.use_item_syntax.is_some() { | ||
23 | if let (ScopeDef::Unknown, Some(name_ref)) = (&res, &ctx.name_ref_syntax) { | ||
24 | if name_ref.syntax().text() == name.to_string().as_str() { | ||
25 | tested_by!(self_fulfilling_completion); | ||
26 | return; | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | acc.add_resolution(ctx, name.to_string(), &res) | ||
31 | }); | ||
18 | } | 32 | } |
19 | 33 | ||
20 | #[cfg(test)] | 34 | #[cfg(test)] |
21 | mod tests { | 35 | mod tests { |
22 | use insta::assert_debug_snapshot; | 36 | use insta::assert_debug_snapshot; |
37 | use test_utils::covers; | ||
23 | 38 | ||
24 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | 39 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; |
25 | 40 | ||
@@ -28,6 +43,29 @@ mod tests { | |||
28 | } | 43 | } |
29 | 44 | ||
30 | #[test] | 45 | #[test] |
46 | fn self_fulfilling_completion() { | ||
47 | covers!(self_fulfilling_completion); | ||
48 | assert_debug_snapshot!( | ||
49 | do_reference_completion( | ||
50 | r#" | ||
51 | use foo<|> | ||
52 | use std::collections; | ||
53 | "#, | ||
54 | ), | ||
55 | @r###" | ||
56 | [ | ||
57 | CompletionItem { | ||
58 | label: "collections", | ||
59 | source_range: [21; 24), | ||
60 | delete: [21; 24), | ||
61 | insert: "collections", | ||
62 | }, | ||
63 | ] | ||
64 | "### | ||
65 | ); | ||
66 | } | ||
67 | |||
68 | #[test] | ||
31 | fn bind_pat_and_path_ignore_at() { | 69 | fn bind_pat_and_path_ignore_at() { |
32 | assert_debug_snapshot!( | 70 | assert_debug_snapshot!( |
33 | do_reference_completion( | 71 | do_reference_completion( |
diff --git a/crates/ra_ide/src/marks.rs b/crates/ra_ide/src/marks.rs index 5e1f135c5..eee44e886 100644 --- a/crates/ra_ide/src/marks.rs +++ b/crates/ra_ide/src/marks.rs | |||
@@ -8,4 +8,5 @@ test_utils::marks!( | |||
8 | test_resolve_parent_module_on_module_decl | 8 | test_resolve_parent_module_on_module_decl |
9 | search_filters_by_range | 9 | search_filters_by_range |
10 | dont_insert_macro_call_parens_unncessary | 10 | dont_insert_macro_call_parens_unncessary |
11 | self_fulfilling_completion | ||
11 | ); | 12 | ); |