cider icon indicating copy to clipboard operation
cider copied to clipboard

Cannot jump to Java symbols

Open watkinsr opened this issue 4 years ago • 11 comments

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

watkinsr avatar Mar 11 '20 00:03 watkinsr

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.

bbatsov avatar Mar 11 '20 08:03 bbatsov

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

watkinsr avatar Mar 11 '20 15:03 watkinsr

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

practicalli-johnny avatar Mar 22 '20 15:03 practicalli-johnny

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

Invertisment avatar Apr 18 '20 14:04 Invertisment

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!

stale[bot] avatar Sep 17 '20 04:09 stale[bot]

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.

Solaxun avatar Nov 05 '20 02:11 Solaxun

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.

bbatsov avatar Nov 05 '20 08:11 bbatsov

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

jeffvalk avatar Jan 21 '21 22:01 jeffvalk

A working solution goes like this:

  • make sure the JDK sources are in your classpath
    • sometimes they are by default, otherwise add them by hand
  • Disable dynapath
  • Use https://github.com/clojure-emacs/enrich-classpath/ for adding arbitrary Java sources for your whole dependency tree
    • (it doesn't add sources for the JDK itself atm, but it's easy enough to do that one by hand)

vemv avatar Aug 29 '21 05:08 vemv

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.

Solaxun avatar Aug 31 '21 16:08 Solaxun

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 avatar Aug 31 '21 16:08 vemv

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

vemv avatar Oct 09 '23 09:10 vemv