fix(gui): properly handle AST Inspector popup state
- Add _show_ast_inspector flag to track when popup should open - Use same pattern as other modals (_show_* flag + open_popup) - Restructure if/else to properly handle end_popup paths - This fixes the Inspect button not opening the modal
This commit is contained in:
+1
-1
@@ -56,7 +56,7 @@ Theme = true
|
|||||||
Diagnostics = false
|
Diagnostics = false
|
||||||
"External Tools" = false
|
"External Tools" = false
|
||||||
"Shader Editor" = false
|
"Shader Editor" = false
|
||||||
"Undo/Redo History" = true
|
"Undo/Redo History" = false
|
||||||
|
|
||||||
[theme]
|
[theme]
|
||||||
palette = "Nord Dark"
|
palette = "Nord Dark"
|
||||||
|
|||||||
+10
-10
@@ -75,7 +75,7 @@ DockId=0xAFC85805,2
|
|||||||
|
|
||||||
[Window][Theme]
|
[Window][Theme]
|
||||||
Pos=0,28
|
Pos=0,28
|
||||||
Size=1109,1750
|
Size=1412,1729
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000005,3
|
DockId=0x00000005,3
|
||||||
|
|
||||||
@@ -102,26 +102,26 @@ Collapsed=0
|
|||||||
DockId=0x0000000D,0
|
DockId=0x0000000D,0
|
||||||
|
|
||||||
[Window][Discussion Hub]
|
[Window][Discussion Hub]
|
||||||
Pos=1111,28
|
Pos=1414,28
|
||||||
Size=1154,1750
|
Size=1154,1729
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000006,0
|
DockId=0x00000006,0
|
||||||
|
|
||||||
[Window][Operations Hub]
|
[Window][Operations Hub]
|
||||||
Pos=0,28
|
Pos=0,28
|
||||||
Size=1109,1750
|
Size=1412,1729
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000005,2
|
DockId=0x00000005,2
|
||||||
|
|
||||||
[Window][Files & Media]
|
[Window][Files & Media]
|
||||||
Pos=1111,28
|
Pos=1414,28
|
||||||
Size=1154,1750
|
Size=1154,1729
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000006,1
|
DockId=0x00000006,1
|
||||||
|
|
||||||
[Window][AI Settings]
|
[Window][AI Settings]
|
||||||
Pos=0,28
|
Pos=0,28
|
||||||
Size=1109,1750
|
Size=1412,1729
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000005,0
|
DockId=0x00000005,0
|
||||||
|
|
||||||
@@ -407,7 +407,7 @@ DockId=0x00000006,1
|
|||||||
|
|
||||||
[Window][Project Settings]
|
[Window][Project Settings]
|
||||||
Pos=0,28
|
Pos=0,28
|
||||||
Size=1109,1750
|
Size=1412,1729
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000005,1
|
DockId=0x00000005,1
|
||||||
|
|
||||||
@@ -591,11 +591,11 @@ Column 4 Width=70
|
|||||||
DockNode ID=0x00000008 Pos=3125,170 Size=593,1157 Split=Y
|
DockNode ID=0x00000008 Pos=3125,170 Size=593,1157 Split=Y
|
||||||
DockNode ID=0x00000009 Parent=0x00000008 SizeRef=1029,147 Selected=0x0469CA7A
|
DockNode ID=0x00000009 Parent=0x00000008 SizeRef=1029,147 Selected=0x0469CA7A
|
||||||
DockNode ID=0x0000000A Parent=0x00000008 SizeRef=1029,145 Selected=0xDF822E02
|
DockNode ID=0x0000000A Parent=0x00000008 SizeRef=1029,145 Selected=0xDF822E02
|
||||||
DockSpace ID=0xAFC85805 Window=0x079D3A04 Pos=0,28 Size=2727,1750 Split=X
|
DockSpace ID=0xAFC85805 Window=0x079D3A04 Pos=0,28 Size=2568,1729 Split=X
|
||||||
DockNode ID=0x00000003 Parent=0xAFC85805 SizeRef=2254,1183 Split=X
|
DockNode ID=0x00000003 Parent=0xAFC85805 SizeRef=2254,1183 Split=X
|
||||||
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=404,1186 Split=X Selected=0xF4139CA2
|
DockNode ID=0x0000000B Parent=0x00000003 SizeRef=404,1186 Split=X Selected=0xF4139CA2
|
||||||
DockNode ID=0x00000007 Parent=0x0000000B SizeRef=1512,858 Split=X Selected=0x8CA2375C
|
DockNode ID=0x00000007 Parent=0x0000000B SizeRef=1512,858 Split=X Selected=0x8CA2375C
|
||||||
DockNode ID=0x00000005 Parent=0x00000007 SizeRef=1109,1681 CentralNode=1 Selected=0x7BD57D6A
|
DockNode ID=0x00000005 Parent=0x00000007 SizeRef=1109,1681 CentralNode=1 Selected=0x418C7449
|
||||||
DockNode ID=0x00000006 Parent=0x00000007 SizeRef=1154,1681 Selected=0x6F2B5B04
|
DockNode ID=0x00000006 Parent=0x00000007 SizeRef=1154,1681 Selected=0x6F2B5B04
|
||||||
DockNode ID=0x0000000E Parent=0x0000000B SizeRef=1777,858 Selected=0x1D56B311
|
DockNode ID=0x0000000E Parent=0x0000000B SizeRef=1777,858 Selected=0x1D56B311
|
||||||
DockNode ID=0x0000000D Parent=0x00000003 SizeRef=435,1186 Selected=0x363E93D6
|
DockNode ID=0x0000000D Parent=0x00000003 SizeRef=435,1186 Selected=0x363E93D6
|
||||||
|
|||||||
+83
-76
@@ -240,6 +240,7 @@ class App:
|
|||||||
self.ui_new_context_preset_name = ""
|
self.ui_new_context_preset_name = ""
|
||||||
self._focus_md_cache: dict[str, str] = {}
|
self._focus_md_cache: dict[str, str] = {}
|
||||||
self.ui_inspecting_ast_file = None
|
self.ui_inspecting_ast_file = None
|
||||||
|
self._show_ast_inspector = False
|
||||||
self._cached_ast_nodes = []
|
self._cached_ast_nodes = []
|
||||||
self._cached_ast_file_path = ''
|
self._cached_ast_file_path = ''
|
||||||
self.ui_editing_slices_file = None
|
self.ui_editing_slices_file = None
|
||||||
@@ -1663,84 +1664,89 @@ class App:
|
|||||||
imgui.end_popup()
|
imgui.end_popup()
|
||||||
|
|
||||||
def _render_ast_inspector_modal(self) -> None:
|
def _render_ast_inspector_modal(self) -> None:
|
||||||
|
if self._show_ast_inspector:
|
||||||
|
imgui.open_popup('AST Inspector')
|
||||||
|
self._show_ast_inspector = False
|
||||||
expanded, opened = imgui.begin_popup_modal('AST Inspector', True, imgui.WindowFlags_.always_auto_resize)
|
expanded, opened = imgui.begin_popup_modal('AST Inspector', True, imgui.WindowFlags_.always_auto_resize)
|
||||||
if expanded:
|
if not opened:
|
||||||
if self.ui_inspecting_ast_file is None:
|
return
|
||||||
imgui.close_current_popup()
|
if self.ui_inspecting_ast_file is None:
|
||||||
else:
|
imgui.close_current_popup()
|
||||||
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()
|
imgui.end_popup()
|
||||||
|
return
|
||||||
|
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:
|
def _render_save_workspace_profile_modal(self) -> None:
|
||||||
if self._show_save_workspace_profile_modal:
|
if self._show_save_workspace_profile_modal:
|
||||||
@@ -2902,6 +2908,7 @@ class App:
|
|||||||
imgui.same_line()
|
imgui.same_line()
|
||||||
if imgui.button(f"[Inspect]##{i}"):
|
if imgui.button(f"[Inspect]##{i}"):
|
||||||
self.ui_inspecting_ast_file = f_item
|
self.ui_inspecting_ast_file = f_item
|
||||||
|
self._show_ast_inspector = True
|
||||||
|
|
||||||
imgui.same_line()
|
imgui.same_line()
|
||||||
if imgui.button(f"[Slices]##{i}"):
|
if imgui.button(f"[Slices]##{i}"):
|
||||||
|
|||||||
Reference in New Issue
Block a user