aider: Split file content into words based on non-alphanumeric characters using re module in FileContentCompleter.

# Context:
USER: have FileContentCompleter(Completer) split the files into words on non-alphanums. so each word is a contiguous sequence of alphanums. non-alphanums are ignored, and only used to split.
ASSISTANT: To make the `FileContentCompleter` split the file content into words based on non-alphanumeric characters, you can use the `re` module to split the content. Here's the change you need to make:

```python
aider/getinput.py
<<<<<<< ORIGINAL
            for word in content.split():
=======
            import re
            for word in re.split(r'\W+', content):
>>>>>>> UPDATED
```

This change imports the `re` module and uses the `re.split()` function with the pattern `\W+` to split the content into words based on non-alphanumeric characters.
This commit is contained in:
Paul Gauthier 2023-05-09 14:12:49 -07:00
parent 0fdd5d101b
commit a87de46371

View file

@ -19,7 +19,8 @@ class FileContentCompleter(Completer):
for fname in self.fnames:
with open(fname, "r") as f:
content = f.read()
for word in content.split():
import re
for word in re.split(r'\W+', content):
if word.startswith(last_word):
yield Completion(word, start_position=-len(last_word))