clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.55k stars 645 forks source link

Cannot jump to Java symbols #2819

Closed watkinsr closed 1 year ago

watkinsr commented 4 years ago

Expected behavior

Succesfully jump to java source files

Actual behavior

No symbol found

Steps to reproduce the problem

M-. on a given java symbol like (.toUpperClass)

Environment & Version information

CIDER version information

;; CIDER 0.25.0snapshot (package: 20200225.1516)
;; Clojure 1.8, Java 1.8.0_232

Lein/Boot version

Lein 2.9.1

Emacs version

Emacs 28.0.50

Operating system

Gentoo

bbatsov commented 4 years ago

Have you installed the JDK source package? You have to have the JDK sources on your classpath for the lookup to work. You can also point CIDER manually to some sources using cider-jdk-src-paths.

watkinsr commented 4 years ago

Hey @bbatsov so I did install the docs and source for the icedtea-3.* package which is basically java 8. I also saw in the docs to set cider-jdk-src-paths so I set this to a src.zip file I believe in my $JAVA_HOME. One thing I did notice is I do not have a $CLASSPATH.

For what it's worth, when there is a backtrace involving a java class, I can go directly to the file but I cannot do this in say a normal buffer containing a java class, i.e. (.toUpperCase "foo")

practicalli-johnny commented 4 years ago

Adding the directory of the extracted Java src.zip to the cider-jdk-src-paths does not allow me to use cider-find-var on Java objects or method. In the mini-buffer I get the message "No source location".

(setq cider-jdk-src-paths '("~/projects/java/clojure-1.10.1-sources"
                              "~/projects/java/openjdk-11/src"))

I can confirm that cider-find-var does navigate to sources once those sources are on the classpath via the build configuration.

I am using a deps.edn project rather than Leiningen (although that shouldn't make any different to CIDER).

CIDER: 0.25.0snapshot (package: 20200227.1414) Emacs: 26.3 OS: Ubuntu Linux Java: openjdk 11 Clojure CLI: version "1.10.1.507" Java Sources: version 11 - added with Ubuntu package openjdk-11-source added as an alias https://practicalli.github.io/spacemacs/navigating-code/java-definitions.html

Invertisment commented 4 years ago

Hi https://github.com/clojure-emacs/cider-nrepl/issues/64

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

Solaxun commented 3 years ago

Echoing @jr0cket above - I spent the past few hours reading through all the related issues and the only thing that seemed to work to enable cider-find-var to correctly jump to java source was explicitly including it in the build tool (in my case lein).

For example, added to project.clj:

:java-source-paths ["/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/src.zip"]

I had almost given up, and in fact after trying last night before finding this tip I had installed Cursive and spent a few hours porting all my shortcuts over. I'm not sure how Cursive has accomplished this, but when setting up a lein project, there was no need to specify source, it just worked. The project.clj file in Cursive also appears unmodified and has no reference to the :java-source-paths , so some sort of sorcery is going on to make it work I guess.

I know it was mentioned above that it largely depends on the build tool, but somehow they've got it working in Cursive so there must be a path. My primary concern with this approach is that when I change JDK at some point in the future, I'll likely forget to adjust the :java-source-paths.

Anyhow - just thought I'd leave this here for future reference, and to mention that I think it is still an open issue as some others of similar nature have been consistently marked stale. Also I don't want to give the impression I keep mentioning Cursive as some sort of slight towards CIDER, which I love, just wanted to mention that they seem to have a solution which could possibly inform this issue.


EDIT:

I celebrated prematurely. Jumping to Java source only works some of the time, probably due to type inference issues but I can't be certain. I guess for heavy interop projects this just might not be in the cards.

bbatsov commented 3 years ago

The project.clj file in Cursive also appears unmodified and has no reference to the :java-source-paths , so some sort of sorcery is going on to make it work I guess.

IntelliJ knows a lot about Java sources in general. :-) It's hard for us to match their work.

Btw, CIDER's approach used to work for years pretty well without much additional setup for the JDKs, so I'm still puzzled what went wrong on JDK 8 (on JDK 9+ it's clear that the modules messed up everything). The situation is definitely fixable, but I haven't had time to dive into this for a while now.

Potentially you can address the problem by using lsp-mode along-side CIDER, as I assume their navigation to Java sources is better.

I celebrated prematurely. Jumping to Java source only works some of the time, probably due to type inference issues but I can't be certain. I guess for heavy interop projects this just might not be in the cards.

If you can provide more details about the issues that'd be helpful.

jeffvalk commented 3 years ago

I think may be (yet another) duplicate of clojure-emacs/orchard#103.

vemv commented 3 years ago

A working solution goes like this:

Solaxun commented 3 years ago

I appreciate you taking the effort to post a work-around @vemv but jump-to-source is table-stakes for any editor and it should be something that just works without tinkering (easier said than done I'm sure). It seems after more than a year that this is still not the case, which is unfortunate but I suppose beggars can't be choosers.

vemv commented 3 years ago

We're working on it! I'm also not posting a workaround, but a preview of how CIDER will work. You can get the same featureset today by performing those steps.

That would be actually valuable feedback. We prefer to find surprises today than after a big announcement.

Cheers - V

vemv commented 1 year ago

enrich-classpath has been a reality for the last few months.

Revamped documentation: https://docs.cider.mx/cider/config/basic_config.html#use-enrich-classpath

You can check this recent announcement for a tour of our current capabilities: https://clojurians.slack.com/archives/C0617A8PQ/p1696618492372739