mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
refactor: simplify AI comment detection and improve comment handling
This commit is contained in:
parent
b5dbb1d39d
commit
a131d5ad35
1 changed files with 10 additions and 13 deletions
|
@ -106,13 +106,7 @@ class FileWatcher:
|
||||||
# Check if file contains AI markers
|
# Check if file contains AI markers
|
||||||
try:
|
try:
|
||||||
content = self.io.read_text(str(path_abs))
|
content = self.io.read_text(str(path_abs))
|
||||||
if match := self.ai_comment_pattern.search(content):
|
return self.ai_comment_pattern.search(content)
|
||||||
if self.verbose:
|
|
||||||
dump(True)
|
|
||||||
return True
|
|
||||||
if self.verbose:
|
|
||||||
dump(False)
|
|
||||||
return False
|
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print("error")
|
print("error")
|
||||||
|
@ -179,10 +173,11 @@ 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:
|
||||||
if comments := self.get_ai_comment(fname):
|
#ai update this too!
|
||||||
ai_comments[fname] = comments
|
comment_lines, has_bang = self.get_ai_comment(fname):
|
||||||
|
ai_comments[fname] = comment_lines
|
||||||
|
|
||||||
# Check for bang (!) comments
|
# ai this logic should move into get_ai_comments()
|
||||||
has_bangs = any(
|
has_bangs = any(
|
||||||
comment.strip().endswith("!")
|
comment.strip().endswith("!")
|
||||||
for comments in ai_comments.values()
|
for comments in ai_comments.values()
|
||||||
|
@ -196,16 +191,18 @@ class FileWatcher:
|
||||||
res = "\n".join(
|
res = "\n".join(
|
||||||
comment for comments in ai_comments.values() if comments for comment in comments
|
comment for comments in ai_comments.values() if comments for comment in comments
|
||||||
)
|
)
|
||||||
res = """The "ai" comments below can be found in the code above.
|
res = """The "ai" comments below can be found in the code files I've shared with you.
|
||||||
They contain your instructions.
|
They contain your instructions.
|
||||||
Make the requested changes.
|
Make the requested changes and remove all the "ai" comments from the code.
|
||||||
Also remove all these comments from the code.
|
|
||||||
|
|
||||||
""" + res
|
""" + res
|
||||||
|
|
||||||
dump(res)
|
dump(res)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
#ai change this to get_ai_comments() with an s
|
||||||
|
#ai return a list of the line numbers which have matching comments
|
||||||
|
# also return a bool indicating if any of the lines end with !
|
||||||
def get_ai_comment(self, filepath):
|
def get_ai_comment(self, filepath):
|
||||||
"""Extract all AI comments from a file"""
|
"""Extract all AI comments from a file"""
|
||||||
comments = []
|
comments = []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue