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

Alt doc for higher-order functions #1749

Merged
merged 5 commits into from
May 18, 2016
Merged

Alt doc for higher-order functions #1749

merged 5 commits into from
May 18, 2016

Conversation

ckoparkar
Copy link
Contributor

@ckoparkar ckoparkar commented May 15, 2016

Before submitting a PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):

  • The commits are consistent with our contribution guidelines
  • You've added tests (if possible) to cover your change(s)
  • All tests are passing (make test)
  • The new code is not generating bytecode or M-x checkdoc warnings
  • You've updated the changelog (if adding/changing user-visible functionality)
  • You've updated the readme (if adding/changing user-visible functionality)
  • You've updated the refcard (if you made changes to the commands listed there)

Thanks!

@ckoparkar
Copy link
Contributor Author

ckoparkar commented May 15, 2016

I have checked this with these forms:

;; clojure

;; variable. should be blank
var-meta-whitelist

(defn)
(clojure.string/blank?)
(clojure.core/defn)
(str/blank?)
(cider.nrepl.middleware.ns/ns-vars-clj)
(ns/ensure-namespace)
(java/member-info (u/as-sym "java.lang.String") (u/as-sym "length"))
;; invalid. should be empty
(clojure.X/defn)

;; interop
(.length)
(java.lang.String/.length)
;; invalid. should be empty
(java.lang.X/.length)


;; combinations

(map inc [1 2 3 4 5])

(reduce + [1 2 3 4 5])

((comp inc (partial + 3)) 3)

(map :a [{:a 1 :b 2} {:a 3 :b 4}])

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)))
Copy link
Contributor Author

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.

Copy link
Contributor Author

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 ?

@bbatsov
Copy link
Member

bbatsov commented May 15, 2016

There should also be some defcustom to restore the old behaviour, as some people might prefer it.

@ckoparkar
Copy link
Contributor Author

Ill make all the changes and update this PR.

@ckoparkar
Copy link
Contributor Author

Done :-) All the lets still don't look pretty enough, but better than before I guess.

(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
Copy link
Member

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?

@bbatsov
Copy link
Member

bbatsov commented May 15, 2016

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.

@ckoparkar
Copy link
Contributor Author

This actually doesn't get the eldoc for a variable. It only considers the (map inc ...) situation, #1638.
I'll raise another PR with those changes, for #1572.

(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))))
Copy link
Member

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.

@bbatsov
Copy link
Member

bbatsov commented May 16, 2016

This actually doesn't get the eldoc for a variable. It only considers the (map inc ...) situation, #1638.
I'll raise another PR with those changes, for #1572.

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.

@ckoparkar
Copy link
Contributor Author

ckoparkar commented May 17, 2016

@bbatsov This PR just handles what this comment describes here:

Basically we just need to make eldoc consider the symbol-at-point in addition to the first symbol of the list at point (which we currently do). So in a form like (map inc ...) if your cursor is over inc you'd see its docstring and when you move forward you'd see once again the docstring for map.

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. :-)

@bbatsov
Copy link
Member

bbatsov commented May 17, 2016

OK, thanks for the update.

@ckoparkar
Copy link
Contributor Author

I've made all the changes and tested everything. This PR now includes both, eldoc for variables and eldoc for higher order functions.

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.
Copy link
Member

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.

Copy link
Contributor Author

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 ?

Copy link
Member

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. :-)

Copy link
Contributor Author

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 :-)

@ckoparkar
Copy link
Contributor Author

ckoparkar commented May 18, 2016

I'm done with all the changes. Before uploading, wanted to change something else. Is this a little confusing ? How about we change it to var -> font-lock-variable-name-face and fn -> font-lock-function-name-face ?

I'll raise another PR for this. Would be better that way probably.

@ckoparkar
Copy link
Contributor Author

So most of the things are handled in this PR. Found a issue with this.
The cider-eldoc-info-at-point, returns eldoc even if when the cursor is on a line which is commented out.
I want to avoid doing, go back to start of the line, check char at point and then decide. Have we implemented something similar anywhere ?

@Malabarba
Copy link
Member

This checks if you're in a comment or a string:

(let ((s (syntax-ppss)))
  (or (nth 4 s)
      (nth 3 s)))

@bbatsov
Copy link
Member

bbatsov commented May 18, 2016

Just wrap the code @Malabarba shared with you in some helper function and you're good to go.

@expez
Copy link
Member

expez commented May 18, 2016

We already have cider-in-string-p and cider-in-comment-p.

@bbatsov
Copy link
Member

bbatsov commented May 18, 2016

Guess we forgot about them. Good catch!

@bbatsov
Copy link
Member

bbatsov commented May 18, 2016

P.S. I'm a bit surprised those aren't in clojure-mode itself.

@ckoparkar
Copy link
Contributor Author

Thanks! Ready to merge now I think.

@expez
Copy link
Member

expez commented May 18, 2016

P.S. I'm a bit surprised those aren't in clojure-mode itself.

haha ;) I argued for that, and initially opened the PR against that repo, but you felt they belonged in CIDER.

@bbatsov
Copy link
Member

bbatsov commented May 18, 2016

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 clojure-mode itself.

@bbatsov bbatsov merged commit f1f1102 into clojure-emacs:master May 18, 2016
@ckoparkar ckoparkar deleted the feature/eldoc-symbol-at-point branch May 19, 2016 05:20
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.

5 participants