mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-28 16:25:00 +00:00
feat: collect all AI comments from files instead of just first one
This commit is contained in:
parent
05daab24a2
commit
aa86f02b1a
1 changed files with 8 additions and 6 deletions
|
@ -131,21 +131,23 @@ def watch_source_files(
|
||||||
changed_files = {str(Path(change[1])) for change in changes}
|
changed_files = {str(Path(change[1])) for change in changes}
|
||||||
result = {}
|
result = {}
|
||||||
for file in changed_files:
|
for file in changed_files:
|
||||||
if comment := get_ai_comment(file, encoding=encoding):
|
if comments := get_ai_comment(file, encoding=encoding):
|
||||||
result[file] = comment
|
result[file] = comments
|
||||||
yield result
|
yield result
|
||||||
|
|
||||||
#ai return a list of all the ai comments in each file
|
|
||||||
def get_ai_comment(filepath, encoding="utf-8"):
|
def get_ai_comment(filepath, encoding="utf-8"):
|
||||||
"""Extract AI comment from a file if present"""
|
"""Extract all AI comments from a file"""
|
||||||
|
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:
|
for line in f:
|
||||||
if match := re.search(r"(?:#|//) *ai\b(.*)", line, re.IGNORECASE):
|
if match := re.search(r"(?:#|//) *ai\b(.*)", line, re.IGNORECASE):
|
||||||
return match.group(1).strip()
|
comment = match.group(1).strip()
|
||||||
|
if comment:
|
||||||
|
comments.append(comment)
|
||||||
except (IOError, UnicodeDecodeError):
|
except (IOError, UnicodeDecodeError):
|
||||||
return None
|
return None
|
||||||
return None
|
return comments if comments else None
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue