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

Create a spec browser, similar to the namespace browser #1918

Closed
expez opened this issue Jan 12, 2017 · 5 comments
Closed

Create a spec browser, similar to the namespace browser #1918

expez opened this issue Jan 12, 2017 · 5 comments

Comments

@expez
Copy link
Member

expez commented Jan 12, 2017

Often I find myself wondering either:

  • Does a spec for this exist?
  • What does this spec really do?

I'd like something like cider-browse-ns which gives me a list of all available specs in the app. We can get this by querying the registry of known specs.

When you click on a spec the definition of the spec should be displayed (this is available with (s/form (s/get-spec :qualified/spec)))

Bonus points if the buffer can be sorted in two different ways:

  • Fully qualified (my-longish-prefix/some-spec)
  • On the suffix only (some-spec)

The latter sort is useful because it would group:

  • user/id
  • line-item/id

Together when you search for id.

Additional bonus points if you can query nested specs, i.e. after hitting RET on a spec, in the browser, to show its definition, it would be nice to be able to click on constituent spec definitions in the popup buffer to see their definitions.

@bbatsov bbatsov changed the title cider-browse-specs Create a spec browser, similar to the namespace browser Jan 12, 2017
@ckoparkar
Copy link
Contributor

I've started work on this. Is adding a separate middleware for spec alright ? I guess we'll be adding a lot more feature focusing on spec.

@bbatsov
Copy link
Member

bbatsov commented Jan 14, 2017

Sure.

@dpsutton
Copy link
Contributor

dpsutton commented Mar 21, 2017

@cskksc can you tell me how you're checking for the existence of spec?

I've had conversations with some clojure core people, and nothing about spec is official. From what I've gathered, spec will be packaged with >1.9 and won't need to be a listed dependency in the project.clj file, nor will it have a version (ie, cider-nrepl on 1.4 and the person's project on 1.8 or whatever). However, we can't require this in the file if the clojure version is <1.9. Alex Miller mentioned there was no plan to separate out into its own dependency (think core.match) nor will it be backported.

I was just wondering what your middleware layer will look like and how it will degrade nicely in the presence of clojures 1.7 or 1.8.

This should definitely be standardized and will be a conditional wart on CIDER while we support versions prior to spec.

@ckoparkar
Copy link
Contributor

@dpsutton We already have something similar in the middleware at spec.clj, and it's used in info.clj, to display the associated spec with docstrings.

Although, when I started working on this particular feature, instead of re-defining the clojure.spec/* functions in our namespace, I used a macro instead.

(defmacro with-spec
  [body]
  `(when (find-ns (symbol "clojure.spec"))
     ~body))

(with-spec
    (->> (clojure.spec/registry)
            (reduce (fn [acc [k v]]
                            (merge acc (spec-with-meta k)))
                         {})))

@bbatsov
Copy link
Member

bbatsov commented Jul 8, 2017

Fixed by #2025.

@bbatsov bbatsov closed this as completed Jul 8, 2017
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

4 participants