This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-11
Channels
- # announcements (6)
- # babashka (35)
- # beginners (6)
- # biff (2)
- # calva (1)
- # cider (16)
- # clj-kondo (14)
- # clojure (176)
- # clojure-austin (13)
- # clojure-europe (7)
- # clojure-norway (6)
- # clojure-uk (12)
- # clojurescript (4)
- # cursive (11)
- # data-science (3)
- # datalog (10)
- # datomic (45)
- # events (1)
- # fulcro (2)
- # hyperfiddle (29)
- # leiningen (14)
- # lsp (2)
- # meander (2)
- # off-topic (24)
- # polylith (5)
- # re-frame (2)
- # shadow-cljs (21)
- # specter (14)
- # tools-deps (16)
- # xtdb (5)
Hey, while using the analysis api on the :var-definitions
there is an option to get the arglists as a string. What would be the best way to get the definition sexp as a string, or is this out of scope?
Just to check we are on the same page: Say I have the file foo.clj
(ns foo)
(defn foo
[]
(inc 1))
I run analysis on this and I get:
[{:arglist-strs ["[]"]
:col 1
:defined-by clojure.core/defn
:defined-by->lint-as clojure.core/defn
:end-col 11
:end-row 5
:filename "/Users/brandonstubbs/projects/x/src/foo.clj"
:fixed-arities #{0}
:name foo
:name-col 7
:name-end-col 10
:name-end-row 3
:name-row 3
:ns foo
:row 3}]
In order to get "(defn foo\n []\n (inc 1))"
parse it as edn for that?Ah sorry, the entire definition. My recommendation is to use rewrite-clj and iterate over the nodes, until the positions match up. And then just use str
on the node, this will give you the definition.
here is a similar function, but then the opposite: it removes definitions from the original code https://github.com/borkdude/carve/blob/cb621317ae1582869c8bd8f1a47cf57a3598d803/src/carve/impl.clj#L118
Ok great thank you I will do that, is this something you do not want in scope of this lib?
not in scope for clj-kondo. it throws away all whitespace so it doesn't even know the original node anymore
I would prefer the whitespace removed, what I am looking for is a quick way to say has this definition changed since this file was analysed
Busy writing something that does a bit of tree shaking for building, similar to turbopack in the js world. But on second thought, I think whitespace should matter as if someone adds a newline that’s important
ok, then you can just focus on the lines and columns that clj-kondo reports and check the contents in the file
Yeah that will actually be great! Thanks for the discussion 😄