mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 01:35:00 +00:00
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:
parent
0fdd5d101b
commit
a87de46371
1 changed files with 2 additions and 1 deletions
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue