mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-08 05:34:59 +00:00
refactor: improve AI comment detection and file handling
This commit is contained in:
parent
9b4df54432
commit
99a1e42381
2 changed files with 10 additions and 8 deletions
|
@ -650,6 +650,7 @@ class RepoMap:
|
||||||
if not code.endswith("\n"):
|
if not code.endswith("\n"):
|
||||||
code += "\n"
|
code += "\n"
|
||||||
|
|
||||||
|
#ai
|
||||||
context = TreeContext(
|
context = TreeContext(
|
||||||
rel_fname,
|
rel_fname,
|
||||||
code,
|
code,
|
||||||
|
|
|
@ -64,13 +64,13 @@ class FileWatcher:
|
||||||
"""Watches source files for changes and AI comments"""
|
"""Watches source files for changes and AI comments"""
|
||||||
|
|
||||||
# Compiled regex pattern for AI comments
|
# Compiled regex pattern for AI comments
|
||||||
ai_comment_pattern = re.compile(r"(?:#|//) *(ai\b.*|ai|.*ai!)", re.IGNORECASE)
|
ai_comment_pattern = re.compile(r"(?:#|//) *(ai\b.*|ai|.*\bai!)", re.IGNORECASE)
|
||||||
|
|
||||||
def __init__(self, coder, gitignores=None, verbose=False):
|
def __init__(self, coder, gitignores=None, verbose=False):
|
||||||
self.coder = coder
|
self.coder = coder
|
||||||
self.io = coder.io
|
self.io = coder.io
|
||||||
self.root = Path(coder.root)
|
self.root = Path(coder.root)
|
||||||
self.verbose = verbose # or True
|
self.verbose = verbose
|
||||||
self.stop_event = None
|
self.stop_event = None
|
||||||
self.watcher_thread = None
|
self.watcher_thread = None
|
||||||
self.changed_files = set()
|
self.changed_files = set()
|
||||||
|
@ -105,13 +105,12 @@ class FileWatcher:
|
||||||
|
|
||||||
# Check if file contains AI markers
|
# Check if file contains AI markers
|
||||||
try:
|
try:
|
||||||
content = self.io.read_text(str(path_abs))
|
with open(str(path_abs), "r", encoding=self.io.encoding) as f:
|
||||||
return self.ai_comment_pattern.search(content)
|
content = f.read()
|
||||||
|
match = self.ai_comment_pattern.search(content)
|
||||||
|
return bool(match)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if self.verbose:
|
return
|
||||||
print("error")
|
|
||||||
dump(err)
|
|
||||||
return False
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start watching for file changes"""
|
"""Start watching for file changes"""
|
||||||
|
@ -173,6 +172,8 @@ class FileWatcher:
|
||||||
if line_nums:
|
if line_nums:
|
||||||
ai_comments[fname] = comments
|
ai_comments[fname] = comments
|
||||||
|
|
||||||
|
# feed the filenames and line numbers to TreeContext, like repomap does
|
||||||
|
# to produce the `res` with context ai!
|
||||||
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
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue