I was looking "in detail" on the existing javadoc support of Calva, and to my understanding it "should be possible" in Clojure (even being a dynamical typed language), to have javadoc in this situation, when hovering over: the ".version" string. (but I don't see any javadoc popup appearing)
(let [^java.util.UUID my-uuid (java.util.UUID/randomUUID)]
(.version my-uuid))
I want to underline that "completion proposal" works "fully" in this case.
(let [^java.util.UUID my-uuid (java.util.UUID/randomUUID)]
(.| my-uuid))
Having cursor at '|' will only propose the method of UUID class for "completion".
So "it should be possible" to have javadoc (asssuming that the javadocs are found and loaded)
which is for me the case, because I do get javadoc in the same snippet when the cursor is at:
(java.util.UUID/rando|mUUID)
(so for a static function)I get javadoc as well when using this "syntax":
java.util.UUID/.versionThis is for sure interesting, as this is now valid Clojure syntax. So I could write my "production" code as:
(let [my-uuid (java.util.UUID/randomUUID)]
(java.util.UUID/.version my-uuid))
and doing so, would give me full javadoc support, while it does not work for the usual interop style:
(let [my-uuid (java.util.UUID/randomUUID)]
(.version my-uuid))Thanks for investigating this! ๐ Thereโs a command for enabling nrepl message logging. Maybe you see something there that can shed some light?
Maybe the javadoc work sin more situations as I thought:
(let [my-env ^OrtEnvironment (OrtEnvironment/getEnvironment)]
(.getVersion my-env)
(.isTrainingEnabled my-env))
I get javadoc for .getVersion and .isTraining enabled and completion behaves as well as expectedso I think "it should work" under tow conditsion: 1. type hints are added 2. I made sure (somehow) that the "source jars" are present in my local maven repo. The simplest way for downloading them it to run:
clojure -X:deps mvn-pom && mvn dependency:sourcesIf I write the same like this, it javadocs and completion work without type hints: (but we still need the "sources jars" downloaded)
(let [my-env-1 (OrtEnvironment/getEnvironment)]
(OrtEnvironment/.getVersion my-env-1)
(OrtEnvironment/.isTrainingEnabled my-env-1))And here the new "clojure.java.doc" libray could step in, as it allows dynamic download of the javadoc jars (which are enough to render "javadoc"). nrepl (and therefore Calva) uses so far the "sources jars" it seems.
Yes, I saw that Calva gets all javadoc info from nrepl. so maybe we should only document somewhere, this "tips" to make it work in more situations 0. java class is imported 1. type hints are added 2. I made sure (somehow) that the "source jars" are present in my local maven repo. or use "new syntax", and then 2. is not needed any more. but '0' and '2', are still required)
(OrtEnvironment/.isTrainingEnabled my-env-1)
I suggested this documentation as well here: https://github.com/BetterThanTomorrow/calva/issues/2965 The "custom snippet" I put there is the basically an "alternative" way of getting javadoc without the need of 2) But ideally nrepl will integrate the "clojure.java.doc" library one day, so that download of "source jars" is not needed at all anymore for Calva users even when using "calva build in javadoc" But until then, docu of existing javadoc support + example snippet somehwere is probably the way forward
@seancorfield was active in the same area, I just saw: https://ask.clojure.org/index.php/14715/improve-javadoc-especially-for-tool-usage
This is interesting as well: Cider automates partially the "source jars download". "CIDER", not nrepl... So Calva does not get it "for free". https://docs.cider.mx/cider/usage/working_with_documentation.html#obtaining-source-jars
We should follow CIDERโs example there.
yes, probbaly.
I would start by documenting this: 'clojure -X:deps mvn-pom && mvn dependency:sources' Not too bad, but "mvn" required, restart of repl needed, and to be repeated when deps.edn changes.
Doing this and "type hinting" improves the javadoc support considerably, without any work in Calva.
Updates to the docs are welcome!
ok, I give it a go.
Awesome. I merged it. Should be updated in a few moments.
as we have now the existing javadoc support documented in PR2967, its easier to talk about the missing features in Calva. In this code snippet (and if we setup the "source jars" as explained in PR 2967)
(import 'org.apache.commons.io.file.Counters)
(def ^CountingInputStream counter (new CountingInputStream
(java.io.ByteArrayInputStream. (.getBytes "hello"))))
(.readAllBytes counter)
we get 2 nice features:
1. precise completion, when we press "tab" when the cursor is at (.| counter). It only proposes methods available on class CountingInputStream
2. After we have written/completed (.readAllBytes counter) we get javadoc, hovering over "readAllBytes"
What is missing is to get JavaDoc, while we get the completion proposals.
The current "proposal" we see is only the "method name" and the "argument list".
Cider does this and shows the full JavaDoc of the completion proposals while we scroll over them.
I saw in the nrepl-logging, that Calva gets the javadoc "while we scroll down the proposals", but they are not shown.