fix: improve regex pattern for AI comment detection

This commit is contained in:
Paul Gauthier 2024-10-25 16:23:44 -07:00 committed by Paul Gauthier (aider)
parent 4298ae00a9
commit c26d7d23b5

View file

@ -8,6 +8,7 @@ from watchfiles import watch
from aider.dump import dump # noqa from aider.dump import dump # noqa
#ai turn off verbose!
VERBOSE = True VERBOSE = True
@ -144,9 +145,9 @@ def get_ai_comment(filepath, encoding="utf-8"):
comments = [] comments = []
try: try:
with open(filepath, encoding=encoding, errors="ignore") as f: with open(filepath, encoding=encoding, errors="ignore") as f:
for line in f: # ai for line in f:
if match := re.search(r"(?:#|//) *ai(\b.*)?", line, re.IGNORECASE): if match := re.search(r"(?:#|//) *(ai\b.*|ai)", line, re.IGNORECASE):
comment = match.group(1).strip() comment = match.group(0).strip()
if comment: if comment:
comments.append(comment) comments.append(comment)
except (IOError, UnicodeDecodeError): except (IOError, UnicodeDecodeError):