fix: update regex pattern for AI comment detection

This commit is contained in:
Paul Gauthier 2024-10-25 16:03:37 -07:00 committed by Paul Gauthier (aider)
parent 0960663811
commit 05daab24a2

View file

@ -135,13 +135,13 @@ def watch_source_files(
result[file] = comment
yield result
#ai return a list of all the ai comments in each file
def get_ai_comment(filepath, encoding="utf-8"):
"""Extract AI comment from a file if present"""
try:
with open(filepath, encoding=encoding, errors="ignore") as f:
for line in f:
if match := re.search(r"(?:#|//) *ai:? *(.*)", line, re.IGNORECASE):
if match := re.search(r"(?:#|//) *ai\b(.*)", line, re.IGNORECASE):
return match.group(1).strip()
except (IOError, UnicodeDecodeError):
return None