aider: Changed self.words initialization from an empty list to an empty set and replaced the extend method with the update method to add words to the set.

# Context:
USER: self.words should be a set not a list
ASSISTANT: To change `self.words` from a list to a set, we will update the `__init__` method in the `FileContentCompleter` class. Here's the updated code:

```python
aider/getinput.py
<<<<<<< ORIGINAL
class FileContentCompleter(Completer):
    def __init__(self, fnames):
        self.words = []
        for fname in fnames:
            with open(fname, "r") as f:
                content = f.read()
            self.words.extend(re.split(r'\W+', content))
=======
class FileContentCompleter(Completer):
    def __init__(self, fnames):
        self.words = set()
        for fname in fnames:
            with open(fname, "r") as f:
                content = f.read()
            self.words.update(re.split(r'\W+', content))
>>>>>>> UPDATED
```

This change updates the `self.words` initialization from an empty list to an empty set and replaces the `extend` method with the `update` method to add words to the set.
This commit is contained in:
Paul Gauthier 2023-05-10 10:55:39 -07:00
parent 9c7d308deb
commit 43331aad89

View file

@ -27,12 +27,11 @@ class Commands:
class FileContentCompleter(Completer): class FileContentCompleter(Completer):
def __init__(self, fnames): def __init__(self, fnames):
self.words = [] self.words = set()
for fname in fnames: for fname in fnames:
with open(fname, "r") as f: with open(fname, "r") as f:
content = f.read() content = f.read()
self.words.extend(re.split(r'\W+', content)) self.words.update(re.split(r'\W+', content))
def get_completions(self, document, complete_event): def get_completions(self, document, complete_event):
text = document.text_before_cursor text = document.text_before_cursor
words = text.split() words = text.split()