calva

2025-11-21T17:40:55.046679Z

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"}))
     
     )
   }
  

๐Ÿ™ 3
Ludger Solbach 2025-11-22T09:06:16.609839Z

I would like to have it in a popup, as with the clojure documentation, so you have a unified documentation experience.

๐Ÿ‘ 1
2025-11-22T19:15:55.960419Z

yes, we started to discuss here: https://github.com/BetterThanTomorrow/calva/issues/2965

2025-11-21T17:42:39.917379Z

Just select: "java.util.StringTokenizer/.countTokens" and run the snippet and it opens the javadoc off class + method in a web view

2025-11-21T17:43:39.112079Z

For reference, the library is this: https://github.com/clojure/java.doc

2025-11-21T18:06:34.322039Z

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

2025-11-21T18:08:41.168159Z

@pez Maybe this should be "build in" into Calva.

pez 2025-11-21T20:52:30.771639Z

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.

๐Ÿ‘ 1
Jack Arrington 2025-11-21T04:27:26.074739Z

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?

Jack Arrington 2025-11-21T08:55:22.286229Z

Thanks! Looks like my version of clojure-lsp is way out of date (2021) so that's probably the cause ๐Ÿ™‚.

pez 2025-11-21T09:12:03.799839Z

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.

Jack Arrington 2025-11-21T04:28:43.117009Z

The whole file, for reference. This is compiling and working correctly in the project, but Calva is still showing the errors.

pez 2025-11-21T07:57:21.962189Z

Itโ€™s clojure-lsp providing these for Calva. You could run:

clojure-lsp diagnostics
In the project root, and see what it says.