Fork me on GitHub
#rewrite-clj
<
2021-03-21
>
ericdallo00:03:35

FYI: when I click on ** on the docs, it points to nothing

lread01:03:28

Thanks, from the change log? Seems to work for me, but I’ll check for any broken links tomorrow.

lread01:03:46

That’s weird, for me it links to my design doc.

lread01:03:43

might be confusing as cljdoc does not currently show doc titles for adoc files?

lread01:03:36

when you say “points to nothing” do you mean 404 or something else?

ericdallo01:03:42

Oh sorry, I thought it was an anchor error, but it's correct 😅

ericdallo01:03:54

Sorry for the false alarm

lread01:03:54

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,

ericdallo01:03:21

yeah, it makes sense!

lread19:03:20

I fixed the missing title bug over at cljdoc, so should be less confusing now.

ericdallo01:03:48

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 "{}")

ericdallo01:03:01

same result with z/edn , not sure I'm missing something

ericdallo01:03:08

For example:

(z/tag (z/edn {})) => :unknown

ericdallo01:03:57

Oh, (z/tag (z/of-string "{}")) it's returning :map now, for some reason I thought seeing returning unknown as well :thinking_face:

lread01:03:49

Another way to create an empty map node:

user=> (require '[rewrite-clj.node :as n])
nil
user=> (-> (n/map-node []) n/string)
"{}"

ericdallo02:03:00

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

lread02:03:05

you can insert/replace/whatever that node into a zipper, ya.

lread02:03:13

when you see :unkown for tag you are looking at something that is not a rewrite-clj node:

user=> (n/tag 32)
:unknown

ericdallo02:03:56

thank you again 🙂

lread02:03:03

A rewrite-clj zipper is just a tree of rewrite-clj nodes that also tracks location.

👍 3
lread02:03:30

You are most welcome, gonna call it a day! Have a good night!

👋 3
lread02:03:44

And please feel free to ask any questions, it’ll help me to improve the docs.

lread02:03:02

g’night!

ericdallo02:03:29

Thank you! For now rewrite-clj is just working great! I'm heavily relying to update clj-kondo config from clojure-lsp side

lread02:03:02

Awesome, very exciting!

🚀 3
catjam 3
borkdude08:03:44

@UKFSJSM38 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 :)

ericdallo12:03:07

Oh my, I just know the assoc one, thank you @U04V15CAJ Is should tried that one facepalm

borkdude12:03:32

It has also update, update-in

ericdallo13:03:27

@U04V15CAJ Is that suppose to work?

(-> (z/of-string "{:foo {bar asd}}")
    (r/assoc-in [:foo 'bar] 'asd))

ericdallo13:03:53

or r only accept its own nodes, not rewrite-clj ones?

ericdallo13:03:36

oh, yeah, it needs to use its own parse-string

borkdude13:03:07

not really, you need to pass it rewrite-clj nodes, not zippers

borkdude13:03:32

so (r/assoc-in (z/node ...) [:foo 'baz] 'asd)

ericdallo13:03:34

oh, you are right, my bad

borkdude13:03:07

so complete example:

(z/replace zloc (r/assoc-in (z/node ...) [:foo 'baz] 'asd))

borkdude13:03:17

feel free to add this to the docs

ericdallo13:03:40

it worked like a charm 🙂

ericdallo13:03:00

your one line lib call replaced my 60+ lines 😆

ericdallo13:03:13

I just realized that it don't add a newline on the end of the node

ericdallo13:03:41

I can manually add the \n like I was doing

borkdude13:03:00

feel free to create an issue + fix if necessary

ericdallo13:03:02

Yeah, I don't know, it's just a FYI if you think it should haha

ericdallo13:03:00

I should have known that lib before implement it all manually facepalm

borkdude13:03:39

I was like facepalm when I started this lib, because I discovered there wasn't one yet ;P

ericdallo13:03:08

haha yeah I imagined that

ericdallo14:03:26

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))

ericdallo14:03:26

I could repro with a test on rewrite-edn 🙂 I can try to fix it

borkdude14:03:45

that should work

ericdallo14:03:57

this test gives the same exception:

(is (= "{:a {:b 2} :d 3}"
         (str (r/assoc-in (r/parse-string "{:d 3}")
                          [:a :b] 2))))

ericdallo14:03:15

the same happens with update-in , so it seems to be a bug indeed as assoc-in use update-in

borkdude14:03:37

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

borkdude14:03:51

shall I take a look, or are you looking into it already?

ericdallo14:03:12

I'm looking, but I'm kind of lost 😆

ericdallo14:03:20

feel free to look if you can

borkdude14:03:56

ok, I will now

🙌 3
borkdude14:03:18

Fixed in 0.0.2

ericdallo14:03:38

uow, really fast! I'll give a try right now

borkdude14:03:05

I think this lib also needs to support namespaced maps, I'll look into that now

👍 3
borkdude14:03:11

this namespaced prefix stuff in clojure has made tooling more complex, not sure if it was worth it

ericdallo14:03:02

Yeah 😕 it'd be util and cool. but it doesn't seems a priority IMO

borkdude15:03:17

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

👍 3