Fork me on GitHub
#core-typed
<
2022-09-20
>
kishima14:09:22

Hello! Is there something like a percentage count of annotation of a given lib

ambrosebs18:09:14

Hi, this used to be a feature in lein-typed but I'm not sure if it works any more. Is that the kind of output you'd want? https://github.com/typedclojure/lein-typed#type-coverage

kishima18:09:47

Ooh, that’s exactly it

kishima18:09:01

Thought that would be cool to put in open source projects, like that test coverage badge thingy, but for typing

kishima18:09:38

I think I’ll try making it for deps, is it a good idea?

ambrosebs19:09:52

Sounds like fun, let me know what you come up with.

ambrosebs19:09:52

Let me know if that function still works.

kishima21:09:01

Hmm, I couldn’t run it

kishima21:09:05

user> (c/var-coverage)
Syntax error compiling at (typed/cljc/analyzer/passes/uniquify.clj:82:15).
Unable to resolve symbol: update-vals in this context
user> 

kishima21:09:19

I can’t find this uniquify.clj file also

ambrosebs21:09:57

you might need to bump your Clojure version.

ambrosebs21:09:46

I think update-vals was added in Clojure 1.11

kishima21:09:22

Oooh that’s right

kishima03:09:31

Ah it works!

Registering annotations from typed.ann.clojure...
Registering annotations from typed.ann.clojure...
Found 0 annotated vars out of 1 vars
0% var annotation coverage

🎉 1
kishima15:09:15

Trying to do it like this:

clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version "1.11.1"} org.typedclojure/typed.clj.runtime {:mvn/version "1.0.32"} org.typedclojure/typed.clj.checker {:mvn/version "1.0.32"}}}' -X clojure.core.typed/var-coverage                  
But var-coverage expects the current namespace or a bunch of namespaces to run. Maybe making a cli version of it would suffice. Something like:
(core/defn var-coverage 
  "Summarises annotated var coverage statistics to *out*
  for namespaces nsyms, a collection of symbols or a symbol/namespace.
  Defaults to the current namespace if no argument provided."
  ([] (var-coverage (all-ns)))
  ([nsyms-or-nsym]
   (load-if-needed)
   ((requiring-resolve 'typed.clj.checker.statistics/var-coverage) nsyms-or-nsym)))

ambrosebs02:09:25

Perhaps it would be more common to want the coverage for all namespaces in a particular directory?

ambrosebs02:09:44

I'd think using all-ns would generate a bunch of noise.

kishima02:09:31

Yeah, just noticed that this spits everything that is loaded hehe