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

(cider-javadoc) cannot fetch javadoc for basic Java class such as "java.lang.Integer" #894

Closed
pw4ever opened this issue Nov 24, 2014 · 5 comments
Labels

Comments

@pw4ever
Copy link
Contributor

pw4ever commented Nov 24, 2014

Not sure if this is a "cider" or "cider-nrepl" issue.

With helm-mode enabled, (cider-javadoc) only sees (Helm completions for) Clojure var (e.g., conj) but not Java class (e.g., java.lang.Integer) symbols. Try to enter "Integer" or "java.lang.Integer" result in "[no match]."

Relevant code seems to be:
cider-javadoc-handler

(defun cider-javadoc-handler (symbol-name)
"Invoke the nREPL \"info\" op on SYMBOL-NAME if available."
(when symbol-name
(cider-ensure-op-supported "info")
(let* ((info (cider-var-info symbol-name))
(url (nrepl-dict-get info "javadoc")))
(if url
(browse-url (url-encode-url url))
(error "No Javadoc available for %s" symbol-name)))))

cider-javadoc

(defun cider-javadoc (query)
"Browse Javadoc on the Java symbol QUERY at point."
(interactive "P")
(cider-read-symbol-name "Javadoc for: " 'cider-javadoc-handler query))

cider-var-info

(defun cider-var-info (var &optional all)
"Return VAR's info as an alist with list cdrs.
When multiple matching vars are returned you'll be prompted to select one,
unless ALL is truthy."
(when (and var (not (string= var "")))
(let ((var-info (cider-sync-request:info var)))
(if all var-info (cider--var-choice var-info)))))

So it appears that info of symbols like Integer/java.lang.Integer are not passed along from cider-nrepl client.


CIDER 0.8.1 (package: 20141123.1045) (Java 1.7.0_71, Clojure 1.6.0, nREPL 0.2.6)

~/.lein/profiles

{
:user { :plugins [[cider/cider-nrepl "0.8.1"]] }
}

(cider-classpath)

@pw4ever pw4ever changed the title (cider-javadoc) cannot fetch javadoc for basic class fetch such as "java.lang.Integer" (cider-javadoc) cannot fetch javadoc for basic Java class such as "java.lang.Integer" Nov 24, 2014
@bbatsov
Copy link
Member

bbatsov commented Nov 24, 2014

Yeah, that's a bug. Someone (perhaps me) copied the var completion code in the javadoc handler. I'll have it fixed.

@pw4ever
Copy link
Contributor Author

pw4ever commented Nov 24, 2014

@bbatsov
Not to bug you, but could you elaborate it a bit? I remember not long ago, cider-javadoc works. So to me, this looks like a recent thing.

If this is a simple fix, could you outline the fix? If it takes more in-depth fix, perhaps a brief idea where to start?

Really appreciate your time & work.

@bbatsov
Copy link
Member

bbatsov commented Nov 24, 2014

It works properly for a symbol at point, but when there isn't a symbol at point you'll be presented with a list of var names. We should change this to use cider-read-from-minibuffer instead (it's used in cider-read-and-eval). cider-read-from-minibuffer gives you a minibuffer prompt that provides symbol completion with TAB and M-TAB.

pw4ever added a commit to pw4ever/cider that referenced this issue Nov 24, 2014
…ut Java class name when no "symbol-at-point".

The regression derives from complecting "cider-read-symbol-name" and "cider-completing-read-var": Not all symbols are vars, e.g., Java classes on JVM.

The current solution is to add an optional parameter "notvarp" to "cider-read-symbol-name": When "notvarp" is nil (the default), complete var by the current "cider-completing-read-var"; otherwise (when "notvarp" is t), use "cider-read-from-minibuffer". "cider-javadoc" can call "cider-read-symbol-name" with "notvarp" being t to bypass "cider-completing-read-var".

The logic is that, by its name, "cider-read-symbol-name" should work for both vars and non-var symbols (e.g., Java classes). However, most majority of current use of "cider-read-symbol-name" is for vars. So add a "notvarp" predicate (nil by default) would bridge the semantic gap between "cider-read-symbol-name" and "cider-completing-read-var" without disturbing most uses.

WISHLIST: If only there could be a completion function for Java classes, perhaps derived on the nrepl side by (ns-imports *ns*), ...
pw4ever added a commit to pw4ever/cider that referenced this issue Nov 24, 2014
…ut Java class name when no "symbol-at-point".

The regression derives from complecting "cider-read-symbol-name" and "cider-completing-read-var": Not all symbols are vars, e.g., Java classes on JVM.

The current solution is to add an optional parameter "notvarp" to "cider-read-symbol-name": When "notvarp" is nil (the default), complete var by the current "cider-completing-read-var"; otherwise (when "notvarp" is t), use "cider-read-from-minibuffer". "cider-javadoc" can call "cider-read-symbol-name" with "notvarp" being t to bypass "cider-completing-read-var".

The logic is that, by its name, "cider-read-symbol-name" should work for both vars and non-var symbols (e.g., Java classes). However, most majority of current use of "cider-read-symbol-name" is for vars. So add a "notvarp" predicate (nil by default) would bridge the semantic gap between "cider-read-symbol-name" and "cider-completing-read-var" without disturbing most uses.

WISHLIST: If only there could be a completion function for Java classes, perhaps derived on the nrepl side by (ns-imports *ns*), ...
@pw4ever
Copy link
Contributor Author

pw4ever commented Nov 24, 2014

Indeed, it works when there is symbol at point.

@bbatsov
I have submitted a patch based on your outlined solution via pull request #896. Kindly take a look at it when you have time.

@pw4ever
Copy link
Contributor Author

pw4ever commented Nov 24, 2014

Also, I am not familiar with cider and cider-nrepl enough to know this: Do we have "completion" function for Java classes (perhaps furnished by nrepl through (ns-imports *ns*))?

If we have this, we can have something similar to "cider-completing-read-var" for Java classes, e.g., "cider-completing-read-class".

@bbatsov bbatsov added the bug label Dec 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants