feat(context): Interactive AST Tree Masking with per-symbol toggles

This commit is contained in:
2026-05-10 13:28:15 -04:00
parent 6c83d097b1
commit b4f8633bd6
4 changed files with 127 additions and 3 deletions
+92
View File
@@ -239,6 +239,9 @@ class App:
self.shader_uniforms = {'crt': 1.0, 'scanline': 0.5, 'bloom': 0.8}
self.ui_new_context_preset_name = ""
self._focus_md_cache: dict[str, str] = {}
self.ui_inspecting_ast_file = None
self._cached_ast_nodes = []
self._cached_ast_file_path = ''
"""UI-level wrapper for approving a pending tool execution ask."""
self._handle_approve_ask()
@@ -1337,6 +1340,9 @@ class App:
if imgui.button("Cancel", imgui.ImVec2(120, 0)):
imgui.close_current_popup()
imgui.end_popup()
self._render_ast_inspector_modal()
except Exception as e:
print(f"ERROR in _gui_func: {e}")
traceback.print_exc()
@@ -1469,6 +1475,86 @@ class App:
imgui.close_current_popup()
imgui.end_popup()
def _render_ast_inspector_modal(self) -> None:
expanded, opened = imgui.begin_popup_modal('AST Inspector', True, imgui.WindowFlags_.always_auto_resize)
if expanded:
if self.ui_inspecting_ast_file is None:
imgui.close_current_popup()
else:
f_item = self.ui_inspecting_ast_file
f_path = f_item.path if hasattr(f_item, "path") else str(f_item)
if f_path != self._cached_ast_file_path:
outline = ""
try:
if f_path.lower().endswith('.py'):
outline = mcp_client.py_get_code_outline(f_path)
elif f_path.lower().endswith(('.c', '.h')):
outline = mcp_client.ts_c_get_code_outline(f_path)
else:
outline = mcp_client.ts_cpp_get_code_outline(f_path)
except Exception as e:
outline = f"Error fetching outline: {e}"
self._cached_ast_nodes = []
import re
pattern = re.compile(r'^(\s*)\[(.*?)\] (.*?) \(Lines \d+-\d+\)')
stack = [] # (indent, name)
for line in outline.splitlines():
m = pattern.match(line)
if m:
indent_str, kind, name = m.groups()
indent = len(indent_str)
while stack and stack[-1][0] >= indent:
stack.pop()
stack.append((indent, name))
full_path = '::'.join([s[1] for s in stack])
self._cached_ast_nodes.append({
'indent': indent,
'kind': kind,
'name': name,
'full_path': full_path
})
self._cached_ast_file_path = f_path
imgui.text(f"Inspecting AST: {f_path}")
imgui.separator()
imgui.begin_child("ast_tree_scroll", imgui.ImVec2(800, 600), True)
if not self._cached_ast_nodes:
imgui.text("No AST nodes found or error fetching outline.")
else:
for node in self._cached_ast_nodes:
indent = node['indent']
kind = node['kind']
name = node['name']
full_path = node['full_path']
imgui.dummy(imgui.ImVec2(indent * 10, 0))
imgui.same_line()
imgui.text(f"[{kind}] {name}")
imgui.same_line(imgui.get_window_width() - 200)
current_mode = f_item.ast_mask.get(full_path, 'hide')
imgui.push_id(full_path)
if imgui.radio_button("Def", current_mode == 'def'):
f_item.ast_mask[full_path] = 'def'
imgui.same_line()
if imgui.radio_button("Sig", current_mode == 'sig'):
f_item.ast_mask[full_path] = 'sig'
imgui.same_line()
if imgui.radio_button("Hide", current_mode == 'hide'):
f_item.ast_mask[full_path] = 'hide'
imgui.pop_id()
imgui.end_child()
imgui.separator()
if imgui.button("Close", imgui.ImVec2(120, 0)):
self.ui_inspecting_ast_file = None
imgui.close_current_popup()
imgui.end_popup()
def _render_save_workspace_profile_modal(self) -> None:
if self._show_save_workspace_profile_modal:
imgui.open_popup("Save Workspace Profile")
@@ -2619,6 +2705,12 @@ class App:
imgui.same_line()
imgui.text(f_path)
if f_path.lower().endswith(('.c', '.cpp', '.h', '.hpp', '.cxx', '.cc')):
imgui.same_line()
if imgui.button(f"[Inspect]##{i}"):
self.ui_inspecting_ast_file = f_item
imgui.open_popup('AST Inspector')
imgui.table_set_column_index(1)
if hasattr(f_item, "auto_aggregate"):
changed_agg, f_item.auto_aggregate = imgui.checkbox(f"Agg##cc{i}", f_item.auto_aggregate)