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`.
This commit is contained in:
Paul Gauthier 2023-05-10 12:13:28 -07:00
parent aafd524cb2
commit cbb3d4f15f

View file

@ -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"