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.
I have wanted this for :tests for very long.
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?]]}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.
would be render by "Only" showing the "keys" of the metadata map + "...":
Issue welcome, and also some investigation into what we can do.
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)
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.
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
Inline tests is what I meant with my comment above.
Can you point me to a Clojure test framework allowing that , for curiosity ? I googled , but did not find any.
All do, I think. Itβs how clojure.test runs tests. Or rather what deftest does.
@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