Just posting here an interesting snippets to show "javavadoc" in an web view, using" flare" and "java.doc" library:
{:name "jdoc"
:key "j"
:snippet
(do
(add-lib 'io.github.clojure/java.doc {:git/tag "v0.1.2" :git/sha "fc518b1"})
(require '[clojure.java.doc.api])
(let [jdoc-info (clojure.java.doc.api/javadoc-data-fn "$selection" nil)
]
(tagged-literal 'flare/html {:html (format "%s\n%s"
(:class-description-html jdoc-info)
(str/join "\n"
(map
(fn [method-doc] (:method-description-html method-doc))
(-> jdoc-info :selected-method)))),
:key "javadoc"
:title "javadoc"}))
)
}
I would like to have it in a popup, as with the clojure documentation, so you have a unified documentation experience.
yes, we started to discuss here: https://github.com/BetterThanTomorrow/calva/issues/2965
Just select: "java.util.StringTokenizer/.countTokens" and run the snippet and it opens the javadoc off class + method in a web view
For reference, the library is this: https://github.com/clojure/java.doc
and we can do even better. With an additional macro it works as well on the more usual
(.countTokens tokenizer) syntax.
(do
(defmacro to-class-instance-form [form]
(str (.getName (class (eval (second form)))) "/" (first form)))
(add-lib 'io.github.clojure/java.doc {:git/tag "v0.1.2" :git/sha "fc518b1"})
(require '[clojure.java.doc.api])
(let [jdoc-info (clojure.java.doc.api/javadoc-data-fn (to-class-instance-form $enclosing-form) nil)
]
(tagged-literal 'flare/html {:html (format "%s\n%s"
(:class-description-html jdoc-info)
(str/join "\n"
(map
(fn [method-doc] (:method-description-html method-doc))
(-> jdoc-info :selected-method)))),
:key "javadoc"
:title "javadoc"}))
)
This is now even easier to use, as it uses the "current-selection",
so when the cursor is in
(.countTokens| tokenizer)
it will do the right thing, and show the javadoc of
java.util.StringTokenizer/.countTokens@pez Maybe this should be "build in" into Calva.
At least in Calva PowerTools, but maybe it actually belongs in Calva. Itโs pretty easy to define a command in the extension manifest that executes a custom command with the code. We could skip giving this command a default keyboard shortcut. Then it would be discoverable via the command palette, and people can assign keys if they like. Please create an issue and we can discuss there.
I'm a bit puzzled as to why Calva is giving me these unresolved var errors for this defcontext macro I'm importing. Is this a clj-kondo config issue?
Thanks! Looks like my version of clojure-lsp is way out of date (2021) so that's probably the cause ๐.
Depends on your Calva settings. If you have configured calva.clojureLspPath, then your ancient version is used. Same if you have pinned that version in calva.clojureLspVersion. Otherwise Calva will download and use latest, or even nightly clojure-lsp, depending on the version setting. But Calva will make no attempt to change your systemโs clojure-lsp.
The whole file, for reference. This is compiling and working correctly in the project, but Calva is still showing the errors.
Itโs clojure-lsp providing these for Calva. You could run:
clojure-lsp diagnostics
In the project root, and see what it says.