@@ -34,6 +34,7 @@ class TreeSitterIdentifierFinder(IdentifierFinder):
3434 """
3535
3636 def __init__ (self , fname : str , source : str | Sequence [str ], parent_restriction : ParentRestriction = None ):
37+ super ().__init__ ()
3738 self .parent_restriction = parent_restriction
3839 match source :
3940 case str () as s :
@@ -65,6 +66,7 @@ def __call__(
6566 # Returns IdentifierBoundaries
6667 return self ._find_identifier (marker , parent_restriction )
6768
69+
6870 def _find_identifier (self ,
6971 marker : Marker ,
7072 parent_restriction : ParentRestriction
@@ -84,39 +86,16 @@ def _find_identifier(self,
8486 """
8587 query_info_key = marker .type
8688 identifier_name = marker .value
87- match marker .type :
88- case 'method' :
89- query_info_key = 'function'
9089 try :
9190 all_restrictions : list [ParentRestriction ] = [parent_restriction ]
9291 # Extract parent name if using dot notation
9392 if '.' in identifier_name :
9493 * parent_parts , identifier_name = identifier_name .split ('.' )
9594 all_restrictions .append ("." + '.' .join (reversed (parent_parts )))
9695
96+ identifier_type = marker .type
9797 # Get all node candidates first
98- candidate_nodes = (
99- self .language .query (self .query_info [query_info_key ].format (name = identifier_name ))
100- .captures (self .tree .root_node )
101- )
102- if not candidate_nodes :
103- return None
104-
105- # Convert captures to boundaries and filter by parent
106- candidates : list [IdentifierBoundaries ] = []
107- for ib in capture2identifier_boundaries (candidate_nodes , self .lines ):
108- # For methods, verify the immediate parent is a class
109- if marker .type == 'method' :
110- if not ib .parents or not ib .parents [0 ].parent_type .startswith ('class' ):
111- continue
112- # Check parent restriction (e.g., specific class name)
113- candidate_matched_all_restrictions = True
114- for pr in all_restrictions :
115- if not ib .match_parent (pr ):
116- candidate_matched_all_restrictions = False
117- break
118- if candidate_matched_all_restrictions :
119- candidates .append (ib )
98+ candidates = self .find_identifiers (query_info_key , identifier_name , all_restrictions )
12099 except Exception as e :
121100 raise ValueError (f"Unable to capture nodes for { marker } : { e } " ) from e
122101
@@ -141,6 +120,34 @@ def _find_identifier(self,
141120 return result .location_to_search_range (relative_position_type )
142121 return result
143122
123+ def find_identifiers (
124+ self , identifier_type : str , name : str , all_restrictions : list [ParentRestriction ] = []
125+ ) -> list [IdentifierBoundaries ]:
126+ if not self .language :
127+ return []
128+ match identifier_type :
129+ case 'method' :
130+ identifier_type = 'function'
131+ candidate_nodes = self .language .query (self .query_info [identifier_type ].format (name = name )).captures (self .tree .root_node )
132+ if not candidate_nodes :
133+ return []
134+ # Convert captures to boundaries and filter by parent
135+ candidates : list [IdentifierBoundaries ] = []
136+ for ib in capture2identifier_boundaries (candidate_nodes , self .lines ):
137+ # For methods, verify the immediate parent is a class
138+ if identifier_type == 'method' :
139+ if not ib .parents or not ib .parents [0 ].parent_type .startswith ('class' ):
140+ continue
141+ # Check parent restriction (e.g., specific class name)
142+ candidate_matched_all_restrictions = True
143+ for pr in all_restrictions :
144+ if not ib .match_parent (pr ):
145+ candidate_matched_all_restrictions = False
146+ break
147+ if candidate_matched_all_restrictions :
148+ candidates .append (ib )
149+ return candidates
150+
144151
145152def _get_by_offset (obj : Sequence , offset : int ):
146153 if 0 <= offset < len (obj ):
0 commit comments