From cbb3d4f15f176f970e532f8f24fb86c10c0be721 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 12:13:28 -0700 Subject: [PATCH] aider: Added functionality to cmd_add to search for files containing words in args, print matches, and add their absolute paths to self.fnames. # Context: USER: finish implementing cmd_add. for each word in the args, find any files which contain it. print the found matches and add their abspth to self.fnames. ASSISTANT: To implement the `cmd_add` method, you can iterate through the words in the `args` and search for files containing those words. Then, print the found matches and add their absolute paths to `self.fnames`. Here's the updated code for the `cmd_add` method: ```python aider/coder.py <<<<<<< ORIGINAL def cmd_add(self, args): "Add files to the chat" files = self.get_active_files() ======= def cmd_add(self, args): "Add files to the chat" files = self.get_active_files() for word in args: matched_files = [file for file in files if word in file] for matched_file in matched_files: abs_file_path = os.path.abspath(os.path.join(self.root, matched_file)) if abs_file_path not in self.fnames: self.fnames.add(abs_file_path) self.console.print(f"[red]Added {matched_file} to the chat") else: self.console.print(f"[red]{matched_file} is already in the chat") >>>>>>> UPDATED ``` This code will search for files containing the words in `args`, print the found matches, and add their absolute paths to `self.fnames`. --- aider/coder.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/aider/coder.py b/aider/coder.py index daed815ea..294e48da0 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -488,7 +488,15 @@ class Coder: "Add files to the chat" files = self.get_active_files() - + for word in args: + matched_files = [file for file in files if word in file] + for matched_file in matched_files: + abs_file_path = os.path.abspath(os.path.join(self.root, matched_file)) + if abs_file_path not in self.fnames: + self.fnames.add(abs_file_path) + self.console.print(f"[red]Added {matched_file} to the chat") + else: + self.console.print(f"[red]{matched_file} is already in the chat") def cmd_ls(self, args): "List files and show their chat status"