@@ -674,18 +674,12 @@ impl Search for DiscreteRange {
674674
675675impl Search for TypeDeclaration {
676676 fn search ( & mut self , searcher : & mut impl Searcher ) -> SearchResult {
677- if !matches ! ( self . def, TypeDefinition :: ProtectedBody ( _) ) {
678- return_if_found ! ( searcher
679- . search_decl( FoundDeclaration :: Type ( self ) )
680- . or_not_found( ) ) ;
681- }
677+ return_if_found ! ( searcher
678+ . search_decl( FoundDeclaration :: Type ( self ) )
679+ . or_not_found( ) ) ;
682680
683681 match self . def {
684682 TypeDefinition :: ProtectedBody ( ref mut body) => {
685- // Protected type body is not considered a declaration
686- return_if_found ! ( searcher
687- . search_pos_with_ref( self . ident. pos( ) , & mut body. type_reference)
688- . or_not_found( ) ) ;
689683 return_if_found ! ( body. decl. search( searcher) ) ;
690684 }
691685 TypeDefinition :: Protected ( ref mut prot_decl) => {
@@ -1318,6 +1312,37 @@ impl Searcher for ItemAtCursor {
13181312 }
13191313}
13201314
1315+ // Search for reference to declaration/definition at cursor
1316+ pub struct FindEnt < ' a , T : Fn ( EntRef < ' a > ) -> bool > {
1317+ root : & ' a DesignRoot ,
1318+ cond : T ,
1319+ pub result : Option < EntRef < ' a > > ,
1320+ }
1321+
1322+ impl < ' a , T : Fn ( EntRef < ' a > ) -> bool > FindEnt < ' a , T > {
1323+ pub fn new ( root : & ' a DesignRoot , cond : T ) -> FindEnt < ' a , T > {
1324+ FindEnt {
1325+ root,
1326+ cond,
1327+ result : None ,
1328+ }
1329+ }
1330+ }
1331+
1332+ impl < ' a , T : Fn ( EntRef < ' a > ) -> bool > Searcher for FindEnt < ' a , T > {
1333+ fn search_decl ( & mut self , decl : FoundDeclaration ) -> SearchState {
1334+ if let Some ( id) = decl. ent_id ( ) {
1335+ let ent = self . root . get_ent ( id) ;
1336+ if ( self . cond ) ( ent) {
1337+ self . result = Some ( ent) ;
1338+ return SearchState :: Finished ( SearchResult :: Found ) ;
1339+ }
1340+ }
1341+
1342+ SearchState :: NotFinished
1343+ }
1344+ }
1345+
13211346// Search for a declaration/definition and format it
13221347pub struct FormatDeclaration < ' a > {
13231348 ent : EntRef < ' a > ,
0 commit comments