Skip to content

Cannot jump to Java symbols #2819

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

Closed
watkinsr opened this issue Mar 11, 2020 · 12 comments
Closed

Cannot jump to Java symbols #2819

watkinsr opened this issue Mar 11, 2020 · 12 comments
Labels
bug help wanted high priority Tickets of particular importance

Comments

@watkinsr
Copy link

watkinsr commented Mar 11, 2020

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

bbatsov commented Mar 11, 2020

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

watkinsr commented Mar 11, 2020

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

practicalli-johnny commented Mar 22, 2020

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

Hi
clojure-emacs/cider-nrepl#64

@stale
Copy link

stale bot commented Sep 17, 2020

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 stale bot added the stale label Sep 17, 2020
@bbatsov bbatsov added help wanted high priority Tickets of particular importance and removed stale labels Sep 17, 2020
@Solaxun
Copy link

Solaxun commented Nov 5, 2020

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

bbatsov commented Nov 5, 2020

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

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

@vemv
Copy link
Member

vemv commented Aug 29, 2021

A working solution goes like this:

@Solaxun
Copy link

Solaxun commented Aug 31, 2021

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

vemv commented Aug 31, 2021

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

vemv commented Oct 9, 2023

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 vemv closed this as completed Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted high priority Tickets of particular importance
Projects
None yet
Development

No branches or pull requests

7 participants