From 8fe98cdcba5144072e102d8d9d96c0ffb13bbc28 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 12:16:26 -0700 Subject: [PATCH] aider: Added `cmd_drop` method to remove files from the chat based on matching words in `args`. # Context: USER: add cmd_drop() which works like cmd_add but removes files from self.fnames if the word in args matches the relative_fname ASSISTANT: To implement the `cmd_drop` method, you can iterate through the words in the `args` and search for files in `self.fnames` that match the words. Then, remove the matched files from `self.fnames`. Here's the updated code for the `cmd_drop` method: ```python aider/coder.py <<<<<<< ORIGINAL def cmd_ls(self, args): "List files and show their chat status" self.console.print(f"* denotes files included in the chat\n") files = self.get_active_files() for file in files: abs_file_path = os.path.abspath(os.path.join(self.root, file)) if abs_file_path in self.fnames: self.console.print(f"* {file}") else: self.console.print(f" {file}") ======= def cmd_drop(self, args): "Remove files from the chat" for word in args.split(): matched_files = [file for file in self.fnames if word in file] for matched_file in matched_files: relative_fname = os.path.relpath(matched_file, self.root) self.fnames.remove(matched_file) self.console.print(f"[red]Removed {relative_fname} from the chat") def cmd_ls(self, args): "List files and show their chat status" self.console.print(f"* denotes files included in the chat\n") files = self.get_active_files() for file in files: abs_file_path = os.path.abspath(os.path.join(self.root, file)) if abs_file_path in self.fnames: self.console.print(f"* {file}") else: self.console.print(f" {file}") >>>>>>> UPDATED ``` This code will search for files in `self.fnames` that match the words in `args`, remove the matched files from `self.fnames`, and print the removed files. --- aider/coder.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/aider/coder.py b/aider/coder.py index 5178f1d70..626994749 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -498,6 +498,16 @@ class Coder: else: self.console.print(f"[red]{matched_file} is already in the chat") + def cmd_drop(self, args): + "Remove files from the chat" + + for word in args.split(): + matched_files = [file for file in self.fnames if word in file] + for matched_file in matched_files: + relative_fname = os.path.relpath(matched_file, self.root) + self.fnames.remove(matched_file) + self.console.print(f"[red]Removed {relative_fname} from the chat") + def cmd_ls(self, args): "List files and show their chat status"