9
9
from text_manipulation .range_spec import IdentifierBoundaries , RangeSpec , ParentInfo , ParentRestriction
10
10
from text_manipulation import IdentifierFinder
11
11
from tree_sitter_languages import get_language , get_parser
12
-
12
+ from pylibtreesitter import nodes_by_type_suffix
13
13
from .tree_sitter_identifier_queries import LANG_TO_TREE_SITTER_QUERY
14
14
15
15
"""
@@ -261,7 +261,11 @@ def find_parent_definition(node):
261
261
node = node .parent
262
262
if node .type .endswith ('_definition' ):
263
263
if node .type == 'decorated_definition' :
264
- node = node .named_children [0 ].next_named_sibling
264
+ node = nodes_by_type_suffix (node .named_children , '_definition' )
265
+ if node :
266
+ if len (node ) > 1 :
267
+ raise ValueError (f'{ len (node )} parent definitions found: { node } ' )
268
+ return node [0 ]
265
269
return node
266
270
return None
267
271
@@ -281,9 +285,11 @@ def capture2identifier_boundaries(captures, lines: Sequence[str]) -> list[Identi
281
285
for capture in captures :
282
286
unique_captures [f'{ capture .range [0 ]} :{ capture .capture_type } ' ] = capture
283
287
# unique_captures={
284
- # '157:function.decorator': CaptureInfo(capture_type='function.decorator', node=<Node type=decorator, start_point=(157, 4), end_point=(157, 17)>),
285
- # '158:function.definition': CaptureInfo(capture_type='function.definition', node=<Node type=function_definition, start_point=(158, 4), end_point=(207, 19)>),
286
- # '159:function.body': CaptureInfo(capture_type='function.body', node=<Node type=block, start_point=(159, 8), end_point=(207, 19)>)
288
+ # '14:function.definition': CaptureInfo(capture_type='function.definition', node=<Node type=function_definition, start_point=(14, 4), end_point=(22, 19)>),
289
+ # '12:function.decorator': CaptureInfo(capture_type='function.decorator', node=<Node type=decorator, start_point=(12, 4), end_point=(12, 17)>),
290
+ # '13:function.decorator': CaptureInfo(capture_type='function.decorator', node=<Node type=decorator, start_point=(13, 4), end_point=(13, 28)>),
291
+ # '15:function.body': CaptureInfo(capture_type='function.body', node=<Node type=block, start_point=(15, 8), end_point=(22, 19)>),
292
+ # '15:function.docstring': CaptureInfo(capture_type='function.docstring', node=<Node type=string, start_point=(15, 8), end_point=(15, 42)>)
287
293
# }
288
294
return associate_identifier_parts (sort_captures (unique_captures ), lines )
289
295
0 commit comments