feat(gui): Implement on-demand definition lookup with clickable navigation and collapsing

This commit is contained in:
2026-03-07 15:20:39 -05:00
parent 0c2df6c188
commit 7ea833e2d3
8 changed files with 245 additions and 17 deletions

View File

@@ -384,6 +384,32 @@ def _get_symbol_node(tree: ast.AST, name: str) -> Optional[ast.AST]:
current = found
return current
def py_get_symbol_info(path: str, name: str) -> tuple[str, int] | str:
"""
Returns (source_code, line_number) for a specific class, function, or method definition.
If not found, returns an error string.
"""
p, err = _resolve_and_check(path)
if err:
return err
assert p is not None
if not p.exists():
return f"ERROR: file not found: {path}"
if not p.is_file():
return f"ERROR: not a file: {path}"
try:
code = p.read_text(encoding="utf-8").lstrip(chr(0xFEFF))
lines = code.splitlines(keepends=True)
tree = ast.parse(code)
node = _get_symbol_node(tree, name)
if node:
start = cast(int, getattr(node, "lineno"))
end = cast(int, getattr(node, "end_lineno"))
return ("".join(lines[start-1:end]), start)
return f"ERROR: definition '{name}' not found in {path}"
except Exception as e:
return f"ERROR retrieving definition '{name}' from '{path}': {e}"
def py_get_definition(path: str, name: str) -> str:
"""
Returns the source code for a specific class, function, or method definition.