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