clojure-emacs / cider

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

i'm unable to access javadocs #3619

Open drewverlee opened 4 months ago

drewverlee commented 4 months ago

Expected behavior

I expect that running cider-inspect on the symbol KafkaConsumer will display the JavaDocs at the bottom of the cider-inspect buffer.

Actual behavior

It doesn't, instead the cider-inspect buffer will correctly open and display everything (e.g interfaces, constructors, etc..) but the javadocs.

Steps to reproduce the problem

First set emacs variable cider-enrich-classpath to t, then clone this repo, navigate within it using emacs to the file with KafkaConsumer , from that file run cider-jack-in, then with your cursor on KafkaConsumer, run cider-inspect, you should expect to see the cider-inspect emacs buffer to open, if you scroll the the bottom, you don't see the javadocs. In this case, it would be these docs. Which you can get to, as demonstrated here, from emacs using the clojure.java.javadoc/javadoc function if you add the right remote.

Environment & Version information

CIDER version information

Include here the version string displayed when CIDER's REPL is launched. Here's an example:

;; CIDER 1.14.0-snapshot (package: 20240201.2038), nREPL 1.0.0
;; Clojure 1.11.1, Java 17.0.9

Startup: bash /home/drewverlee/.emacs.d/elpa/29.2/develop/cider-20240201.2038/clojure.sh /usr/local/bin/clojure -Sdeps \{\:deps\ \{nrepl/nrepl\ \{\:mvn/version\ \"1.0.0\"\}\ cider/cider-nrepl\ \{\:mvn/version\ \"0.45.0\"\}\}\ \:aliases\ \{\:cider/nrepl\ \{\:main-opts\ \[\"-m\"\ \"nrepl.cmdline\"\ \"--middleware\"\ \"\[cider.nrepl/cider-middleware\]\"\]\}\}\} -M:cider/nrepl

Clojure CLI version

clojure --version Clojure CLI version 1.11.1.1413

Emacs version

GNU Emacs 29.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0) of 2024-02-11

Operating system

Distributor ID: Ubuntu Description: Ubuntu 22.04.3 LTS Release: 22.04 Codename: jammy

JDK distribution

[openjdk version "21.0.1" 2023-10-17 OpenJDK Runtime Environment Homebrew (build 21.0.1) OpenJDK 64-Bit Server VM Homebrew (build 21.0.1, mixed mode, sharing)H

Classpath of example project

/home/drewverlee/.m2/repository/com/billpiel/sayid/0.1.0/sayid-0.1.0.jar
/home/drewverlee/.m2/repository/djblue/portal/0.51.1/portal-0.51.1.jar
/home/drewverlee/.m2/repository/org/apache/kafka/kafka-clients/2.8.0/kafka-clients-2.8.0.jar
/home/drewverlee/.m2/repository/org/clojure/clojure/1.11.1/clojure-1.11.1.jar
/home/drewverlee/.m2/repository/vvvvalvalval/scope-capture/0.3.3/scope-capture-0.3.3.jar
/home/drewverlee/.m2/repository/org/clojure/tools.namespace/1.0.0/tools.namespace-1.0.0.jar
/home/drewverlee/.m2/repository/org/clojure/tools.reader/1.3.2/tools.reader-1.3.2.jar
/home/drewverlee/.m2/repository/tamarin/tamarin/0.1.2/tamarin-0.1.2.jar
/home/drewverlee/.m2/repository/com/cognitect/transit-clj/1.0.333/transit-clj-1.0.333.jar
/home/drewverlee/.m2/repository/com/cognitect/transit-cljs/0.8.280/transit-cljs-0.8.280.jar
/home/drewverlee/.m2/repository/com/google/code/gson/gson/2.10.1/gson-2.10.1.jar
/home/drewverlee/.m2/repository/http-kit/http-kit/2.7.0/http-kit-2.7.0.jar
/home/drewverlee/.m2/repository/org/clojure/data.json/2.4.0/data.json-2.4.0.jar
/home/drewverlee/.m2/repository/com/github/luben/zstd-jni/1.4.9-1/zstd-jni-1.4.9-1.jar
/home/drewverlee/.m2/repository/org/lz4/lz4-java/1.7.1/lz4-java-1.7.1.jar
/home/drewverlee/.m2/repository/org/slf4j/slf4j-api/1.7.30/slf4j-api-1.7.30.jar
/home/drewverlee/.m2/repository/org/xerial/snappy/snappy-java/1.1.8.1/snappy-java-1.1.8.1.jar
/home/drewverlee/.m2/repository/org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.jar
/home/drewverlee/.m2/repository/org/clojure/spec.alpha/0.3.218/spec.alpha-0.3.218.jar
/home/drewverlee/.m2/repository/org/clojure/java.classpath/1.0.0/java.classpath-1.0.0.jar
/home/drewverlee/.m2/repository/com/cognitect/transit-java/1.0.371/transit-java-1.0.371.jar
/home/drewverlee/.m2/repository/com/cognitect/transit-js/0.8.874/transit-js-0.8.874.jar
/home/drewverlee/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.14.2/jackson-core-2.14.2.jar
/home/drewverlee/.m2/repository/javax/xml/bind/jaxb-api/2.4.0-b180830.0359/jaxb-api-2.4.0-b180830.0359.jar
/home/drewverlee/.m2/repository/org/msgpack/msgpack/0.6.12/msgpack-0.6.12.jar
/home/drewverlee/.m2/repository/javax/activation/javax.activation-api/1.2.0/javax.activation-api-1.2.0.jar
/home/drewverlee/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar
/home/drewverlee/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar
drewverlee commented 4 months ago

Calling cider-inspect on CSVReader in (import '(com.opencsv CSVReader)) in the project does show the java docs. Well, it shows some docs at the bottom:

image

This indicates to me that this means the KafkaConsumer failing to get the docs might be unique to the way the Apache Kafka project is put together.

vemv commented 4 months ago

Thanks, sorry for the delay, I had this pending to check out.

enrich-classpath intentionally excludes some .jars. It could be that (which I intend to improve).

It's useful that you reflect that you see it working for at least one case. Similarly the JDK should be an easy case.

drewverlee commented 5 days ago

@vemv How does it choose which source jars to grab?

Here is a link to the source kakfa jar that is currently not being downloaded, that i believe contains the javadoc: https://repo1.maven.org/maven2/org/apache/kafka/kafka-clients/2.8.0/kafka-clients-2.8.0-sources.jar

I can download the sources for the kafka jar to my local repository using the mvn command line tool and it's plugin: mvn dependency:get -Dartifact=org.apache.kafka:kafka-clients:2.8.0:jar:sources

This still doesn't result in cider inspect on the variable KafkaConsumer showing the docs, though they are definatly on my computer, i believe right next to the source files:

e.g assuming i unziped the jar cat org/apache/kafka/clients/consumer/KafkaConsumer.java

Shows the source file including the javadoc.

vemv commented 5 days ago

I'd have to check it in detail.

However if you explicitly add the sources jar to the classpath by hand, it should generally work. Add the jar to your project's :resources.

...there are exceptions, and neither Lein or t.deps support explicitly adding an item at the tail of the classpath. When a .java file is not at the tail, arbitrary issues can happen (I've seen them in various forms) which is why I don't generally advise the technique (and why the enrich-classpath tech has some detailed logic).

But as a quick experiment, please do try it!

drewverlee commented 5 days ago

Modifying my deps.edn to

{:paths ["src" "resources"]
 :deps  {org.apache.kafka/kafka-clients    {:local/root "resources/kafka-clients-2.8.0-sources.jar"}}}

and putting the dep in the corresponding folder:

ls resources/kafka-clients-2.8.0-sources.jar 
resources/kafka-clients-2.8.0-sources.jar

then running cider-jack-in and evaling (import '(org.apache.kafka.clients.consumer KafkaConsumer)) results in the class not being found.

Not surprising, but I wasn't sure if anything would turn a .java file into a class file automatically. Adding the class files back in:

org.apache.kafka/kafka-clients {:mvn/version "2.8.0"}

{org.apache.kafka/kafka-clients           {:mvn/version "2.8.0"}
 org.apache.kafka/kafka-clients-source    {:local/root "resources/kafka-clients-2.8.0-sources.jar" }}

it will now eval (find the class), but cider-inspect still doesn't return the javadoc, and i can't cider-find-val so its likely not finding the source, even though, i feel like i put it on the classpath.

I'm not exactly fixated on this particular package; i'm more curious if you think this is worth trying to improve. Assuming this is a real issue, and i'm not just barking up the wrong tree.

I think currently, my solution to this kind of thing would be to use Intelliji, which, at a certain point of having to dive through Java code, I believe you're forced to do because it has so much more information available. E.g., number of references, etc..

But for emacs users, it would be nice to delay that step, as it comes with a heavy cost.

vemv commented 5 days ago

Yes, you have to depend on the real dep and the source dep.

(normally what enrich-classpath does is adding the source dep)

i feel like i put it on the classpath.

Best way to check it is to inspect the classpath. Or see if something like (clojure.java.io/resource "org/apache/kafka/clients/consumer/KafkaConsumer.java") (must use slahes) returns non-nil.

I'm not exactly fixated on this particular package; i'm more curious if you think this is worth trying to improve.

I'm not sure what 'this' is. Things generally work for the JDK itself (documentation for Thread, Long etc) any many, many packages.

You saw it working for another package in https://github.com/clojure-emacs/cider/issues/3619#issuecomment-1949106858

I also shared misc demos with you here https://clojurians.slack.com/archives/C099W16KZ/p1707539760278099

I can fix specific bugs (which are quite rare) but I'm not sure if you got a proper taster of the base tech. Without that, concrete bugfixes wouldn't make much of a difference for you.

With all this said, I'll be happy to investigate Kafka in particular as time allows, which is why this ticket remains open 🤝