From 5a83610fb120bce94aef955ddc2b888e59d711c7 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 11 Dec 2024 20:16:10 -0800 Subject: [PATCH] refactor: Update ai comment action handling to support '?' --- aider/watch.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/aider/watch.py b/aider/watch.py index 156033f40..b28a2b067 100644 --- a/aider/watch.py +++ b/aider/watch.py @@ -166,10 +166,11 @@ class FileWatcher: def process_changes(self): """Get any detected file changes""" - has_bangs = False + has_action = None for fname in self.changed_files: - _, _, has_bang = self.get_ai_comments(fname) - has_bangs |= has_bang + _, _, action = self.get_ai_comments(fname) + if action in ("!", "?"): + has_action = action if fname in self.coder.abs_fnames: continue @@ -180,7 +181,7 @@ class FileWatcher: self.io.tool_output(f"Added {rel_fname} to the chat") self.io.tool_output() - if not has_bangs: + if not has_action: return "" if self.analytics: @@ -229,10 +230,10 @@ class FileWatcher: return res def get_ai_comments(self, filepath): - """Extract AI comment line numbers, comments and bang status from a file""" + """Extract AI comment line numbers, comments and action status from a file""" line_nums = [] comments = [] - has_bang = False + has_action = None # None, "!" or "?" content = self.io.read_text(filepath, silent=True) for i, line in enumerate(content.splitlines(), 1): if match := self.ai_comment_pattern.search(line): @@ -244,10 +245,12 @@ class FileWatcher: comment = comment.lstrip("/#-") comment = comment.strip() if comment.startswith("ai!") or comment.endswith("ai!"): - has_bang = True + has_action = "!" + elif comment.startswith("ai?") or comment.endswith("ai?"): + has_action = "?" if not line_nums: - return None, None, False - return line_nums, comments, has_bang + return None, None, None + return line_nums, comments, has_action def main():