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 1818; ; TODO: Remove this middleware (or make it a no-op).
1919
2020(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)))))
2532
2633(defn handle-pprint-fn
2734 [handler msg]
Original file line number Diff line number Diff line change 143143 (is (= " {:a 1, :b 2, :c 3}" formatted-edn))
144144 (is (= #{" done" } status))))
145145
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