@@ -33,6 +33,7 @@ pub(crate) enum PatternRefutability {
33
33
Irrefutable ,
34
34
}
35
35
36
+ #[ derive( Debug ) ]
36
37
pub ( crate ) enum Visible {
37
38
Yes ,
38
39
Editable ,
@@ -355,10 +356,11 @@ pub(crate) struct CompletionContext<'a> {
355
356
356
357
pub ( super ) locals : FxHashMap < Name , Local > ,
357
358
359
+ /// The module depth of the current module of the cursor position.
358
360
/// - crate-root
359
361
/// - mod foo
360
362
/// - mod bar
361
- /// Here depth will be 2: {[bar<->foo], [foo<->crate-root]}
363
+ /// Here depth will be 2
362
364
pub ( super ) depth_from_crate_root : usize ,
363
365
}
364
366
@@ -383,6 +385,30 @@ impl<'a> CompletionContext<'a> {
383
385
FamousDefs ( & self . sema , self . krate )
384
386
}
385
387
388
+ /// Checks if an item is visible and not `doc(hidden)` at the completion site.
389
+ pub ( crate ) fn def_is_visible ( & self , item : & ScopeDef ) -> Visible {
390
+ match item {
391
+ ScopeDef :: ModuleDef ( def) => match def {
392
+ hir:: ModuleDef :: Module ( it) => self . is_visible ( it) ,
393
+ hir:: ModuleDef :: Function ( it) => self . is_visible ( it) ,
394
+ hir:: ModuleDef :: Adt ( it) => self . is_visible ( it) ,
395
+ hir:: ModuleDef :: Variant ( it) => self . is_visible ( it) ,
396
+ hir:: ModuleDef :: Const ( it) => self . is_visible ( it) ,
397
+ hir:: ModuleDef :: Static ( it) => self . is_visible ( it) ,
398
+ hir:: ModuleDef :: Trait ( it) => self . is_visible ( it) ,
399
+ hir:: ModuleDef :: TypeAlias ( it) => self . is_visible ( it) ,
400
+ hir:: ModuleDef :: Macro ( it) => self . is_visible ( it) ,
401
+ hir:: ModuleDef :: BuiltinType ( _) => Visible :: Yes ,
402
+ } ,
403
+ ScopeDef :: GenericParam ( _)
404
+ | ScopeDef :: ImplSelfType ( _)
405
+ | ScopeDef :: AdtSelfType ( _)
406
+ | ScopeDef :: Local ( _)
407
+ | ScopeDef :: Label ( _)
408
+ | ScopeDef :: Unknown => Visible :: Yes ,
409
+ }
410
+ }
411
+
386
412
/// Checks if an item is visible and not `doc(hidden)` at the completion site.
387
413
pub ( crate ) fn is_visible < I > ( & self , item : & I ) -> Visible
388
414
where
@@ -393,14 +419,6 @@ impl<'a> CompletionContext<'a> {
393
419
self . is_visible_impl ( & vis, & attrs, item. krate ( self . db ) )
394
420
}
395
421
396
- pub ( crate ) fn is_scope_def_hidden ( & self , scope_def : ScopeDef ) -> bool {
397
- if let ( Some ( attrs) , Some ( krate) ) = ( scope_def. attrs ( self . db ) , scope_def. krate ( self . db ) ) {
398
- return self . is_doc_hidden ( & attrs, krate) ;
399
- }
400
-
401
- false
402
- }
403
-
404
422
/// Check if an item is `#[doc(hidden)]`.
405
423
pub ( crate ) fn is_item_hidden ( & self , item : & hir:: ItemInNs ) -> bool {
406
424
let attrs = item. attrs ( self . db ) ;
@@ -468,6 +486,14 @@ impl<'a> CompletionContext<'a> {
468
486
self . scope . process_all_names ( & mut |name, def| f ( name, def) ) ;
469
487
}
470
488
489
+ fn is_scope_def_hidden ( & self , scope_def : ScopeDef ) -> bool {
490
+ if let ( Some ( attrs) , Some ( krate) ) = ( scope_def. attrs ( self . db ) , scope_def. krate ( self . db ) ) {
491
+ return self . is_doc_hidden ( & attrs, krate) ;
492
+ }
493
+
494
+ false
495
+ }
496
+
471
497
fn is_visible_impl (
472
498
& self ,
473
499
vis : & hir:: Visibility ,
0 commit comments