diff --git a/aider/watch.py b/aider/watch.py index 2818e6928..2cce902ca 100644 --- a/aider/watch.py +++ b/aider/watch.py @@ -106,8 +106,8 @@ class FileWatcher: # Check if file contains AI markers try: - _, _, has_match = self.get_ai_comments(str(path_abs)) - return has_match + comments, _, _ = self.get_ai_comments(str(path_abs)) + return bool(comments) except Exception: return diff --git a/tests/basic/test_watch.py b/tests/basic/test_watch.py index 97c23f8d2..d8bce3d6f 100644 --- a/tests/basic/test_watch.py +++ b/tests/basic/test_watch.py @@ -23,15 +23,22 @@ def test_ai_comment_pattern(): # Test Python fixture py_path = fixtures_dir / "watch.py" py_lines, py_comments, py_has_bang = watcher.get_ai_comments(str(py_path)) + # Count unique AI comments (excluding duplicates and variations with extra spaces) unique_py_comments = set(comment.strip().lower() for comment in py_comments) - assert len(unique_py_comments) == 11, f"Expected 11 unique AI comments in Python fixture, found {len(unique_py_comments)}" + + py_expected = 10 + assert len(unique_py_comments) == 10, ( + f"Expected {py_expected} unique AI comments in Python fixture, found" + f" {len(unique_py_comments)}" + ) assert py_has_bang, "Expected at least one bang (!) comment in Python fixture" # Test JavaScript fixture js_path = fixtures_dir / "watch.js" js_lines, js_comments, js_has_bang = watcher.get_ai_comments(str(js_path)) + js_expected = 14 assert ( - len(js_lines) == 11 - ), f"Expected 11 AI comments in JavaScript fixture, found {len(js_lines)}" + len(js_lines) == js_expected + ), f"Expected {js_expected} AI comments in JavaScript fixture, found {len(js_lines)}" assert js_has_bang, "Expected at least one bang (!) comment in JavaScript fixture" diff --git a/tests/fixtures/watch.js b/tests/fixtures/watch.js index 516014077..ea7f4314d 100644 --- a/tests/fixtures/watch.js +++ b/tests/fixtures/watch.js @@ -1,27 +1,35 @@ // Regular AI comment -//ai do something -//AI make this better -//ai! urgent change needed -//AI! another urgent one -// ai with space -// AI with caps -// ai! with bang +//ai do 1 something +//AI make 2 this better +//ai! urgent 3 change needed +//AI! another 4 urgent one +// ai with 5 space +// AI with 6 caps +// ai! with 7 bang // this is not an ai comment -// aider is not an ai comment +// aider is not an ai! comment function dummyFunction() { - // ai inside function + // ai inside 8 function return true; } class Example { constructor() { - // ai in constructor + // ai in 9 constructor this.value = 42; } method() { - // ai in method + // ai in 10 method return this.value; } + // ai! + //ai + //ai! + // 11-13 + + method2() { // ai 14 + return 1; + } } diff --git a/tests/fixtures/watch.py b/tests/fixtures/watch.py index f636f16aa..1aa37a495 100644 --- a/tests/fixtures/watch.py +++ b/tests/fixtures/watch.py @@ -1,19 +1,20 @@ -# Regular AI comment -# ai do something -# AI make this better -# ai! urgent change needed -# AI! another urgent one -//ai javascript style -//AI do that thing -//ai! urgent js thing -// ai with some space -// AI with caps -// ai! with bang +# flake8: noqa + +# Regular not AI comment +# ai 1 do something +# AI 2 make this better +# ai! 3 urgent change needed +# AI! 4 another urgent one # this is not an ai comment -// this is also not an ai comment # aider is not an ai comment -// aider is not an ai comment +# not an ai! comment + def dummy_function(): - # ai inside function - pass + # ai inside 5 function + # final 6 ai! + # final 7 ai + # ai + # ai + # those are 8+9 + pass # ai 10