-
-
Notifications
You must be signed in to change notification settings - Fork 232
Open
Labels
Description
When there is auto-resolve keywords (e.g., ::foo) and {:align-associative? true} config is present, the formatting of a given form doesn't work.
Example:
(defn foo []
(let[a :b
aa :bb
ccc {:a :b :aa :bb :ccc :ccc :dddd ::dddd}]
))Expected result after pressing tab:
(defn foo []
(let [a :b
aa :bb
ccc {:a :b
:aa :bb
:ccc :ccc
:dddd ::dddd}]))Actual result (no formatting at all):
(defn foo []
(let[a :b
aa :bb
ccc {:a :b :aa :bb :ccc :ccc :dddd ::dddd}]
))I was able to reproduce this with a test, but I couldn't figure it out the fix (thus I'm opening as issue):
diff --git a/src/cljs-lib/test/calva/fmt/formatter_test.cljs b/src/cljs-lib/test/calva/fmt/formatter_test.cljs
index d82e6ac83..7163db412 100644
--- a/src/cljs-lib/test/calva/fmt/formatter_test.cljs
+++ b/src/cljs-lib/test/calva/fmt/formatter_test.cljs
@@ -25,7 +25,7 @@ baz)")
[x]
baz)"
- (:range-text (sut/format-text-at-idx {:eol "\n" :all-text all-text :range [10 38] :idxs [11]}))))
+ (:range-text (sut/format-text-at-idx {:eol "\n" :all-text all-text :range [10 38] :idxs [11]}))))
(is (= [10 38]
(:range (sut/format-text-at-idx {:eol "\n" :all-text all-text :range [10 38] :idxs [11]}))))
(is (= [0 5]
@@ -44,6 +44,12 @@ aa bb
ccc {:a b :aa bb :ccc ccc}]
))")
+(def misaligned-text-with-double-collon "(def foo
+(let[a b
+aa bb
+ccc {:a b :aa bb :ccc ccc :dddd ::dddd}]
+))")
+
(deftest format-aligned-text-at-idx
(testing "Aligns associative structures when `:align-associative` is `true`"
(is (= "(def foo
@@ -58,6 +64,20 @@ ccc {:a b :aa bb :ccc ccc}]
:range [0 56]
:idxs [0]})))))
+ (testing "Aligns associative structures with double colon when `:align-associative` is `true`"
+ (is (= "(def foo
+ (let [a b
+ aa bb
+ ccc {:a b
+ :aa bb
+ :ccc ccc
+ :dddd ::dddd}]))"
+ (:range-text (sut/format-text-at-idx {:eol "\n"
+ :all-text misaligned-text-with-double-collon
+ :config {:align-associative? true}
+ :range [0 69]
+ :idxs [0]})))))
+
(testing "Does not align associative structures when `:align-associative` is not `true`"
(is (= "(def foo
(let [a bexpected: (= "(def foo\n (let [a b\n aa bb\n ccc {:a b\n :aa bb\n :ccc ccc\n :dddd ::dddd}]))" (:range-text (sut/format-text-at-idx {:eol "\n", :all-text misaligned-text-with-double-collon, :config {:align-associative? true}, :range [0 69], :idxs [0]})))
actual: (not (= "(def foo\n (let [a b\n aa bb\n ccc {:a b\n :aa bb\n :ccc ccc\n :dddd ::dddd}]))" "(def foo\n(let[a b\naa bb\nccc {:a b :aa bb :ccc ccc :dddd ::dddd}]\n))"))
or formatted:
expected: (= "(def foo
(let [a b
aa bb
ccc {:a b
:aa bb
:ccc ccc
:dddd ::dddd}]))" (:range-text (sut/format-text-at-idx {:eol "
", :all-text misaligned-text-with-double-collon, :config {:align-associative? true}, :range [0 69], :idxs [0]})))
actual: (not (= "(def foo
(let [a b
aa bb
ccc {:a b
:aa bb
:ccc ccc
:dddd ::dddd}]))" "(def foo
(let[a b
aa bb
ccc {:a b :aa bb :ccc ccc :dddd ::dddd}]
))"))