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

Conversation

liquidz
Copy link
Member

@liquidz liquidz commented Dec 28, 2019

  • The commits are consistent with our contribution guidelines
  • You've added tests to cover your change(s)
  • All tests are passing
  • The new code is not generating reflection warnings
  • You've updated the README (if adding/changing middleware)

Currently, the meta data for protocol method without docstring has a nil value for :doc key.

(defn foo [])
(defn bar "..." [])
(defprotocol Dummy
  (hello [this])
  (world [this] "..."))

(meta #'foo)   ; not containing `:doc`
(meta #'bar)   ; containing `:doc`
(meta #'hello) ; containing `:doc`, but nil
(meta #'world) ; containing `:doc`

The nil value is treated as a list by nrepl/bencode, so info op returns a empty list as a docstring for protocol method.
https://github.com/nrepl/bencode/blob/v1.0.0/src/bencode/core.clj#L324

E.g. info response for hello

d12:arglists-str6:[this]3:docle4:file47:file:/.../core.clj4:linei7e4:name5:hello2:ns8:foo.core8:protocol16:#'foo.core/Dummy7:session36:3b4401ac-a962-43b1-8fbc-1c17d
b0477346:statusl4:doneee

# 3:docle <= Here!

Is this an expected behavior?

This PR will dissociate :doc key when the value is nil not to return empty list as a bencode response.

@bbatsov
Copy link
Member

bbatsov commented Dec 29, 2019

Is this an expected behavior?

It is, but it's definitely not ideal as clients can't tell apart an empty list from a nil. Generally it's best to avoid returning empty keys as you suggested.

This PR will dissociate :doc key when the value is nil not to return empty list as a bencode response.

Probably we can have a more generic solution and drop any metadata that's nil from the response. Then the clients would know that if something's missing it's nil.

@liquidz liquidz force-pushed the bugfix/protorol_docstring branch from 5a7ce9a to 525c087 Compare December 29, 2019 23:12
@liquidz
Copy link
Member Author

liquidz commented Dec 29, 2019

@bbatsov Thanks! I fixed a commit.

CI for Java 11, Clojure 1.10 seems failure, but I didn't change anything about cljs-inspect-test and the CI is successful in my local environment.

$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

$ lein with-profile +1.10,+test test cider.nrepl.middleware.cljs-inspect-test

lein test cider.nrepl.middleware.cljs-inspect-test
Warning: Nashorn engine is planned to be removed from a future JDK release

Ran 19 tests containing 50 assertions.
0 failures, 0 errors.

@bbatsov
Copy link
Member

bbatsov commented Dec 30, 2019

Looks good to me. Just mention this fix in the changelog and we're good to go.

@liquidz liquidz force-pushed the bugfix/protorol_docstring branch from 525c087 to e4b0a13 Compare December 30, 2019 10:34
@bbatsov bbatsov merged commit 1a0ea6f into clojure-emacs:master Dec 30, 2019
@bbatsov
Copy link
Member

bbatsov commented Dec 30, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants