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

@@ -21,6 +21,8 @@ from src import log_registry
from src import log_pruner
from src import models
from src import app_controller
from src import mcp_client
import re
from pydantic import BaseModel
from imgui_bundle import imgui, hello_imgui, immapp, imgui_node_editor as ed
@@ -1404,7 +1406,33 @@ class App:
if read_mode:
imgui.begin_child("read_content", imgui.ImVec2(0, 150), True)
if self.ui_word_wrap: imgui.push_text_wrap_pos(imgui.get_content_region_avail().x)
imgui.text(entry["content"])
content = entry["content"]
last_idx = 0
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
for match in pattern.finditer(content):
before = content[last_idx:match.start()]
if before: imgui.text(before)
header_text = match.group(0).split("\n")[0].strip()
path = match.group(2)
code_block = match.group(4)
if imgui.collapsing_header(header_text):
if imgui.button(f"[Source]##{i}_{match.start()}"):
res = mcp_client.read_file(path)
if res:
self.text_viewer_title = path
self.text_viewer_content = res
self.show_text_viewer = True
if code_block:
code_content = code_block.strip()
if code_content.count("\n") + 1 > 50:
imgui.begin_child(f"code_{i}_{match.start()}", imgui.ImVec2(0, 200), True)
imgui.text(code_content)
imgui.end_child()
else:
imgui.text(code_content)
last_idx = match.end()
after = content[last_idx:]
if after: imgui.text(after)
if self.ui_word_wrap: imgui.pop_text_wrap_pos()
imgui.end_child()
else: