-
-
Notifications
You must be signed in to change notification settings - Fork 645
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
Add a spec browser #2025
Add a spec browser #2025
Conversation
Can you add a few screenshot of the new functionality here as a reference? |
Awesome! This is going to be great ;) |
Sorry clicked the wrong button and closed the PR |
Oh man, this is so cool, @jpmonettas! Fantastic work! 👍 |
cider-browse-spec.el
Outdated
(cider-browse-spec--propertize-fn spec-name))))) | ||
(goto-char (point-min))))) | ||
|
||
(defun ns-keywordp (str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clojure calls this qualified-keyword?
in 1.9 and we might want to stick with that, i.e. qualfied-keyword-p
cider-browse-spec.el
Outdated
;; and remove all clojure.core ns | ||
(thread-last form | ||
(replace-regexp-in-string "^\\(clojure.spec\\|clojure.spec.alpha\\)/" "s/") | ||
(replace-regexp-in-string "^\\(clojure.core\\)/" ""))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is super helpful! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I even wonder if this one should go in clojure-mode
somehow or some place where it can be added to inf-clojure
as well...need to think about that
cider-browse-spec.el
Outdated
(provide 'cider-browse-spec) | ||
|
||
|
||
(provide 'cider-browse-spec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double provide
here
I was excited at the screenshots, but even more so after reading the code. Beautiful work, @jpmonettas! This needs a rebase on master, but otherwise looks like it's ready for a merge and testing by early (eager?) adopters. |
You'll have to rebase on top of the current master. |
(push cider-browse-spec-buffer cider-ancillary-buffers) | ||
(push cider-browse-spec-example-buffer cider-ancillary-buffers) | ||
|
||
(defvar cider-browse-spec-navigation '() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be buffer-local?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm if I make this buffer-local I'll need to surround code that works with the navigation state inside (with-current-buffer ) and for me when I see that I'm expecting that piece of code to read or write the buffer. Am I right?
cider-browse-spec.el
Outdated
;; Non interactive functions | ||
|
||
(defun cider-browse-spec--clear-nav-history | ||
() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Elisp - params should be on the previous line. :-)
cider-browse-spec.el
Outdated
|
||
(defun spec-fn-p (value fn-name) | ||
"Return non nil if VALUE is clojure.spec.[alpha]/FN-NAME." | ||
(and (stringp fn-name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the the type check needed? Seems unlispy to me. Same for the previous function.
cider-browse-spec.el
Outdated
|
||
(defun cider-browse-spec--pprint (form) | ||
"Given a spec FORM builds a multi line string with a pretty render of that FORM." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This this blank line.
cider-browse-spec.el
Outdated
|
||
(cond ((ns-keywordp form) | ||
(cider-browse-spec--propertize-keyword form)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general kill all such blank lines. They make the code harder to read IMO.
A couple of other thoughts:
|
I just pushed the code changes suggested above. Regarding @bbatsov thoughts:
didn't fully understood that, do you mean that cider-browse-spec-all should receive a query that can be a regex or a list of words and concat them in a regex?
under what menu should I put this commands?
I can do something for that, but should't the specs in the doc come from the fns in the spec middleware (so everything comes from the same place) and be pprinted with the same rules? I'm thinking about things like multi-spec, you can't browse them otherwise |
Yeah, that's one aspect of it. The other was that visually the buffer could be made to look more similar to apropos, but that's not a big deal. In general I really dislike this type of UI (the first browser was put together very quickly and we never got to improving it, but we did copy this for other browsers; and at some point I was planning to extract a bit of common code). Anyways, better some solution that works, than nothing.
Guess you can put those somewhere near the ns browser references. |
Absolutely! That's certainly be an improvement over the current situation. |
cad1fbc
to
11b543b
Compare
A huge thanks for working on this from me! Hopefully we'll see more such awesome contributions from you!
Sounds like a plan to me. Don't forget about the manual as well. ;-) |
this is amazing! thanks a lot! |
First of all, thanks @jpmonettas, I am going to pull
This is an idea I had as well. what if we create an |
@bbatsov @expez @arichiardi hey glad I can help. First I should say thanks to you guys for all the hard work on the tool I've been using the past 5 years everyday. I've some free time now so I'll be trying to contribute to the proyect wherever I can. |
This was introduced by clojure-emacs/cider#2025.
This was introduced by clojure-emacs/cider#2025.
This was introduced by clojure-emacs/cider#2025.
This was introduced by clojure-emacs/cider#2025.
Spec browsing is introduced in CIDER by clojure-emacs/cider#2025.
Added a spec browser thru
cider-browser-spec
andcider-browse-spec-all
.The browser uses the functionality provided by the cider-nrepl spec middleware (see clojure-emacs/cider-nrepl#423) wich provides spec-list, spec-form and spec-example.
Using this it creates a buffer, a major mode, and a navigation stack to let you navigate into sub specs and back using keyboard or mouse, functionality that has been asked for in issues like:
#1918
#1919
#1901
Drawing the buffer uses
cider-browse-spec--pprint
that prints the spec form nicer by applyingrules to specific spec forms, hiding or shortening ns, etc. I don't like the current implementation, I think this can be improved, but I think it's important to do a custom print of different kinds of specs and specs combinators to have a better user experience.
Buttercup tests are comming!
It's the first time I create a pull request for Cider so probably I'm missing something.
Thanks for all the hard work on Cider btw!
Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
make test
)M-x checkdoc
warnings