diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion')
5 files changed, 121 insertions, 2 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index a673dbdcf..be839345f 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -180,6 +180,26 @@ mod tests { | |||
180 | } | 180 | } |
181 | 181 | ||
182 | #[test] | 182 | #[test] |
183 | fn test_method_attr_filtering() { | ||
184 | check_ref_completion( | ||
185 | "method_attr_filtering", | ||
186 | r" | ||
187 | struct A {} | ||
188 | impl A { | ||
189 | #[inline] | ||
190 | fn the_method(&self) { | ||
191 | let x = 1; | ||
192 | let y = 2; | ||
193 | } | ||
194 | } | ||
195 | fn foo(a: A) { | ||
196 | a.<|> | ||
197 | } | ||
198 | ", | ||
199 | ); | ||
200 | } | ||
201 | |||
202 | #[test] | ||
183 | fn test_tuple_field_completion() { | 203 | fn test_tuple_field_completion() { |
184 | check_ref_completion( | 204 | check_ref_completion( |
185 | "tuple_field_completion", | 205 | "tuple_field_completion", |
diff --git a/crates/ra_ide_api/src/completion/complete_fn_param.rs b/crates/ra_ide_api/src/completion/complete_fn_param.rs index 43532226f..4d6416284 100644 --- a/crates/ra_ide_api/src/completion/complete_fn_param.rs +++ b/crates/ra_ide_api/src/completion/complete_fn_param.rs | |||
@@ -7,7 +7,7 @@ use rustc_hash::FxHashMap; | |||
7 | 7 | ||
8 | use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem}; | 8 | use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem}; |
9 | 9 | ||
10 | /// Complete repeated parametes, both name and type. For example, if all | 10 | /// Complete repeated parameters, both name and type. For example, if all |
11 | /// functions in a file have a `spam: &mut Spam` parameter, a completion with | 11 | /// functions in a file have a `spam: &mut Spam` parameter, a completion with |
12 | /// `spam: &mut Spam` insert text/label and `spam` lookup string will be | 12 | /// `spam: &mut Spam` insert text/label and `spam` lookup string will be |
13 | /// suggested. | 13 | /// suggested. |
diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 445788407..eeaf26d93 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs | |||
@@ -4,7 +4,7 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { | |||
4 | if !ctx.is_trivial_path { | 4 | if !ctx.is_trivial_path { |
5 | return; | 5 | return; |
6 | } | 6 | } |
7 | let names = ctx.resolver.all_names(); | 7 | let names = ctx.resolver.all_names(ctx.db); |
8 | 8 | ||
9 | names.into_iter().for_each(|(name, res)| { | 9 | names.into_iter().for_each(|(name, res)| { |
10 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) | 10 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) |
@@ -165,4 +165,23 @@ mod tests { | |||
165 | fn completes_self_in_methods() { | 165 | fn completes_self_in_methods() { |
166 | check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }") | 166 | check_reference_completion("self_in_methods", r"impl S { fn foo(&self) { <|> } }") |
167 | } | 167 | } |
168 | |||
169 | #[test] | ||
170 | fn completes_prelude() { | ||
171 | check_reference_completion( | ||
172 | "completes_prelude", | ||
173 | " | ||
174 | //- /main.rs | ||
175 | fn foo() { let x: <|> } | ||
176 | |||
177 | //- /std/lib.rs | ||
178 | #[prelude_import] | ||
179 | use prelude::*; | ||
180 | |||
181 | mod prelude { | ||
182 | struct Option; | ||
183 | } | ||
184 | ", | ||
185 | ); | ||
186 | } | ||
168 | } | 187 | } |
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__completes_prelude.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__completes_prelude.snap new file mode 100644 index 000000000..2b5a1a8ea --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__completes_prelude.snap | |||
@@ -0,0 +1,54 @@ | |||
1 | --- | ||
2 | created: "2019-02-13T19:52:43.734834624Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | ||
5 | expression: kind_completions | ||
6 | --- | ||
7 | [ | ||
8 | CompletionItem { | ||
9 | completion_kind: Reference, | ||
10 | label: "Option", | ||
11 | kind: Some( | ||
12 | Struct | ||
13 | ), | ||
14 | detail: None, | ||
15 | documentation: None, | ||
16 | lookup: None, | ||
17 | insert_text: None, | ||
18 | insert_text_format: PlainText, | ||
19 | source_range: [18; 18), | ||
20 | text_edit: None | ||
21 | }, | ||
22 | CompletionItem { | ||
23 | completion_kind: Reference, | ||
24 | label: "foo", | ||
25 | kind: Some( | ||
26 | Function | ||
27 | ), | ||
28 | detail: Some( | ||
29 | "fn foo()" | ||
30 | ), | ||
31 | documentation: None, | ||
32 | lookup: None, | ||
33 | insert_text: Some( | ||
34 | "foo()$0" | ||
35 | ), | ||
36 | insert_text_format: Snippet, | ||
37 | source_range: [18; 18), | ||
38 | text_edit: None | ||
39 | }, | ||
40 | CompletionItem { | ||
41 | completion_kind: Reference, | ||
42 | label: "std", | ||
43 | kind: Some( | ||
44 | Module | ||
45 | ), | ||
46 | detail: None, | ||
47 | documentation: None, | ||
48 | lookup: None, | ||
49 | insert_text: None, | ||
50 | insert_text_format: PlainText, | ||
51 | source_range: [18; 18), | ||
52 | text_edit: None | ||
53 | } | ||
54 | ] | ||
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap new file mode 100644 index 000000000..46f9fa971 --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap | |||
@@ -0,0 +1,26 @@ | |||
1 | --- | ||
2 | created: "2019-02-12T18:32:09.428929418Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | ||
5 | expression: kind_completions | ||
6 | --- | ||
7 | [ | ||
8 | CompletionItem { | ||
9 | completion_kind: Reference, | ||
10 | label: "the_method", | ||
11 | kind: Some( | ||
12 | Method | ||
13 | ), | ||
14 | detail: Some( | ||
15 | "fn the_method(&self)" | ||
16 | ), | ||
17 | documentation: None, | ||
18 | lookup: None, | ||
19 | insert_text: Some( | ||
20 | "the_method()$0" | ||
21 | ), | ||
22 | insert_text_format: Snippet, | ||
23 | source_range: [249; 249), | ||
24 | text_edit: None | ||
25 | } | ||
26 | ] | ||