mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
refactor: rename and enhance get_ai_comments to track line numbers and bang status
This commit is contained in:
parent
a131d5ad35
commit
21dffa26b9
1 changed files with 15 additions and 19 deletions
|
@ -173,17 +173,9 @@ class FileWatcher:
|
||||||
# Refresh all AI comments from tracked files
|
# Refresh all AI comments from tracked files
|
||||||
ai_comments = {}
|
ai_comments = {}
|
||||||
for fname in self.coder.abs_fnames:
|
for fname in self.coder.abs_fnames:
|
||||||
#ai update this too!
|
comments, line_nums, has_bang = self.get_ai_comments(fname)
|
||||||
comment_lines, has_bang = self.get_ai_comment(fname):
|
ai_comments[fname] = comments
|
||||||
ai_comments[fname] = comment_lines
|
has_bangs = has_bang
|
||||||
|
|
||||||
# ai this logic should move into get_ai_comments()
|
|
||||||
has_bangs = any(
|
|
||||||
comment.strip().endswith("!")
|
|
||||||
for comments in ai_comments.values()
|
|
||||||
if comments
|
|
||||||
for comment in comments
|
|
||||||
)
|
|
||||||
|
|
||||||
if not has_bangs:
|
if not has_bangs:
|
||||||
return ""
|
return ""
|
||||||
|
@ -200,22 +192,26 @@ class FileWatcher:
|
||||||
dump(res)
|
dump(res)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
#ai change this to get_ai_comments() with an s
|
def get_ai_comments(self, filepath):
|
||||||
#ai return a list of the line numbers which have matching comments
|
"""Extract all AI comments from a file, returning comments, line numbers and bang status"""
|
||||||
# also return a bool indicating if any of the lines end with !
|
|
||||||
def get_ai_comment(self, filepath):
|
|
||||||
"""Extract all AI comments from a file"""
|
|
||||||
comments = []
|
comments = []
|
||||||
|
line_nums = []
|
||||||
|
has_bang = False
|
||||||
try:
|
try:
|
||||||
content = self.io.read_text(filepath)
|
content = self.io.read_text(filepath)
|
||||||
for line in content.splitlines():
|
for i, line in enumerate(content.splitlines(), 1):
|
||||||
if match := self.ai_comment_pattern.search(line):
|
if match := self.ai_comment_pattern.search(line):
|
||||||
comment = match.group(0).strip()
|
comment = match.group(0).strip()
|
||||||
if comment:
|
if comment:
|
||||||
comments.append(comment)
|
comments.append(comment)
|
||||||
|
line_nums.append(i)
|
||||||
|
if comment.strip().endswith('!'):
|
||||||
|
has_bang = True
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return None, None, False
|
||||||
return comments if comments else None
|
if not comments:
|
||||||
|
return None, None, False
|
||||||
|
return comments, line_nums, has_bang
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue