File tree 2 files changed +54
-2
lines changed
2 files changed +54
-2
lines changed Original file line number Diff line number Diff line change 259
259
(defn- reader-conditional? [zloc]
260
260
(and (reader-macro? zloc) (#{" ?" " ?@" } (-> zloc z/down token-value str))))
261
261
262
+ (defn- find-next-keyword [zloc]
263
+ (z/find zloc z/right #(n/keyword-node? (z/node %))))
264
+
265
+ (defn- first-symbol-in-reader-conditional [zloc]
266
+ (when (reader-conditional? zloc)
267
+ (when-let [key-loc (-> zloc z/down z/right z/down find-next-keyword)]
268
+ (when-let [value-loc (-> key-loc z/next skip-meta)]
269
+ (when (token? value-loc)
270
+ (z/sexpr value-loc))))))
271
+
262
272
(defn- form-symbol [zloc]
263
- (-> zloc z/leftmost token-value))
273
+ (let [zloc (z/leftmost zloc)]
274
+ (or (token-value zloc)
275
+ (first-symbol-in-reader-conditional zloc))))
264
276
265
277
(defn- index-matches-top-argument? [zloc depth idx]
266
278
(and (> depth 0 )
Original file line number Diff line number Diff line change 697
697
" :cljs bar)" ]
698
698
[" #?@(:clj foo"
699
699
" :cljs bar)" ])
700
- " splicing syntax" ))
700
+ " splicing syntax" )
701
+ (testing " symbols using reader conditionals should indent correctly"
702
+ (let [opts {:indents '{defprotocol [[:block 1 ] [:inner 1 ]]
703
+ potemkin/defprotocol+ [[:block 1 ] [:inner 1 ]]}}]
704
+ (testing " standard syntax"
705
+ (is (reformats-to?
706
+ [" (#?(:clj potemkin/defprotocol+ :cljs defprotocol) MyProtocol"
707
+ " \" This is a docstring for my protocol.\" "
708
+ " (method [this x]"
709
+ " \" This is a docstring for a protocol method.\" )"
710
+ " )" ]
711
+ [" (#?(:clj potemkin/defprotocol+ :cljs defprotocol) MyProtocol"
712
+ " \" This is a docstring for my protocol.\" "
713
+ " (method [this x]"
714
+ " \" This is a docstring for a protocol method.\" ))" ]
715
+ opts)
716
+ " :clj and :cljs" ))
717
+ (is (reformats-to?
718
+ [" (#?(:clj potemkin/defprotocol+) MyProtocol"
719
+ " \" This is a docstring for my protocol.\" "
720
+ " (method [this x]"
721
+ " \" This is a docstring for a protocol method.\" )"
722
+ " )" ]
723
+ [" (#?(:clj potemkin/defprotocol+) MyProtocol"
724
+ " \" This is a docstring for my protocol.\" "
725
+ " (method [this x]"
726
+ " \" This is a docstring for a protocol method.\" ))" ]
727
+ opts)
728
+ " only :clj" )
729
+ (is (reformats-to?
730
+ [" (#?(:cljs ^:wow defprotocol) MyProtocol"
731
+ " \" This is a docstring for my protocol.\" "
732
+ " (method [this x]"
733
+ " \" This is a docstring for a protocol method.\" )"
734
+ " )" ]
735
+ [" (#?(:cljs ^:wow defprotocol) MyProtocol"
736
+ " \" This is a docstring for my protocol.\" "
737
+ " (method [this x]"
738
+ " \" This is a docstring for a protocol method.\" ))" ]
739
+ opts)
740
+ " only :cljs; skip metadata in front of symbol" ))))
701
741
702
742
(testing " namespaced maps"
703
743
(is (reformats-to?
You can’t perform that action at this time.
0 commit comments