From ad5cdc463a26917ed673df4caa6b7fee96b3b5d0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 5 Jul 2023 21:38:44 -0700 Subject: [PATCH] aider: Refactored `cmd_drop` to use `glob` for matching files against the given word. # Context: USER: have `cmd_drop` also glob against the `files` ASSISTANT: To implement this change, we need to modify the `aider/commands.py` file. Here's the step-by-step process: 1. In the `cmd_drop` method, use the `glob.glob` function to match the word against the `files`. 2. If no files match, print an error message. 3. If files match, remove them from the chat session. Here's the code change: ```python aider/commands.py <<<<<<< ORIGINAL def cmd_drop(self, args): "Remove matching files from the chat session" if not args.strip(): self.io.tool_output("Dropping all files from the chat session.") self.coder.abs_fnames = set() for word in args.split(): matched_files = [ file for file in self.coder.abs_fnames if word.lower() in os.path.relpath(file, self.coder.root).lower() ] if not matched_files: self.io.tool_error(f"No files matched '{word}'") for matched_file in matched_files: relative_fname = os.path.relpath(matched_file, self.coder.root) self.coder.abs_fnames.remove(matched_file) self.io.tool_output(f"Removed {relative_fname} from the chat") ======= def cmd_drop(self, args): "Remove matching files from the chat session" if not args.strip(): self.io.tool_output("Dropping all files from the chat session.") self.coder.abs_fnames = set() for word in args.split(): matched_files = [ file for file in self.coder.abs_fnames if any(glob.fnmatch.fnmatch(os.path.relpath(file, self.coder.root), word) for file in self.coder.abs_fnames) ] if not matched_files: self.io.tool_error(f"No files matched '{word}'") for matched_file in matched_files: relative_fname = os.path.relpath(matched_file, self.coder.root) self.coder.abs_fnames.remove(matched_file) self.io.tool_output(f"Removed {relative_fname} from the chat") >>>>>>> UPDATED ``` Please let me know if you need any further changes. --- aider/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aider/commands.py b/aider/commands.py index 83715b01f..ccda68e7d 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -288,7 +288,7 @@ class Commands: matched_files = [ file for file in self.coder.abs_fnames - if word.lower() in os.path.relpath(file, self.coder.root).lower() + if any(glob.fnmatch.fnmatch(os.path.relpath(file, self.coder.root), word) for file in self.coder.abs_fnames) ] if not matched_files: self.io.tool_error(f"No files matched '{word}'")