Fork me on GitHub
#clj-kondo
<
2019-09-30
>
sogaiu10:09:08

i'm looking at the analysis export in the var-usages section -- one of the map entries i see is roughly like:

{:filename "src/augistints/src/augistints/gen.cljc",
 :row 11,
 :col 17,
 :from augistints.gen,
 :to rewrite-clj.zip,
 :name string,
 :arity 1,
 :lang :clj}
i looked in the source file and what i see on row / line 11 is:
(let [fn-name (rz/string (:fn-name studied))]
there is the following bit in the ns declaration at the top of the file:
[rewrite-clj.zip :as rz]))
so it looks like the analysis data doesn't retain the alias info within the map entry in this case (though perhaps the info about rz == rewrite-clj.zip is retained elsewhere in the analysis info). is there a way to get it to do that? is it correct that there's no way currently to distinguish between occurrences of: 1) rewrite-clj.zip/string 2) rz/string without visitng the file to check?

borkdude10:09:43

the alias is included in other parts of the analysis information so you might be able to get it like that.

sogaiu10:09:01

was just hoping i could get clj-kondo to do it 🙂

borkdude10:09:22

why do you need this?

sogaiu10:09:19

in emacs, the default M-. behavior detects namespaces so i wanted to create indices where the identifiers can also have ns / alias info with them.

sogaiu10:09:39

then i don't need to give instructions to override emacs behavior to throw away ns info.

sogaiu10:09:52

it also means less extra defs to comb through in results.

borkdude10:09:01

ah so you want to go from rz/string to the file with namespace rewrite-clj?

sogaiu10:09:31

yes, to rewrite-clj.zip or other relevant

borkdude10:09:18

can't you look in the used-namespaces to look up the alias?

sogaiu10:09:34

i may try doing that -- there are a few things about that, possibly minor: 1) indexing will likely be slower (not sure how much, so may be once i do it, i'll have a better idea) 2) i can't distinguish from the analysis data whether the occurence is rewrite-clj.zip/string or rz/string without visiting the file -- may be that's not important though

sogaiu10:09:40

to address the second point, i guess i can throw in extra index entries for every non-ns-prefixed entry -- so the index may grow in size

sogaiu10:09:26

in any case, i can try out an implementation first and see i suppose

borkdude10:09:23

from this:

:namespace-usages [{:filename "<stdin>",
                                :row 1,
                                :col 20,
                                :from foo,
                                :to clojure.set,
                                :alias set}]
you can make a map from filename to namespace name + alias

borkdude10:09:30

or any other shape you need

sogaiu10:09:47

ah, so i can distinguish then

sogaiu10:09:01

ok, thanks for straightening me out 🙂

borkdude10:09:49

but I guess adding the alias to the var usage would also be fine, maybe call it :to-alias or something

sogaiu11:09:21

that would be nice 🙂 but i'm ok to try what you suggest in any case

borkdude11:09:22

but for now I guess using :namespace-usages will be fine maybe

sogaiu11:09:07

ah, also, i noticed that things that use (alias ...) and not require :as, don't seem to get picked up in the same way.

borkdude11:09:30

yeah, I noticed that too. same for (require ...)

borkdude11:09:43

fix welcome

sogaiu11:09:11

he he -- hopefully i'll learn enough about clj-kondo that that will be manageable before long 🙂

borkdude11:09:33

it's just data processing -- and there are already many other places where this data is emitted, so you can just imitate that if you're interested in doing a fix.

sogaiu11:09:56

ah, if it's not too much trouble, would you mind pointing me at specific functions / lines of an example or two?

borkdude11:09:22

Sure. These are the functions through which all the data flows that ends up in the analysis export: https://github.com/borkdude/clj-kondo/blob/master/src/clj_kondo/impl/analysis.clj So you can grep for wherever these functions are called.

borkdude11:09:13

One thing that bugs me is that I spelled :var-args-min-arity not like :varargs-min-arity.

sogaiu11:09:22

i don't rely on that, so have no problem with that changing 🙂

sogaiu11:09:33

even if i did, i'm happy to adjust

borkdude11:09:18

right, I don't think a lot of people depend on this yet

sogaiu11:09:23

better change it soon as you mentioned the analysis export it in your talk 🙂