From ba17dceb4d412e34201b9dae1bbee6d3a0798162 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 27 Nov 2024 17:35:05 -0800 Subject: [PATCH] feat: make /drop use substring matching for non-glob patterns --- aider/commands.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index af74e281c..58b1c764a 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -808,15 +808,22 @@ class Commands: # Expand tilde in the path expanded_word = os.path.expanduser(word) - # Handle read-only files separately, without glob_filtered_to_repo + # Handle read-only files with substring matching read_only_matched = [f for f in self.coder.abs_read_only_fnames if expanded_word in f] + for matched_file in read_only_matched: + self.coder.abs_read_only_fnames.remove(matched_file) + self.io.tool_output(f"Removed read-only file {matched_file} from the chat") - if read_only_matched: - for matched_file in read_only_matched: - self.coder.abs_read_only_fnames.remove(matched_file) - self.io.tool_output(f"Removed read-only file {matched_file} from the chat") - - matched_files = self.glob_filtered_to_repo(expanded_word) + # For editable files, use glob if word contains glob chars, otherwise use substring + if any(c in expanded_word for c in "*?[]"): + matched_files = self.glob_filtered_to_repo(expanded_word) + else: + # Use substring matching like we do for read-only files + matched_files = [ + self.coder.get_rel_fname(f) + for f in self.coder.abs_fnames + if expanded_word in f + ] if not matched_files: matched_files.append(expanded_word)