calva

2026-05-16T11:00:39.404339Z

It would be nice to have in Calva a configurable setting which would "autofold" certain defn metadata. I am lately working with 2 types of metadata , which are somehow "documentation", and "I" would often want to fold them. They are for now the "2 keys" in def metadata: :malli/schema :metadoc/examples this would apply to. Special the "examples" could get "long"..... as it allows to give "several examples" for a function. (FYI: these tool renders them as clojuredoc: https://github.com/generateme/metadoc) Maybe there are other keys with similar purpose around, maybe even auto-folding the "docstring" as such.

pez 2026-05-16T11:10:54.863689Z

I have wanted this for :tests for very long.

2026-05-16T11:11:23.727319Z

A concrete example of the meta of a defn:

{:metadoc/examples [(example-session "Train random-forest on iris data"
     (let [training-data
           (->
            (scicloj.metamorph.ml.rdatasets/datasets-iris)
            (ds/drop-columns [:rownames])
            (ds-mod/set-inference-target [:species]))
           model
           (scicloj.metamorph.ml/train training-data {:model-type :metamorph.ml/random-forest})]
       (-> model :model-data :forest :trees count))
     (comment "forest with hundred trees created"))]

   :malli/schema [:=> [:cat
                       [:fn (fn [x]
                              (or (dataset? x)
                                  (= (-> x class .getName) "ml.dmlc.xgboost4j.java.DMatrix")))]
                       map?]
                  [map?]]}

pez 2026-05-16T11:12:24.866819Z

I think that last time I looked in to it there were no API for autofolding specific things. I can have looked in the wrong place, and it can also have changed since I looked, because several years ago.

πŸ€” 1
2026-05-16T11:12:55.122709Z

would be render by "Only" showing the "keys" of the metadata map + "...":

pez 2026-05-16T11:13:29.702659Z

Issue welcome, and also some investigation into what we can do.

πŸ‘ 1
2026-05-16T11:27:41.884009Z

https://github.com/BetterThanTomorrow/calva/issues/3223 some "VScode extensions" seem to do "auto fold", so something should be possible now. (ev. in collaboration with LSP I saw as well)

πŸ™ 1
pez 2026-05-16T11:33:23.516109Z

I think clojure-lsp provides folding information, and that you can choose what folding provider to use in VS Code settings. If selective autofolding is possible, it can probably use these providers. Even if here I think that either Calva or clojure-lsp would need to provide the configurability.

2026-05-16T11:39:32.700359Z

I never tried "inline" unit testing(so attach unit tests to a function metadata), but clearly one "obstacle" for this is "information overload" in the "production code". (but not only... additional test dependencies is an other one) which a "perfect IDE" could clearly reduce. Attaching "examples" to defn like metadoc proposes requires ev. example-specific dependencies/require statements

pez 2026-05-16T11:44:46.501099Z

Inline tests is what I meant with my comment above.

2026-05-16T11:46:03.392009Z

Can you point me to a Clojure test framework allowing that , for curiosity ? I googled , but did not find any.

pez 2026-05-16T11:53:51.355679Z

All do, I think. It’s how clojure.test runs tests. Or rather what deftest does.

seancorfield 2026-05-16T14:00:04.997959Z

@carsten.behring See https://clojuredocs.org/clojure.test/with-test for example. I talk about some of the potential problems with that approach here https://cljdoc.org/d/com.github.seancorfield/expectations/2.2.214/doc/getting-started#tests-with-source-code

pez 2026-05-16T15:34:35.821299Z