feat(mcp): Extract return type hints and ImGui scopes in code outline

This commit is contained in:
2026-05-13 17:22:34 -04:00
parent 8cbd232db0
commit 51be7d7405
2 changed files with 77 additions and 4 deletions
+35 -4
View File
@@ -53,7 +53,11 @@ class CodeOutliner:
return doc.splitlines()[0]
return None
count = [0]
def walk(node: ast.AST, indent: int = 0) -> None:
count[0] += 1
if count[0] > 100000:
raise Exception("Infinite loop detected! " + str(type(node)))
"""
[C: src/summarize.py:_summarise_python]
"""
@@ -70,15 +74,42 @@ class CodeOutliner:
start_line = node.lineno
end_line = getattr(node, "end_lineno", start_line)
prefix = "[Async Func]" if isinstance(node, ast.AsyncFunctionDef) else "[Func]"
# Check if it's a method
# We can check the indent or the parent, but in AST walk we know if we are inside a ClassDef
# Let's use a simpler heuristic for the outline: if indent > 0, it's likely a method.
if indent > 0:
prefix = "[Method]"
output.append(f"{' ' * indent}{prefix} {node.name} (Lines {start_line}-{end_line})")
returns = ""
if getattr(node, "returns", None):
try:
returns = f" -> {ast.unparse(node.returns)}"
except Exception:
pass
output.append(f"{' ' * indent}{prefix} {node.name}{returns} (Lines {start_line}-{end_line})")
doc = get_docstring(node)
if doc:
output.append(f"{' ' * (indent + 1)}\"\"\"{doc}\"\"\"")
for item in node.body:
walk(item, indent + 1)
elif isinstance(node, ast.With):
is_imgui = False
try:
for item in node.items:
ctx_str = ast.unparse(item.context_expr)
if "imscope." in ctx_str or "imgui." in ctx_str:
start_line = node.lineno
end_line = getattr(node, "end_lineno", start_line)
output.append(f"{' ' * indent}[ImGui Scope] {ctx_str} (Lines {start_line}-{end_line})")
is_imgui = True
break
except Exception:
pass
for item in node.body:
walk(item, indent + 1 if is_imgui else indent)
else:
for block_attr in ("body", "orelse", "handlers", "finalbody"):
block = getattr(node, block_attr, [])
if isinstance(block, list):
for item in block:
walk(item, indent)
for node in tree.body:
walk(node)
return "\n".join(output)