diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_path.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 1eded7658..7413c71e8 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -15,7 +15,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
15 | hir::Def::Module(module) => { | 15 | hir::Def::Module(module) => { |
16 | let module_scope = module.scope(ctx.db); | 16 | let module_scope = module.scope(ctx.db); |
17 | for (name, res) in module_scope.entries() { | 17 | for (name, res) in module_scope.entries() { |
18 | CompletionItem::new(CompletionKind::Reference, name.to_string()) | 18 | CompletionItem::new(CompletionKind::Reference, ctx, name.to_string()) |
19 | .from_resolution(ctx, res) | 19 | .from_resolution(ctx, res) |
20 | .add_to(acc); | 20 | .add_to(acc); |
21 | } | 21 | } |
@@ -24,7 +24,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
24 | e.variants(ctx.db) | 24 | e.variants(ctx.db) |
25 | .into_iter() | 25 | .into_iter() |
26 | .for_each(|(variant_name, _variant)| { | 26 | .for_each(|(variant_name, _variant)| { |
27 | CompletionItem::new(CompletionKind::Reference, variant_name.to_string()) | 27 | CompletionItem::new(CompletionKind::Reference, ctx, variant_name.to_string()) |
28 | .kind(CompletionItemKind::EnumVariant) | 28 | .kind(CompletionItemKind::EnumVariant) |
29 | .add_to(acc) | 29 | .add_to(acc) |
30 | }); | 30 | }); |
@@ -35,7 +35,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
35 | 35 | ||
36 | #[cfg(test)] | 36 | #[cfg(test)] |
37 | mod tests { | 37 | mod tests { |
38 | use crate::completion::{CompletionKind, check_completion}; | 38 | use crate::completion::CompletionKind; |
39 | use crate::completion::completion_item::check_completion; | ||
39 | 40 | ||
40 | fn check_reference_completion(code: &str, expected_completions: &str) { | 41 | fn check_reference_completion(code: &str, expected_completions: &str) { |
41 | check_completion(code, expected_completions, CompletionKind::Reference); | 42 | check_completion(code, expected_completions, CompletionKind::Reference); |
@@ -44,6 +45,7 @@ mod tests { | |||
44 | #[test] | 45 | #[test] |
45 | fn completes_use_item_starting_with_self() { | 46 | fn completes_use_item_starting_with_self() { |
46 | check_reference_completion( | 47 | check_reference_completion( |
48 | "use_item_starting_with_self", | ||
47 | r" | 49 | r" |
48 | use self::m::<|>; | 50 | use self::m::<|>; |
49 | 51 | ||
@@ -51,13 +53,13 @@ mod tests { | |||
51 | struct Bar; | 53 | struct Bar; |
52 | } | 54 | } |
53 | ", | 55 | ", |
54 | "Bar", | ||
55 | ); | 56 | ); |
56 | } | 57 | } |
57 | 58 | ||
58 | #[test] | 59 | #[test] |
59 | fn completes_use_item_starting_with_crate() { | 60 | fn completes_use_item_starting_with_crate() { |
60 | check_reference_completion( | 61 | check_reference_completion( |
62 | "use_item_starting_with_crate", | ||
61 | " | 63 | " |
62 | //- /lib.rs | 64 | //- /lib.rs |
63 | mod foo; | 65 | mod foo; |
@@ -65,13 +67,13 @@ mod tests { | |||
65 | //- /foo.rs | 67 | //- /foo.rs |
66 | use crate::Sp<|> | 68 | use crate::Sp<|> |
67 | ", | 69 | ", |
68 | "Spam;foo", | ||
69 | ); | 70 | ); |
70 | } | 71 | } |
71 | 72 | ||
72 | #[test] | 73 | #[test] |
73 | fn completes_nested_use_tree() { | 74 | fn completes_nested_use_tree() { |
74 | check_reference_completion( | 75 | check_reference_completion( |
76 | "nested_use_tree", | ||
75 | " | 77 | " |
76 | //- /lib.rs | 78 | //- /lib.rs |
77 | mod foo; | 79 | mod foo; |
@@ -79,13 +81,13 @@ mod tests { | |||
79 | //- /foo.rs | 81 | //- /foo.rs |
80 | use crate::{Sp<|>}; | 82 | use crate::{Sp<|>}; |
81 | ", | 83 | ", |
82 | "Spam;foo", | ||
83 | ); | 84 | ); |
84 | } | 85 | } |
85 | 86 | ||
86 | #[test] | 87 | #[test] |
87 | fn completes_deeply_nested_use_tree() { | 88 | fn completes_deeply_nested_use_tree() { |
88 | check_reference_completion( | 89 | check_reference_completion( |
90 | "deeply_nested_use_tree", | ||
89 | " | 91 | " |
90 | //- /lib.rs | 92 | //- /lib.rs |
91 | mod foo; | 93 | mod foo; |
@@ -97,37 +99,37 @@ mod tests { | |||
97 | //- /foo.rs | 99 | //- /foo.rs |
98 | use crate::{bar::{baz::Sp<|>}}; | 100 | use crate::{bar::{baz::Sp<|>}}; |
99 | ", | 101 | ", |
100 | "Spam", | ||
101 | ); | 102 | ); |
102 | } | 103 | } |
103 | 104 | ||
104 | #[test] | 105 | #[test] |
105 | fn completes_enum_variant() { | 106 | fn completes_enum_variant() { |
106 | check_reference_completion( | 107 | check_reference_completion( |
108 | "reference_completion", | ||
107 | " | 109 | " |
108 | //- /lib.rs | 110 | //- /lib.rs |
109 | enum E { Foo, Bar(i32) } | 111 | enum E { Foo, Bar(i32) } |
110 | fn foo() { let _ = E::<|> } | 112 | fn foo() { let _ = E::<|> } |
111 | ", | 113 | ", |
112 | "Foo;Bar", | ||
113 | ); | 114 | ); |
114 | } | 115 | } |
115 | 116 | ||
116 | #[test] | 117 | #[test] |
117 | fn dont_render_function_parens_in_use_item() { | 118 | fn dont_render_function_parens_in_use_item() { |
118 | check_reference_completion( | 119 | check_reference_completion( |
120 | "dont_render_function_parens_in_use_item", | ||
119 | " | 121 | " |
120 | //- /lib.rs | 122 | //- /lib.rs |
121 | mod m { pub fn foo() {} } | 123 | mod m { pub fn foo() {} } |
122 | use crate::m::f<|>; | 124 | use crate::m::f<|>; |
123 | ", | 125 | ", |
124 | "foo", | ||
125 | ) | 126 | ) |
126 | } | 127 | } |
127 | 128 | ||
128 | #[test] | 129 | #[test] |
129 | fn dont_render_function_parens_if_already_call() { | 130 | fn dont_render_function_parens_if_already_call() { |
130 | check_reference_completion( | 131 | check_reference_completion( |
132 | "dont_render_function_parens_if_already_call", | ||
131 | " | 133 | " |
132 | //- /lib.rs | 134 | //- /lib.rs |
133 | fn frobnicate() {} | 135 | fn frobnicate() {} |
@@ -135,7 +137,6 @@ mod tests { | |||
135 | frob<|>(); | 137 | frob<|>(); |
136 | } | 138 | } |
137 | ", | 139 | ", |
138 | "main;frobnicate", | ||
139 | ) | 140 | ) |
140 | } | 141 | } |
141 | } | 142 | } |