1
1
//! Completion of paths, including when writing a single name.
2
2
3
- use hir:: { Adt , PathResolution , ScopeDef } ;
3
+ use hir:: { Adt , PathResolution , ScopeDef , HasVisibility } ;
4
4
use ra_syntax:: AstNode ;
5
5
use test_utils:: tested_by;
6
6
@@ -15,9 +15,10 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
15
15
Some ( PathResolution :: Def ( def) ) => def,
16
16
_ => return ,
17
17
} ;
18
+ let context_module = ctx. scope ( ) . module ( ) ;
18
19
match def {
19
20
hir:: ModuleDef :: Module ( module) => {
20
- let module_scope = module. scope ( ctx. db ) ;
21
+ let module_scope = module. scope ( ctx. db , context_module ) ;
21
22
for ( name, def) in module_scope {
22
23
if ctx. use_item_syntax . is_some ( ) {
23
24
if let ScopeDef :: Unknown = def {
@@ -53,7 +54,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
53
54
ty. iterate_path_candidates ( ctx. db , krate, & traits_in_scope, None , |_ty, item| {
54
55
match item {
55
56
hir:: AssocItem :: Function ( func) => {
56
- if !func. has_self_param ( ctx. db ) {
57
+ if !func. has_self_param ( ctx. db ) && context_module . map_or ( true , |m| func . is_visible_from ( ctx . db , m ) ) {
57
58
acc. add_function ( ctx, func) ;
58
59
}
59
60
}
@@ -169,6 +170,41 @@ mod tests {
169
170
) ;
170
171
}
171
172
173
+ #[ test]
174
+ fn path_visibility ( ) {
175
+ assert_debug_snapshot ! (
176
+ do_reference_completion(
177
+ r"
178
+ use self::my::<|>;
179
+
180
+ mod my {
181
+ struct Bar;
182
+ pub struct Foo;
183
+ pub use Bar as PublicBar;
184
+ }
185
+ "
186
+ ) ,
187
+ @r###"
188
+ [
189
+ CompletionItem {
190
+ label: "Foo",
191
+ source_range: [31; 31),
192
+ delete: [31; 31),
193
+ insert: "Foo",
194
+ kind: Struct,
195
+ },
196
+ CompletionItem {
197
+ label: "PublicBar",
198
+ source_range: [31; 31),
199
+ delete: [31; 31),
200
+ insert: "PublicBar",
201
+ kind: Struct,
202
+ },
203
+ ]
204
+ "###
205
+ ) ;
206
+ }
207
+
172
208
#[ test]
173
209
fn completes_use_item_starting_with_self ( ) {
174
210
assert_debug_snapshot ! (
@@ -177,7 +213,7 @@ mod tests {
177
213
use self::m::<|>;
178
214
179
215
mod m {
180
- struct Bar;
216
+ pub struct Bar;
181
217
}
182
218
"
183
219
) ,
0 commit comments