mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-08 21:55:00 +00:00
Fix find files with symbol
This commit is contained in:
parent
646ed36527
commit
032a0e5d35
2 changed files with 47 additions and 15 deletions
|
@ -55,10 +55,12 @@ from aider.tools.undo_change import _execute_undo_change
|
|||
from aider.tools.list_changes import _execute_list_changes
|
||||
from aider.tools.extract_lines import _execute_extract_lines
|
||||
from aider.tools.view_numbered_context import execute_view_numbered_context
|
||||
from aider.tools.view_files_with_symbol import _execute_view_files_with_symbol # Import the function
|
||||
|
||||
|
||||
class NavigatorCoder(Coder):
|
||||
"""Mode where the LLM autonomously manages which files are in context."""
|
||||
|
||||
|
||||
edit_format = "navigator"
|
||||
gpt_prompts = NavigatorPrompts()
|
||||
|
||||
|
@ -719,9 +721,12 @@ class NavigatorCoder(Coder):
|
|||
elif norm_tool_name == 'viewfileswithsymbol':
|
||||
symbol = params.get('symbol')
|
||||
if symbol is not None:
|
||||
# Call the imported function from the tools directory
|
||||
result_message = _execute_view_files_with_symbol(self, symbol)
|
||||
else:
|
||||
result_message = "Error: Missing 'symbol' parameter for ViewFilesWithSymbol"
|
||||
|
||||
# Command tools
|
||||
elif norm_tool_name == 'command':
|
||||
command_string = params.get('command_string')
|
||||
if command_string is not None:
|
||||
|
|
|
@ -2,17 +2,43 @@ import os
|
|||
|
||||
def _execute_view_files_with_symbol(coder, symbol):
|
||||
"""
|
||||
Find files containing a specific symbol and add them to context as read-only.
|
||||
Find files containing a symbol using RepoMap and add them to context.
|
||||
Checks files already in context first.
|
||||
"""
|
||||
if not coder.repo_map:
|
||||
coder.io.tool_output("⚠️ Repo map not available, cannot use ViewFilesWithSymbol tool.")
|
||||
return "Repo map not available"
|
||||
|
||||
if not symbol:
|
||||
return "Error: Missing 'symbol' parameter for ViewFilesWithSymbol"
|
||||
|
||||
# --- Start Modification ---
|
||||
# 1. Check files already in context
|
||||
files_in_context = list(coder.abs_fnames) + list(coder.abs_read_only_fnames)
|
||||
found_in_context = []
|
||||
for abs_fname in files_in_context:
|
||||
rel_fname = coder.get_rel_fname(abs_fname)
|
||||
try:
|
||||
# Use get_tags for consistency with RepoMap usage elsewhere for now.
|
||||
tags = coder.repo_map.get_tags(abs_fname, rel_fname)
|
||||
for tag in tags:
|
||||
if tag.name == symbol:
|
||||
found_in_context.append(rel_fname)
|
||||
break # Found in this file, move to next
|
||||
except Exception as e:
|
||||
coder.io.tool_warning(f"Could not get symbols for {rel_fname} while checking context: {e}")
|
||||
|
||||
if found_in_context:
|
||||
# Symbol found in already loaded files. Report this and stop.
|
||||
file_list = ", ".join(sorted(list(set(found_in_context))))
|
||||
coder.io.tool_output(f"Symbol '{symbol}' found in already loaded file(s): {file_list}. No external search performed.")
|
||||
return f"Symbol '{symbol}' found in already loaded file(s): {file_list}. No external search performed."
|
||||
# --- End Modification ---
|
||||
|
||||
|
||||
# 2. If not found in context, search the repository using RepoMap
|
||||
coder.io.tool_output(f"🔎 Searching for symbol '{symbol}' in repository (excluding current context)...")
|
||||
try:
|
||||
if not coder.repo_map:
|
||||
coder.io.tool_output("⚠️ Repo map not available, cannot use ViewFilesWithSymbol tool.")
|
||||
return "Repo map not available"
|
||||
|
||||
if not symbol:
|
||||
return "Error: Missing 'symbol' parameter for ViewFilesWithSymbol"
|
||||
|
||||
coder.io.tool_output(f"🔎 Searching for symbol '{symbol}'...")
|
||||
found_files = set()
|
||||
current_context_files = coder.abs_fnames | coder.abs_read_only_fnames
|
||||
files_to_search = set(coder.get_all_abs_files()) - current_context_files
|
||||
|
@ -54,8 +80,9 @@ def _execute_view_files_with_symbol(coder, symbol):
|
|||
rel_path = coder.get_rel_fname(abs_file_path)
|
||||
# Double check it's not already added somehow
|
||||
if abs_file_path not in coder.abs_fnames and abs_file_path not in coder.abs_read_only_fnames:
|
||||
add_result = coder._add_file_to_context(rel_path, explicit=True) # Use explicit=True for clear output
|
||||
if "Added" in add_result:
|
||||
# Use explicit=True for clear output, even though it's an external search result
|
||||
add_result = coder._add_file_to_context(rel_path, explicit=True)
|
||||
if "Added" in add_result or "Viewed" in add_result: # Count successful adds/views
|
||||
added_count += 1
|
||||
added_files_rel.append(rel_path)
|
||||
|
||||
|
@ -67,9 +94,9 @@ def _execute_view_files_with_symbol(coder, symbol):
|
|||
coder.io.tool_output(f"🔎 Found '{symbol}' and added files: {', '.join(added_files_rel)}")
|
||||
return f"Found symbol '{symbol}' and added {added_count} files as read-only."
|
||||
else:
|
||||
coder.io.tool_output(f"⚠️ Symbol '{symbol}' not found in searchable files.")
|
||||
return f"Symbol '{symbol}' not found in searchable files."
|
||||
coder.io.tool_output(f"⚠️ Symbol '{symbol}' not found in searchable files (outside current context).")
|
||||
return f"Symbol '{symbol}' not found in searchable files (outside current context)."
|
||||
|
||||
except Exception as e:
|
||||
coder.io.tool_error(f"Error in ViewFilesWithSymbol: {str(e)}")
|
||||
return f"Error: {str(e)}"
|
||||
return f"Error: {str(e)}"
|
Loading…
Add table
Add a link
Reference in a new issue