branch: elpa/clojure-ts-mode
commit 32490c80fad7d27367b08d967e8184f75b4ca19e
Author: Roman Rudakov <rruda...@fastmail.com>
Commit: Bozhidar Batsov <bozhi...@batsov.dev>

    Fix clojure-ts-add-arity bug when body has more than one expression
---
 CHANGELOG.md                                    |  3 ++-
 clojure-ts-mode.el                              |  7 ++++++-
 test/clojure-ts-mode-refactor-add-arity-test.el | 16 ++++++++++++++++
 test/samples/refactoring.clj                    |  3 ++-
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2bfc74a8820..15087a6591d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,8 @@
 - [#116](https://github.com/clojure-emacs/clojure-ts-mode/pull/116): Extend 
built-in completion to complete all imported symbols from an `ns`
   form.
 - Add documentation and bug reporting commands from `clojure-mode`.
-- Add some ns manipulation functions from `clojure-mode`.
+- [#118](https://github.com/clojure-emacs/clojure-ts-mode/pull/118): Add some 
ns manipulation functions from `clojure-mode`.
+- Fix a bug in `clojure-ts-add-arity` when body has more than one expression.
 
 ## 0.5.1 (2025-06-17)
 
diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index bcb0107a286..3152e397549 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -2325,7 +2325,12 @@ type, etc.  See `treesit-thing-settings' for more 
details."
     (when same-line-p
       (newline-and-indent))
     (when single-arity-p
-      (insert-pair 2 ?\( ?\))
+      (save-excursion
+        (backward-up-list)
+        (forward-list)
+        (down-list -1)
+        (insert ")"))
+      (insert "(")
       (backward-up-list))
     (insert "([])\n")
     ;; Put the point between square brackets.
diff --git a/test/clojure-ts-mode-refactor-add-arity-test.el 
b/test/clojure-ts-mode-refactor-add-arity-test.el
index f119607dc30..10c052815a3 100644
--- a/test/clojure-ts-mode-refactor-add-arity-test.el
+++ b/test/clojure-ts-mode-refactor-add-arity-test.el
@@ -80,6 +80,22 @@
 
     (clojure-ts-add-arity))
 
+  (when-refactoring-with-point-it "should handle a single-arity defn with 
multiple body expressions"
+    "(defn fo|o
+  ^{:bla \"meta\"}
+  [arg]
+  body
+  second-expr)"
+
+    "(defn foo
+  ^{:bla \"meta\"}
+  ([|])
+  ([arg]
+   body
+   second-expr))"
+
+    (clojure-ts-add-arity))
+
   (when-refactoring-with-point-it "should add an arity to a multi-arity defn"
     "(defn foo
   ([arg1])
diff --git a/test/samples/refactoring.clj b/test/samples/refactoring.clj
index c2346ee874a..499d3e07377 100644
--- a/test/samples/refactoring.clj
+++ b/test/samples/refactoring.clj
@@ -133,7 +133,8 @@
 (defn foo
   ^{:bla "meta"}
   [arg]
-  body)
+  body
+  second-expr)
 
 (if ^boolean (= 2 2)
   true

Reply via email to