Skip to content

Commit

Permalink
Fix info op not to return nil as a value of key
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Dec 30, 2019
1 parent 9b0ef8b commit e4b0a13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
Change the format of debugger command messages to a set of command names, leaving key mappings up to client implementations.
* [#653](https://github.com/clojure-emacs/cider-nrepl/pull/653): Add `inspect-def-current-value` to inspect middleware.

### Changes

* [#661](https://github.com/clojure-emacs/cider-nrepl/pull/661): Fix `info` op not to return nil as a value of key.

## 0.22.4 (2019-10-08)

### Changes
Expand Down
11 changes: 11 additions & 0 deletions src/cider/nrepl/middleware/info.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@

(declare format-response)

(defn dissoc-nil-keys
"Dissociate keys which has nil as a value to avoid returning empty list as a nil.
nrepl/bencode converts nil to empty list."
[info]
(reduce-kv
(fn [res k v]
(cond-> res
(some? v) (assoc k v)))
{} info))

(defn format-nested
"Apply response formatting to nested `:candidates` info for Java members."
[info]
Expand Down Expand Up @@ -43,6 +53,7 @@
(info/file-info file))
(when-let [path (:javadoc info)]
(info/javadoc-info path)))
dissoc-nil-keys
format-nested
blacklist
util/transform-value))))
Expand Down
13 changes: 12 additions & 1 deletion test/clj/cider/nrepl/middleware/info_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
[cider.nrepl.test TestClass AnotherTestClass YetAnotherTest]
[org.apache.commons.lang3 SystemUtils]))

(defprotocol FormatResponseTest
(proto-foo [this])
(proto-bar [this] "baz"))

(deftest format-response-test
(is (re-find #"^(https?|file|jar|zip):" ; resolved either locally or online
(-> (info/info {:class "java.lang.Object" :member "toString"})
Expand All @@ -27,7 +31,14 @@
;; used to crash, sym is parsed as a class name
(is (nil? (info/format-response (info/info {:ns "cider.nrepl.middleware.info" :symbol "notincanter.core"}))))
;; unfound nses should fall through
(is (nil? (info/format-response (info/info {:ns "cider.nrepl.middleware.nonexistent-namespace" :symbol "a-var"})))))
(is (nil? (info/format-response (info/info {:ns "cider.nrepl.middleware.nonexistent-namespace" :symbol "a-var"}))))
;; protorol docstring
(is (-> (info/format-response (info/info {:ns "cider.nrepl.middleware.info-test" :symbol "proto-foo"}))
(contains? "doc")
not))
(is (-> (info/format-response (info/info {:ns "cider.nrepl.middleware.info-test" :symbol "proto-bar"}))
(get "doc")
(= "baz"))))

(deftest response-test
(let [v (ns-resolve 'cider.nrepl.middleware.info 'assoc)
Expand Down

0 comments on commit e4b0a13

Please sign in to comment.