-
-
Notifications
You must be signed in to change notification settings - Fork 648
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
Alt doc for higher-order functions #1749
Alt doc for higher-order functions #1749
Conversation
I have checked this with these forms:
Please try out once :-) |
(unless (member (or (char-after (1- (point))) 0) '(?\" ?\{ ?\[)) | ||
(list (cider-symbol-at-point) argument-index))))) | ||
(let ((thing-at-point (cider-symbol-at-point)) | ||
(pos-thing-at-point (point))) |
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'm not sure if this is right. But even without this var, eldoc seems to work correctly.
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 think I should remove this var. It highlights the argument, but it is subtle so I din't notice the difference. But in a sexp like (map inc ...)
, inc wouldn't have any arguments to highlight.
And even if the mapping function is something like +
which can take 2 args, the cursor position would be such that it would never need to highlight the arguments.
Does this make sense ?
There should also be some |
Ill make all the changes and update this PR. |
Done :-) All the |
(unless (member (or (char-after (1- (point))) 0) '(?\" ?\{ ?\[)) | ||
(list (cider-symbol-at-point) argument-index))))) | ||
(let ((sym-at-point (cider-symbol-at-point))) | ||
;; cider-eldoc-beginning-of-sexp is nil for variables |
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 comment makes it sound like nothing will be done if we're not at the beginning of sexp. Could you elaborate to make it clearer?
The highlighting of the current argument doesn't make sense for the symbol at point's docstring, but makes a lot of sense for everything else. And as far as higher order functions go I believe the idea on the ticket for them was to hardcode a list of known such functions and to have some special treatment for them. That's not something important, I'm just pointing it out. Also now that you can get an eldoc for the variable name at point - we should font-lock the type of the eldoc and for variables we should probably show the first line of their docstring as they don't have arguments. This is how eldoc works for variables in Elisp. |
(sym-at-sexp-beginning (unless (member (or (char-after (1- (point))) 0) '(?\" ?\{ ?\[)) | ||
(cider-symbol-at-point))) | ||
(sym-at-point-eldoc-info (cider-eldoc-info (cider--eldoc-remove-dot sym-at-point))) | ||
(sym-at-sexp-beginning-eldoc-info (cider-eldoc-info (cider--eldoc-remove-dot sym-at-sexp-beginning)))) |
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.
Inline this function call so we'll don't do the request when we don't have to.
Meaning that you'll get eldoc for the second symbol after your cursor goes pass it? Or you just get eldoc at point for whatever symbol now? I still don't quite get what exactly does the PR solve. |
@bbatsov This PR just handles what this comment describes here:
For the eldoc of any form at point, we require a small nrepl change here. I was a bit busy yesterday so I couldn't follow up on this. But I'm gonna finish both of these tickets today. I've already made the nrepl change, just have to change the elisp interface. I'll submit the nrepl PR, and the "eldoc for any form at point including variables" and all the changes @Malabarba suggested here, by tonight. :-) |
OK, thanks for the update. |
I've made all the changes and tested everything. This PR now includes both, I've tried to make the functions small enough to avoid comments all together. There's probably some scope for more refactoring here, but haven't made any of those changes here. Depends on clojure-emacs/cider-nrepl#360. |
@@ -17,6 +17,7 @@ | |||
* [#1720](https://github.com/clojure-emacs/cider/issues/1720): Add a command `cider-eval-sexp-at-point` to evaluate the form around point (bound to `C-c C-v v`). | |||
* [#1564](https://github.com/clojure-emacs/cider/issues/1564): CIDER's internal namespaces and vars are filtered from the ns-browser and apropos functions. | |||
* [#1725](https://github.com/clojure-emacs/cider/issues/1725): Display class names in eldoc for interop forms. | |||
* [#1638](https://github.com/clojure-emacs/cider/issues/1638): Alternate documentation for higher-order functions. |
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.
Just to clarify - the issue about alternative eldoc for higher order functions was different, so I wouldn't call this HOF-related. The idea there was in a situation like this:
(map inc [1 2 3|])
to show the eldoc for inc
, not map
(| denotes the cursor). This means this cannot be generic, as changing the eldoc like this doesn't make sense for every higher order function - it should be applied just for a list of know functions.
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.
Oh. That makes sense. The first thing to do is change the commit message probably so the issue isn't incorrectly closed. And the commit should still be merged right ?
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.
Yep. The references you were using were the primary source of my confusion - as what was suggested in the ticket was different and I said we can simplify it if we extend my idea about variable eldoc to all symbols at point. :-)
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.
Yeah.. Sorry about that. Now I understand correctly 💡 . I'll change that in another PR though. This one is huge even now :-)
I'll raise another PR for this. Would be better that way probably. |
So most of the things are handled in this PR. Found a issue with this. |
This checks if you're in a comment or a string:
|
Just wrap the code @Malabarba shared with you in some helper function and you're good to go. |
We already have |
Guess we forgot about them. Good catch! |
P.S. I'm a bit surprised those aren't in |
Thanks! Ready to merge now I think. |
haha ;) I argued for that, and initially opened the PR against that repo, but you felt they belonged in CIDER. |
Now I remembered - my concern was that we weren't using them anywhere in |
Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
make test
)M-x checkdoc
warningsThanks!