last progress before ending last session
This commit is contained in:
+49
-10
@@ -205,30 +205,69 @@ class ASTParser:
|
||||
"""
|
||||
[C: src/mcp_client.py:_search_file, src/mcp_client.py:py_find_usages, src/mcp_client.py:py_get_hierarchy, src/mcp_client.py:trace, src/outline_tool.py:CodeOutliner.outline, src/outline_tool.py:CodeOutliner.walk, src/summarize.py:_summarise_python]
|
||||
"""
|
||||
if node.type == "function_definition":
|
||||
body = node.child_by_field_name("body")
|
||||
if node.type in ("function_definition", "method_definition", "template_declaration"):
|
||||
# If template, look for inner function/method
|
||||
target_node = node
|
||||
if node.type == "template_declaration":
|
||||
for child in node.children:
|
||||
if child.type in ("function_definition", "method_definition"):
|
||||
target_node = child
|
||||
break
|
||||
|
||||
body = target_node.child_by_field_name("body")
|
||||
if not body:
|
||||
# C++ fallback: sometimes the body is just a compound_statement without a field name in certain contexts
|
||||
for child in target_node.children:
|
||||
if child.type in ("compound_statement", "block"):
|
||||
body = child
|
||||
break
|
||||
|
||||
if body and body.type in ("block", "compound_statement"):
|
||||
indent = " " * body.start_point.column
|
||||
first_stmt = None
|
||||
for child in body.children:
|
||||
if child.type != "comment":
|
||||
if child.type not in ("comment", "{", "}"):
|
||||
first_stmt = child
|
||||
break
|
||||
|
||||
initializer = None
|
||||
for child in node.children:
|
||||
if child.type == "field_initializer_list":
|
||||
initializer = child
|
||||
break
|
||||
if self.language_name in ("cpp", "c"):
|
||||
for child in target_node.children:
|
||||
if child.type == "field_initializer_list":
|
||||
initializer = child
|
||||
break
|
||||
|
||||
if first_stmt and is_docstring(first_stmt):
|
||||
start_byte = first_stmt.end_byte
|
||||
end_byte = body.end_byte
|
||||
if end_byte > start_byte:
|
||||
edits.append((start_byte, end_byte, f"\n{indent}..."))
|
||||
# Keep closing brace if it exists
|
||||
if body.children and body.children[-1].type in ("}", "end"):
|
||||
end_byte = body.children[-1].start_byte
|
||||
edits.append((start_byte, end_byte, f"\n{indent} ... "))
|
||||
else:
|
||||
edits.append((start_byte, end_byte, f"\n{indent}..."))
|
||||
else:
|
||||
# If there's an initializer list (C++), we strip it too or start from it
|
||||
start_byte = initializer.start_byte if initializer else body.start_byte
|
||||
end_byte = body.end_byte
|
||||
repl = "..."
|
||||
edits.append((start_byte, end_byte, repl))
|
||||
|
||||
# Try to preserve braces for C-style languages
|
||||
if body.type == "compound_statement" and len(body.children) >= 2:
|
||||
if body.children[0].type == "{" and body.children[-1].type == "}":
|
||||
start_byte = body.children[0].end_byte
|
||||
end_byte = body.children[-1].start_byte
|
||||
edits.append((start_byte, end_byte, " ... "))
|
||||
else:
|
||||
edits.append((start_byte, end_byte, "..."))
|
||||
else:
|
||||
edits.append((start_byte, end_byte, "..."))
|
||||
|
||||
if node.type == "template_declaration":
|
||||
# We handled the inner function body, so we should skip visiting its children
|
||||
# but we still want to visit other siblings if any (unlikely for template)
|
||||
pass
|
||||
|
||||
for child in node.children:
|
||||
walk(child)
|
||||
walk(tree.root_node)
|
||||
|
||||
Reference in New Issue
Block a user