@@ -101,7 +101,6 @@ def _collect_function_nodes(self, node: Node, result: list[Node]) -> None:
101101 if node .type == "function_definition" :
102102 result .append (node )
103103 elif node .type == "decorated_definition" :
104- # For decorated definitions, the function_definition is a child
105104 for child in node .children :
106105 if child .type == "function_definition" :
107106 result .append (child )
@@ -145,12 +144,10 @@ def get_node_name(self, node: Node) -> str:
145144 Name string
146145 """
147146 if node .type == "function_definition" :
148- # Function name is in the first identifier child
149147 for child in node .children :
150148 if child .type == "identifier" :
151149 return child .text .decode ("utf-8" )
152150 elif node .type == "class_definition" :
153- # Class name is in the first identifier child
154151 for child in node .children :
155152 if child .type == "identifier" :
156153 return child .text .decode ("utf-8" )
@@ -169,7 +166,6 @@ def get_function_parameters(self, node: Node) -> list[dict[str, Any]]:
169166 """
170167 parameters = []
171168
172- # Find parameters node
173169 for child in node .children :
174170 if child .type == "parameters" :
175171 for param in child .children :
@@ -181,7 +177,6 @@ def get_function_parameters(self, node: Node) -> list[dict[str, Any]]:
181177 }
182178 )
183179 elif param .type == "typed_parameter" :
184- # Typed parameter: name: type
185180 name_node = None
186181 type_node = None
187182 for p_child in param .children :
@@ -197,7 +192,6 @@ def get_function_parameters(self, node: Node) -> list[dict[str, Any]]:
197192 }
198193 )
199194 elif param .type == "typed_default_parameter" :
200- # Typed default parameter: name: type = value
201195 name_node = None
202196 type_node = None
203197 for p_child in param .children :
@@ -214,14 +208,11 @@ def get_function_parameters(self, node: Node) -> list[dict[str, Any]]:
214208 }
215209 )
216210 elif param .type == "default_parameter" :
217- # Default parameter: name = value
218- name_node = param .child_by_field_name ("name" )
219- if name_node is None :
220- # Fallback: find identifier
221- for p_child in param .children :
222- if p_child .type == "identifier" :
223- name_node = p_child
224- break
211+ name_node = None
212+ for p_child in param .children :
213+ if p_child .type == "identifier" :
214+ name_node = p_child
215+ break
225216 if name_node :
226217 parameters .append (
227218 {
@@ -243,26 +234,12 @@ def get_function_return_type(self, node: Node) -> Optional[str]:
243234 Returns:
244235 Return type string or None
245236 """
246- for child in node .children :
247- if child .type == "type" :
248- # Check if this is a return type (comes after ->)
249- prev_sibling = None
250- for prev in node .children :
251- if prev is child :
252- break
253- prev_sibling = prev
254-
255- if prev_sibling and prev_sibling .type == "->" :
256- return child .text .decode ("utf-8" )
257-
258- # Alternative: look for -> followed by type
259237 found_arrow = False
260238 for child in node .children :
261239 if found_arrow and child .type == "type" :
262240 return child .text .decode ("utf-8" )
263241 if child .type == "->" :
264242 found_arrow = True
265-
266243 return None
267244
268245 def get_function_decorators (self , tree : Tree , node : Node ) -> list [str ]:
@@ -276,8 +253,6 @@ def get_function_decorators(self, tree: Tree, node: Node) -> list[str]:
276253 List of decorator names
277254 """
278255 decorators = []
279-
280- # Find the decorated_definition parent by walking the tree
281256 decorated_parent = self ._find_decorated_parent (tree , node )
282257
283258 if decorated_parent :
@@ -290,7 +265,6 @@ def get_function_decorators(self, tree: Tree, node: Node) -> list[str]:
290265 for call_child in dec_child .children :
291266 if call_child .type == "identifier" :
292267 decorators .append (call_child .text .decode ("utf-8" ))
293-
294268 return decorators
295269
296270 def _find_decorated_parent (self , tree : Tree , target_node : Node ) -> Optional [Node ]:
@@ -303,23 +277,10 @@ def _find_decorated_parent(self, tree: Tree, target_node: Node) -> Optional[Node
303277 Returns:
304278 decorated_definition node or None
305279 """
306-
307- def search (node : Node , parent : Optional [Node ]) -> Optional [Node ]:
308- if node is target_node :
309- return parent if parent and parent .type == "decorated_definition" else None
310-
311- for child in node .children :
312- result = search (child , node if node .type == "decorated_definition" else parent )
313- if result :
314- return result
315- return None
316-
317- # Special handling: check if target is inside a decorated_definition
318280 for child in tree .root_node .children :
319281 if child .type == "decorated_definition" :
320282 for grandchild in child .children :
321283 if grandchild .type == "function_definition" :
322- # Check if this is our target by comparing positions
323284 if (
324285 grandchild .start_point == target_node .start_point
325286 and grandchild .end_point == target_node .end_point
@@ -337,8 +298,6 @@ def get_class_bases(self, node: Node) -> list[Node]:
337298 List of base class nodes
338299 """
339300 bases = []
340-
341- # Look for argument_list after class name (contains base classes)
342301 found_name = False
343302 for child in node .children :
344303 if found_name :
@@ -350,7 +309,6 @@ def get_class_bases(self, node: Node) -> list[Node]:
350309 break
351310 elif child .type == "identifier" :
352311 found_name = True
353-
354312 return bases
355313
356314 def get_docstring (self , node : Node ) -> Optional [str ]:
@@ -362,15 +320,12 @@ def get_docstring(self, node: Node) -> Optional[str]:
362320 Returns:
363321 Docstring content or None
364322 """
365- # Look for expression_statement with string as first child in block
366323 for child in node .children :
367324 if child .type == "block" :
368- # First child of block might be docstring
369325 for block_child in child .children :
370326 if block_child .type == "expression_statement" :
371327 for expr_child in block_child .children :
372328 if expr_child .type == "string" :
373- # Get string_content from inside string
374329 for string_child in expr_child .children :
375330 if string_child .type == "string_content" :
376331 return string_child .text .decode ("utf-8" )
@@ -400,7 +355,6 @@ def _collect_nodes(self, node: Node, node_type: str, result: list[Node]) -> None
400355 """
401356 if node .type == node_type :
402357 result .append (node )
403-
404358 for child in node .children :
405359 self ._collect_nodes (child , node_type , result )
406360
@@ -426,7 +380,6 @@ def find_node_at_position(self, tree: Tree, line: int, column: int) -> Optional[
426380 Returns:
427381 Node at position or None
428382 """
429- # Convert to byte position (tree-sitter uses 0-based row, column)
430383 return tree .root_node .descendant_for_point_range ((line - 1 , column ), (line - 1 , column ))
431384
432385 def get_node_text (self , node : Node , source_code : bytes ) -> str :
@@ -473,61 +426,3 @@ def get_all_identifiers(self, tree: Tree) -> list[str]:
473426 for node in nodes :
474427 identifiers .append (node .text .decode ("utf-8" ))
475428 return identifiers
476-
477- def get_assignment_targets (self , tree : Tree ) -> list [dict [str , Any ]]:
478- """Get all assignment targets
479-
480- Args:
481- tree: Tree-sitter Tree
482-
483- Returns:
484- List of assignment info dictionaries
485- """
486- assignments = []
487- nodes = self .query_nodes (tree , "assignment" )
488-
489- for node in nodes :
490- left_node = node .child_by_field_name ("left" )
491- right_node = node .child_by_field_name ("right" )
492-
493- if left_node :
494- assignments .append (
495- {
496- "target" : left_node .text .decode ("utf-8" ),
497- "value" : right_node .text .decode ("utf-8" ) if right_node else None ,
498- "line" : node .start_point [0 ] + 1 ,
499- }
500- )
501-
502- return assignments
503-
504- def get_call_nodes (self , tree : Tree ) -> list [dict [str , Any ]]:
505- """Get all function call nodes
506-
507- Args:
508- tree: Tree-sitter Tree
509-
510- Returns:
511- List of call info dictionaries
512- """
513- calls = []
514- nodes = self .query_nodes (tree , "call" )
515-
516- for node in nodes :
517- func_node = node .child_by_field_name ("function" )
518- if func_node :
519- calls .append (
520- {
521- "function" : func_node .text .decode ("utf-8" ),
522- "line" : node .start_point [0 ] + 1 ,
523- "arguments" : [
524- arg .text .decode ("utf-8" )
525- for arg in node .child_by_field_name ("arguments" ).children
526- if arg .type != ","
527- ]
528- if node .child_by_field_name ("arguments" )
529- else [],
530- }
531- )
532-
533- return calls
0 commit comments