@@ -33,6 +33,7 @@ pub(crate) enum PatternRefutability {
3333 Irrefutable ,
3434}
3535
36+ #[ derive( Debug ) ]
3637pub ( crate ) enum Visible {
3738 Yes ,
3839 Editable ,
@@ -355,10 +356,11 @@ pub(crate) struct CompletionContext<'a> {
355356
356357 pub ( super ) locals : FxHashMap < Name , Local > ,
357358
359+ /// The module depth of the current module of the cursor position.
358360 /// - crate-root
359361 /// - mod foo
360362 /// - mod bar
361- /// Here depth will be 2: {[bar<->foo], [foo<->crate-root]}
363+ /// Here depth will be 2
362364 pub ( super ) depth_from_crate_root : usize ,
363365}
364366
@@ -383,6 +385,30 @@ impl<'a> CompletionContext<'a> {
383385 FamousDefs ( & self . sema , self . krate )
384386 }
385387
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+
386412 /// Checks if an item is visible and not `doc(hidden)` at the completion site.
387413 pub ( crate ) fn is_visible < I > ( & self , item : & I ) -> Visible
388414 where
@@ -393,14 +419,6 @@ impl<'a> CompletionContext<'a> {
393419 self . is_visible_impl ( & vis, & attrs, item. krate ( self . db ) )
394420 }
395421
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-
404422 /// Check if an item is `#[doc(hidden)]`.
405423 pub ( crate ) fn is_item_hidden ( & self , item : & hir:: ItemInNs ) -> bool {
406424 let attrs = item. attrs ( self . db ) ;
@@ -468,6 +486,14 @@ impl<'a> CompletionContext<'a> {
468486 self . scope . process_all_names ( & mut |name, def| f ( name, def) ) ;
469487 }
470488
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+
471497 fn is_visible_impl (
472498 & self ,
473499 vis : & hir:: Visibility ,
0 commit comments