feat(gui): Implement on-demand definition lookup with clickable navigation and collapsing
This commit is contained in:
@@ -46,11 +46,12 @@ def parse_symbols(text: str) -> list[str]:
|
||||
"""
|
||||
return re.findall(r"@([a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*)*)", text)
|
||||
|
||||
def get_symbol_definition(symbol: str, files: list[str]) -> tuple[str, str] | None:
|
||||
def get_symbol_definition(symbol: str, files: list[str]) -> tuple[str, str, int] | None:
|
||||
for file_path in files:
|
||||
result = mcp_client.py_get_definition(file_path, symbol)
|
||||
if 'not found' not in result.lower():
|
||||
return (file_path, result)
|
||||
result = mcp_client.py_get_symbol_info(file_path, symbol)
|
||||
if isinstance(result, tuple):
|
||||
source, line = result
|
||||
return (file_path, source, line)
|
||||
return None
|
||||
|
||||
class GenerateRequest(BaseModel):
|
||||
@@ -1827,6 +1828,15 @@ class AppController:
|
||||
self.last_file_items = file_items
|
||||
self._set_status("sending...")
|
||||
user_msg = self.ui_ai_input
|
||||
|
||||
symbols = parse_symbols(user_msg)
|
||||
file_paths = [f['path'] for f in file_items]
|
||||
for symbol in symbols:
|
||||
res = get_symbol_definition(symbol, file_paths)
|
||||
if res:
|
||||
file_path, definition, line = res
|
||||
user_msg += f'\n\n[Definition: {symbol} from {file_path} (line {line})]\n```python\n{definition}\n```'
|
||||
|
||||
base_dir = self.ui_files_base_dir
|
||||
sys.stderr.write(f"[DEBUG] _do_generate success. Prompt: {user_msg[:50]}...\n")
|
||||
sys.stderr.flush()
|
||||
|
||||
Reference in New Issue
Block a user