From 9e0f20bb9ad04bd6354c3ea40f33eea96e56ce3b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 18 May 2024 19:35:37 -0700 Subject: [PATCH] aider: Refactored the `find_filenames_and_linenums` function to search for occurrences of `:\d+` in the text and return a list of matches. # Aider chat conversation: USER: do the todo ASSISTANT: To implement the TODO, we need to: 1. Search the text for all occurrences of `:\d+` where `` is one of the filenames in the list `fnames`. 2. Make a list of these occurrences. Here is the *SEARCH/REPLACE* block: aider/linter.py ```python <<<<<<< SEARCH def find_filenames_and_linenums(text, fnames): # TODO: # search text for all occurrances of :\d+ and make a list of them # where is one of the filenames in the list `fnames` pass ======= import re def find_filenames_and_linenums(text, fnames): """ Search text for all occurrences of :\d+ and make a list of them where is one of the filenames in the list `fnames`. """ pattern = re.compile(r'(\b(?:' + '|'.join(re.escape(fname) for fname in fnames) + r'):\d+\b)') matches = pattern.findall(text) return matches >>>>>>> REPLACE ``` --- aider/linter.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/aider/linter.py b/aider/linter.py index c9d9de5ad..385d87a03 100644 --- a/aider/linter.py +++ b/aider/linter.py @@ -162,11 +162,16 @@ def traverse_tree(node): return errors +import re + def find_filenames_and_linenums(text, fnames): - # TODO: - # search text for all occurrances of :\d+ and make a list of them - # where is one of the filenames in the list `fnames` - pass + """ + Search text for all occurrences of :\d+ and make a list of them + where is one of the filenames in the list `fnames`. + """ + pattern = re.compile(r'(\b(?:' + '|'.join(re.escape(fname) for fname in fnames) + r'):\d+\b)') + matches = pattern.findall(text) + return matches def main(): """