Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix info op not to return nil as a document for protocl #661

Merged
merged 1 commit into from
Dec 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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