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

Display Clojure.spec in the doc buffer #1769

Closed
Malabarba opened this issue May 27, 2016 · 19 comments
Closed

Display Clojure.spec in the doc buffer #1769

Malabarba opened this issue May 27, 2016 · 19 comments

Comments

@Malabarba
Copy link
Member

According to http://clojure.org/about/spec

Functions specs defined via fdef will appear when you call doc on the fn name. You can call describe on specs to get descriptions as forms

We should probably ensure that cider doc buffers display the same information.

@bbatsov
Copy link
Member

bbatsov commented May 28, 2016

Yep, we should probably do this, although 1.9 is not going to be released for a while, so this is definitely not something particularly important right now.

@Malabarba
Copy link
Member Author

Here's an example of what we'd like to display: http://clojure.github.io/java.jdbc/#clojure.java.jdbc/create-table-ddl

@ckoparkar
Copy link
Contributor

I'd like to take this up. I'll submit a PR soon.

@bbatsov
Copy link
Member

bbatsov commented Jul 10, 2016

Great!

@expez
Copy link
Member

expez commented Aug 4, 2016

You still interested in taking this on, @cskksc?

@ckoparkar
Copy link
Contributor

ckoparkar commented Aug 4, 2016

Yep. But I have been traveling for the last couple of weeks. I'll finish this by Tuesday next week :-) Is that ok ?

@bbatsov
Copy link
Member

bbatsov commented Aug 4, 2016

Absolutely. It's not like Clojure 1.9 is even released yet... :-)

@bbatsov
Copy link
Member

bbatsov commented Aug 21, 2016

@cskksc Any updates here?

@ckoparkar
Copy link
Contributor

I'm done with the nREPL changes. The elisp interface should be done soon. Got caught in some university work. Sorry, I forgot to post an update here.

@lvh
Copy link

lvh commented Aug 23, 2016

I don't know if it's relevant, but clojure.repl/doc exposes this for you.

@ckoparkar
Copy link
Contributor

ckoparkar commented Aug 23, 2016

@ivh Yep. Even clojure.spec has fn's for this. The nREPL would return (clojure.spec/describe (clojure.spec/get-spec namespace-qualified-var)) and we just have pretty-print this into the doc buffers.

@ckoparkar
Copy link
Contributor

ckoparkar commented Aug 25, 2016

For the ranged-rand example from the guide;

(require '[clojure.spec :as s])

(defn ranged-rand
  "Returns random int in range start <= rand < end."
  [start end]
  (+ start (long (rand (- end start)))))

(s/fdef ranged-rand
        :args (s/and (s/cat :start int? :end int?)
                     #(< (:start %) (:end %)))
        :ret int?
        :fn (s/and #(>= (:ret %) (-> % :args :start))
                   #(< (:ret %) (-> % :args :end))))

this is how our doc buffers would look.

screen shot 2016-08-25 at 8 04 37 am

Does it look ok ? I just have to write tests and tidy up some code before submitting a PR.

@ckoparkar
Copy link
Contributor

ckoparkar commented Aug 25, 2016

I mean it looks exactly same as the clojure.repl/doc fn displays it. Do we want to change/add anything ? I was thinking of adding something like "Spec is defined here: hyperlink". I'm not sure if the API provides metadata for this, but I'm gonna check that now. Also, it would only make sense to have something like this for spec's defined in the user controlled namespaces.

@expez
Copy link
Member

expez commented Aug 25, 2016

I think it makes more sense to add the location of the function at the bottom instead of between the docstring and the spec. This is because I view the spec to be part of the documentation.

This is obviously a minor thing, so don't spend any time on it if it's hard to change.

@ckoparkar
Copy link
Contributor

ckoparkar commented Aug 25, 2016

@expez Done :-)

screen shot 2016-08-25 at 8 27 57 am

@expez
Copy link
Member

expez commented Aug 25, 2016

👍

@lvh
Copy link

lvh commented Aug 25, 2016

Looks awesome to me :)

@Malabarba
Copy link
Member Author

👍

@bbatsov
Copy link
Member

bbatsov commented Aug 26, 2016

Looks good indeed.

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

No branches or pull requests

5 participants