From a87de46371c2f930d6175f9460bc41205c84953a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 14:12:49 -0700 Subject: [PATCH] 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. --- aider/getinput.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aider/getinput.py b/aider/getinput.py index 3edb2b2a6..c6945ac09 100644 --- a/aider/getinput.py +++ b/aider/getinput.py @@ -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))