File tree Expand file tree Collapse file tree 2 files changed +17
-12
lines changed
src/cider/nrepl/middleware
test/clj/cider/nrepl/middleware Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Original file line number Diff line number Diff line change 18
18
; ; TODO: Remove this middleware (or make it a no-op).
19
19
20
20
(defn- resolve-pprint-fn
21
- [sym]
22
- (if-let [pp-fn (-> sym u/as-sym find-var)]
23
- pp-fn
24
- (throw (IllegalArgumentException. (format " %s is not resolvable to a var" sym)))))
21
+ " Resolve a namespaced symbol to a printer var. Returns the var or nil if
22
+ the argument is nil or not resolvable."
23
+ [var-sym]
24
+ (when-let [var-sym (and var-sym (symbol var-sym))]
25
+ (try
26
+ (require (symbol (namespace var-sym)))
27
+ (resolve var-sym)
28
+ (catch Exception ex
29
+ (nrepl.misc/log ex " Couldn't resolve printer function" var-sym)
30
+ (require 'cider.nrepl.pprint)
31
+ (resolve 'cider.nrepl.pprint/pprint)))))
25
32
26
33
(defn handle-pprint-fn
27
34
[handler msg]
Original file line number Diff line number Diff line change 143
143
(is (= " {:a 1, :b 2, :c 3}" formatted-edn))
144
144
(is (= #{" done" } status))))
145
145
146
- #_ (testing " format-edn returns an error if the :pprint-fn is unresolvable"
147
- (let [{:keys [err ex status] :as response} (session/message {:op " format-edn"
148
- :edn " {:b 2 :c 3 :a 1}"
149
- :pprint-fn " fake.nrepl.pprint/puget-pprint" })]
150
- (is (.startsWith err " java.lang.IllegalArgumentException: No such namespace: fa" ))
151
- (is (= " class java.lang.IllegalArgumentException" ex))
152
- (is (= #{" done" " format-edn-error" } status))
153
- (is (:pp-stacktrace response)))))
146
+ (testing " format-edn returns fallbacks to a default printer if :pprint-fn is unresolvable"
147
+ (let [{:keys [formatted-edn status] :as response} (session/message {:op " format-edn"
148
+ :edn " {:b 2 :c 3 :a 1}"
149
+ :pprint-fn " fake.nrepl.pprint/puget-pprint" })]
150
+ (is (= " {:b 2, :c 3, :a 1}" formatted-edn))
151
+ (is (= #{" done" } status)))))
You can’t perform that action at this time.
0 commit comments