FYI: when I click on *<https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.0.594-alpha/doc/design/merging-rewrite-clj-and-rewrite-cljs|Merging rewrite-clj and rewrite-cljs>*
on the docs, it points to nothing
I fixed the missing title bug over at cljdoc, so should be less confusing now.
Nice!
Thanks, from the change log? Seems to work for me, but Iโll check for any broken links tomorrow.
Directly from the cljdoc site: https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.0.594-alpha/doc/design/merging-rewrite-clj-and-rewrite-cljs
Thatโs weird, for me it links to my design doc.
might be confusing as cljdoc does not currently show doc titles for adoc files?
when you say โpoints to nothingโ do you mean 404 or something else?
Oh sorry, I thought it was an anchor error, but it's correct ๐
Sorry for the false alarm
Hey, I appreciate you sharing your confusion, Iโm sure you wonโt be the only one. Maybe Iโll go fix that missing doc title bug over at cljdoc,
yeah, it makes sense!
It could look a dumb question, but, how can I create a zipper from a empty map?
I can create with: (z/of-string "{:foo 1}")
that return a :map
tag correctly, but no with (z/of-string "{}")
@ericdallo if you need to update the :lint-as
map in config.edn
you can also use r/assoc-in
from https://github.com/borkdude/rewrite-edn :)
Oh my, I just know the assoc one, thank you @borkdude Is should tried that one ๐คฆ
It has also update, update-in
I can't find those on docs though https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.0.594-alpha/api/rewrite-clj.zip
https://github.com/borkdude/rewrite-edn rewrite-edn, not rewrite-clj
oh, got it
@borkdude Is that suppose to work?
(-> (z/of-string "{:foo {bar asd}}")
(r/assoc-in [:foo 'bar] 'asd))
or r
only accept its own nodes, not rewrite-clj ones?
oh, yeah, it needs to use its own parse-string
not really, you need to pass it rewrite-clj nodes, not zippers
so (r/assoc-in (z/node ...) [:foo 'baz] 'asd)
oh, you are right, my bad
so complete example:
(z/replace zloc (r/assoc-in (z/node ...) [:foo 'baz] 'asd))
feel free to add this to the docs
it worked like a charm ๐
your one line lib call replaced my 60+ lines ๐
:)
I just realized that it don't add a newline on the end of the node
I can manually add the \n
like I was doing
should it?
feel free to create an issue + fix if necessary
Yeah, I don't know, it's just a FYI if you think it should haha
๐
I should have known that lib before implement it all manually ๐คฆ
I was like ๐คฆ when I started this lib, because I discovered there wasn't one yet ;P
haha yeah I imagined that
Is this supposed to work?
(-> (z/of-string "{:a 1}")
z/node
(r/assoc-in [:lint-as 'foo] 'bar))
it gives a No implementation of method: :tag of protocol: #'rewrite-clj.node.protocols/Node found for class: nil
but this works:
(-> (z/of-string "{}")
z/node
(r/assoc-in [:lint-as 'foo] 'bar))
I could repro with a test on rewrite-edn ๐ I can try to fix it
that should work
this test gives the same exception:
(is (= "{:a {:b 2} :d 3}"
(str (r/assoc-in (r/parse-string "{:d 3}")
[:a :b] 2))))
weird!
the issue seems to be this nil arg: https://github.com/borkdude/rewrite-edn/blob/master/src/borkdude/rewrite_edn/impl.cljc#L101
the same happens with update-in
, so it seems to be a bug indeed as assoc-in use update-in
confirmed. user=> (r/assoc-in (r/parse-string "{:a 1}") [:b :c] 1) Execution error (IllegalArgumentException) at rewrite-clj.node.protocols/eval230$fn$G (protocols.cljc:9). No implementation of method: :tag of protocol: #'rewrite-clj.node.protocols/Node found for class: nil
shall I take a look, or are you looking into it already?
I'm looking, but I'm kind of lost ๐
feel free to look if you can
ok, I will now
found it
Fixed in 0.0.2
uow, really fast! I'll give a try right now
I think this lib also needs to support namespaced maps, I'll look into that now
this namespaced prefix stuff in clojure has made tooling more complex, not sure if it was worth it
Yeah ๐ it'd be util and cool. but it doesn't seems a priority IMO
https://github.com/borkdude/rewrite-edn/commit/453bafe5d3233fe173eed637162f1c3c1ce5b06a#r48516020
I had a small stab at namespaced maps, but it's more work than I expected, so I will go back to fixing some clj-kondo issues. PR for the above thing is welcome
thank you!!
same result with z/edn
, not sure I'm missing something
For example:
(z/tag (z/edn {})) => :unknown
Oh, (z/tag (z/of-string "{}"))
it's returning :map now, for some reason I thought seeing returning unknown as well :thinking_face:
Another way to create an empty map node:
user=> (require '[rewrite-clj.node :as n])
nil
user=> (-> (n/map-node []) n/string)
"{}"
But I can't convert that to zip, right?
My case is that I need to create a empty {}
and assoc things with rewrite-clj later
you can insert/replace/whatever that node into a zipper, ya.
when you see :unkown
for tag
you are looking at something that is not a rewrite-clj node:
user=> (n/tag 32)
:unknown
I see, cool
thank you again ๐
A rewrite-clj zipper is just a tree of rewrite-clj nodes that also tracks location.
You are most welcome, gonna call it a day! Have a good night!
Maybe thisโll help: https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.0.594-alpha/doc/user-guide#_creating_nodes
Yes!
And please feel free to ask any questions, itโll help me to improve the docs.
gโnight!
Thank you! For now rewrite-clj is just working great! I'm heavily relying to update clj-kondo config from clojure-lsp side
Awesome, very exciting!