branch: elpa/aidermacs commit 6366951cee9497eb37f85ab1fc0bd8f1e00e2aa9 Author: Kang Tu <tni...@gmail.com> Commit: GitHub <nore...@github.com>
Fix: Better one line comment identification (#64) * feat: Add aider-implement-todo function to implement TODOs in current context * feat: Add `aider-implement-todo` function description to README * docs(readme): update aider command description * refactor: Add comment line detection to aider-implement-todo for more precise implementation context * fix: improve prompt clarity for comment implementation * refactor: Improve comment detection in aider-implement-todo function * fix: Improve comment detection by trimming comment-start from both sides * refactor: Extract comment detection logic into dedicated function * test: Add comprehensive unit tests for aider--is-comment-line function * style: remove extra whitespace and newlines in test file * test: update test cases to use multiple comment markers --------- Co-authored-by: Kang Tu <kang...@apple.com> --- aider.el | 14 ++++++++++++-- test_aider.el | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/aider.el b/aider.el index a94004ae94..f7d2d46c34 100644 --- a/aider.el +++ b/aider.el @@ -621,6 +621,17 @@ This function assumes the cursor is on or inside a test function." (aider--send-command command t)) (message "No test function found at cursor position."))) +(defun aider--is-comment-line (line) + "Check if LINE is a comment line based on current buffer's comment syntax. +Returns non-nil if LINE starts with one or more comment characters, +ignoring leading whitespace." + (when comment-start + (let ((comment-str (string-trim-right comment-start))) + (string-match-p (concat "^[ \t]*" + (regexp-quote comment-str) + "+") + (string-trim-left line))))) + ;;;###autoload (defun aider-implement-todo () "Implement TODO comments in current context. @@ -631,8 +642,7 @@ Otherwise implement TODOs for the entire current file." (if (not buffer-file-name) (message "Current buffer is not visiting a file.") (let* ((current-line (string-trim (thing-at-point 'line t))) - (is-comment (and comment-start - (string-prefix-p comment-start (string-trim-left current-line)))) + (is-comment (aider--is-comment-line current-line)) (function-name (which-function)) (initial-input (cond diff --git a/test_aider.el b/test_aider.el index b7e1be181d..460a898cf4 100644 --- a/test_aider.el +++ b/test_aider.el @@ -116,3 +116,35 @@ (let ((face-props (face-all-attributes face nil)) (default-props (face-all-attributes 'default nil))) (not (equal face-props default-props)))) + +(ert-deftest aider--is-comment-line-test () + "Test the aider--is-comment-line function." + ;; Test with semicolon comment style (Lisp) + (let ((comment-start ";")) + ;; Basic comment cases + (should (aider--is-comment-line "; comment")) + (should (aider--is-comment-line ";; double comment")) + (should (aider--is-comment-line ";;; triple comment")) + ;; Comments with leading whitespace + (should (aider--is-comment-line " ; indented comment")) + (should (aider--is-comment-line "\t; tabbed comment")) + ;; Non-comment cases + (should-not (aider--is-comment-line "code ; with comment")) + (should-not (aider--is-comment-line "regular code")) + (should-not (aider--is-comment-line ""))) + ;; Test with hash comment style (Python) + (let ((comment-start "#")) + (should (aider--is-comment-line "# python comment")) + (should (aider--is-comment-line " ## indented python comment")) + (should-not (aider--is-comment-line "code # with comment"))) + ;; Test with double slash comment style (C/Java) + (let ((comment-start "//")) + (should (aider--is-comment-line "// c style comment")) + (should (aider--is-comment-line " /// indented c comment")) + (should-not (aider--is-comment-line "code // with comment"))) + ;; Test with nil comment-start + (let ((comment-start nil)) + (should-not (aider--is-comment-line "; not a comment when no comment-start")) + (should-not (aider--is-comment-line "# not a comment when no comment-start")) + (should-not (aider--is-comment-line "// not a comment when no comment-start"))) + )