clojure-emacs / cider

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

cider-find-var doesn't work for all java classes #1666

Closed expez closed 5 years ago

expez commented 8 years ago
Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  compare-strings("*" nil nil nil 0 1 nil)
  string-prefix-p("*" nil)
  cider--jump-to-loc-from-info((dict "status" ("done") "class" "org.joda.time.Period" "id" "2535" "interfaces" ("org.joda.time.ReadablePeriod" "java.io.Serializable") "javadoc" "org/joda/time/Period.html" "modifiers" "#{:public :final}" "name" "Period" "package" "org.joda.time" "session" "450c9c46-a161-4bda-9ad8-e961666d6a52" "super" "org.joda.time.base.BasePeriod"))
  cider--find-var("org.joda.time.Period")
  cider-read-symbol-name("Symbol" cider--find-var)
  cider-find-var(nil)
  call-interactively(cider-find-var nil nil)
  command-execute(cider-find-var)

Not entirely sure what's special with Period. Jumping to e.g. java.lang.Exception works fine. Perhaps it's that it's in a jar.

;; Connected to nREPL server - nrepl://localhost:51749
;; CIDER 0.12.0snapshot (package: 20160410.2022), nREPL 0.2.12
;; Clojure 1.7.0, Java 1.8.0_66
bbatsov commented 8 years ago

Likely the source jar is not on the classpath.

expez commented 8 years ago

Likely the source jar is not on the classpath.

This happened with org.joda.time.Period IIRC. Does it not work because that jar is pulled in by clj-time?

bbatsov commented 8 years ago

Probably. It likely pulled just the compiled classes, but you also need the source jar for source lookup to work.

bbatsov commented 8 years ago

Btw, you shouldn't be getting an error, but some message saying the source can't be found. That's odd...

bbatsov commented 8 years ago

I tested this and got a No source location message (as expected). Maybe we can improve this message a bit...

vspinu commented 8 years ago

Is there a known workaround for this? I have manually built and installed maven project which contains both source and javadoc jars. CIDER cannot locate neither source nor javadoc.

vspinu commented 8 years ago

Just found a rudimentary workaround by manually adding jar files to lein's :resource-paths.

bbatsov commented 7 years ago

Guess we can close this then. Unless someone wants to contribute some documentation on the subject?

dpsutton commented 7 years ago

I'll have to get up to speed but I can do it tomorrow

On Oct 8, 2016 12:25 PM, "Bozhidar Batsov" notifications@github.com wrote:

Guess we can close this then. Unless someone wants to contribute some documentation on the subject?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/clojure-emacs/cider/issues/1666#issuecomment-252437249, or mute the thread https://github.com/notifications/unsubscribe-auth/AGFPTcAUxsuCmd54yxLRvm52RN-uHxqGks5qx9IUgaJpZM4IFO1w .

bbatsov commented 7 years ago

@dpsutton Sounds good.

dpsutton commented 7 years ago

I've been trying to figure this out. I've built a project mvn install and then referenced it. I got no errors, just info that no documentation was found when trying to view docs. @vspinu can you help shed some light on circumstances that could trigger an error?

bbatsov commented 7 years ago

I think a larger point is that we haven't documented at all how one can add source jars to their lein/boot project.

expez commented 7 years ago

@vspinu I tried adding paths to jars in :resource-paths and I still can't jump to the java source nor view its documentation. What did you do?

vspinu commented 7 years ago

Just that, added full paths to the :resource-paths

  :resource-paths ["/home/vspinu/.m2/repository/com/interactivebrokers/tws-api/9.71.1/tws-api-9.71.1-sources.jar"
                  "/home/vspinu/.m2/repository/com/interactivebrokers/tws-api/9.71.1/tws-api-9.71.1-javadoc.jar"]

Did the trick for me, both for refs and javadocs.

vspinu commented 7 years ago

Documenting this is just passing the ball to the user. How hard would it be to check for -sources.jar or-javadoc.jar and add them to the classpath dynamically?

expez commented 7 years ago

Thanks, the mistake was mine, I added the wrong jar (with only .class files).

It would be easy to check for jars, but where would we check?

vspinu commented 7 years ago

but where would we check?

In the parent directory of the class jar.

vspinu commented 6 years ago

The trick with :resource-path no longer works. Has something changed in the java-ref lookup in the past 7 months or so?

I now see a lot "bad source file" errors like this when I first call cider-find-var:

  bad source file: /home/vspinu/.m2/repository/io/netty/netty-transport/4.1.22.Final/netty-transport-4.1.22.Final-sources.jar(io/netty/channel/ChannelFactory.java)
    file does not contain class io.netty.channel.ChannelFactory
    Please remove or make sure it appears in the correct subdirectory of the sourcepath.

If I check manually I do see an interface ChannelFactory in that java file.

vspinu commented 6 years ago

Another simple workaround for this is to use tags instead

## fetch sources and javadocs
lein pom
mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

## build tags
mkdir java-sources && cd java-sources
jar -xvf ~/.m2/repository/io/netty/netty-all/4.0.23.Final/netty-all-4.0.23.Final-sources.jar
ctags -eR 
stale[bot] commented 5 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!

bbatsov commented 5 years ago

The trick with :resource-path no longer works. Has something changed in the java-ref lookup in the past 7 months or so?

@jeffvalk is our resident expert here. I don't recall any changes in this area for quite a while until very recently. It still seems to me that the only thing needed for the lookup to work should be for the source artifacts to be on the classpath.

jeffvalk commented 5 years ago

Is this still an issue? If the source is on the classpath, info should work for java sources. The JDK sources are added to classpath by Orchard. Anything else, the user would need to add in project.clj, etc.

stale[bot] commented 5 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!

stale[bot] commented 5 years ago

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.