mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
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.
This commit is contained in:
parent
d42c684a36
commit
8fe98cdcba
1 changed files with 10 additions and 0 deletions
|
@ -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"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue