Please, can someone point me out the example of code that statically analyses symbol resolution?
(ns user
(:require [foo.bar :refer [baz] :as foobar]))
(println foobar/baz)
(println baz)
I would like to study from someone's code that can resolve baz and foobar/baz to foo.bar/baz, and also can handle things like let-bindings, etcThatβs #clj-kondo
statically analyzing ns is actually quite difficult because it is so so flexible. Highly recommend using kondo as a library for static analysis to leverage the community effort. Though you can look at early clojure-lsp (parser.clj) commits before we switched to kondo.
So, you folks confirmed I have to dive in the clj-kondo source, which seems a bit scary to me for now π
Thank you for your suggestions
If you want an example take a look at the old lsp code.
Yeah, I want to adapt some code for the CLJS, not necessary the most elaborate implementation
here's the pr, so just before this. https://github.com/clojure-lsp/clojure-lsp/pull/261/commits/a1ee3756c88b70609befc5bce5ca0b11a92770f1
I know clj-kondo seems scary, but it's honestly quite readable. If you start from https://github.com/clj-kondo/clj-kondo/blob/707454f78069c59811405c010c2349c0b33fda47/src/clj_kondo/main.clj#L184, trace the calls: > clj-kondo.main/-main -> clj-kondo.main/main -> clj-kondo.core/run! -> clj-kondo.core.impl/process-files -> clj-kondo.core.impl/process-file -> clj-kondo.core.impl/schedule (assuming not parallel for simplicity) -> clj-kondo.impl.analyzer/analyze-input -> clj-kondo.impl.analyzer/analyze-expressions and then at that point, clj-kondo loops over every top-level expression in the parsed input (from the file or string) and uses recursion to handle all sub-expressions (with clj-kondo.impl.analyzer/analyze-expression**). @borkdude is also very helpful if you have questions about how it all works
@snoe that's a cool PR! I didn't know that clojure-lsp did its own analysis before using clj-kondo.
@s_zharinov You don't have to read the source code of clj-kondo to be able to use its analysis: https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md
Just found it, looks like it provides everything I need (and even much more). Ideally, I'm aiming to have self-contained node.js library in the project I'm playing with.
It's plugin for Clojure support in Prettier formatting tooling, to be specific.
I think I'll just delay this particular decision and focus on another concerns for now. I appreciate you made me sure symbol resolution problem can be solved one way or another π