Fork me on GitHub
#chlorine-clover
<
2020-04-20
>
seancorfield19:04:06

@mauricio.szabo It looks like the code that identifies the namespace for the current file gets confused if there's explicit metadata on the namespace but I'm having a hard time isolating a repro case...

seancorfield19:04:41

Some metadata seems OK, some doesn't. Can you point me to where that is parsed in the code so I can try to create a repro?

seancorfield19:04:57

(not sure whether this would be in repl-tooling or chlorine itself)

seancorfield19:04:29

(the specific case I'm trying to use is clj-kondo metadata which is quite complex)

seancorfield19:04:45

Ah, ok. so simple-read is where I should start looking...

mauricio.szabo19:04:06

Yes, it just uses cljs.reader/read-string to parse the ns form

seancorfield19:04:15

OK, so this metadata is probably not value EDN...

borkdude19:04:29

@seancorfield Are you trying to put metadata in the ns form?

borkdude19:04:10

(ns foo { ... } ;; <-- metadata
also works

borkdude19:04:28

instead of (ns ^{ ... } foo)

seancorfield19:04:32

@borkdude yes, I have tried both this:

(ns
  ^{:clj-kondo/config
    '{:lint-as
      {worldsingles.expectations.mobile.user/patch-notifications
       clj-kondo.lint-as/def-catch-all}}}
  worldsingles.expectations.mobile.user
and this
(ns worldsingles.expectations.mobile.user
  {:clj-kondo/config
    '{:lint-as
      {worldsingles.expectations.mobile.user/patch-notifications
       clj-kondo.lint-as/def-catch-all}}}
and Chlorine chokes on both.

borkdude19:04:56

ok, yeah, because EDN cannot contain quotes. I guess this is in Chlorine then.

seancorfield19:04:09

I think the quote is the problem here (not valid EDN) but without the quote it isn't legal Clojure 🙂

borkdude19:04:50

@mauricio.szabo if you're looking for a parser that extends EDN with normal code features (while not evaluating code): https://github.com/borkdude/edamame

mauricio.szabo19:04:38

Weeeellll... worth a try 👍

borkdude19:04:53

I'm using it in sci/babashka to parse code

mauricio.szabo19:04:02

Do you know if it performs better, or worse, than rewrite-cljs?

borkdude19:04:27

I think better, since it doesn't read into intermediate forms, straightly into the sexprs

borkdude19:04:31

but benchmarking is knowing

borkdude19:04:57

it's based on tools.reader, so it's not faster than tools.reader

mauricio.szabo19:04:12

Maybe it'll be a good fit for Chlorine to parse the ns forms, but I can see it being useful to detect blocks too (the current code is quite slow to be honest)

borkdude19:04:06

yeah. I want to add a public api to use a reader and read expression by expression using a reader, so far I've been plugging into the .impl namespaces from babashka and sci to do that: https://github.com/borkdude/babashka/blob/master/src/babashka/impl/repl.clj#L29

mauricio.szabo22:04:53

@borkdude Is it possible to dispatch all tag literals to a specific reader, for example as it is possible with:

(clojure.reader/read-string "#foo 10" {:readers {:default tagged-literal}})

borkdude06:04:08

Yes, you can pass exactly this option to edamame, it’s in the README

seancorfield19:04:23

OK, this works for both

(ns
  ^{:clj-kondo/config
    (quote {:lint-as
            {worldsingles.expectations.mobile.user/patch-notifications
             clj-kondo.lint-as/def-catch-all}})}
  worldsingles.expectations.mobile.user

mauricio.szabo19:04:47

Well, maybe we can change to tools.reader/read-string? I don't know if this could be a problem or not, to be honest..

seancorfield19:04:29

(I'm such an edge case, aren't I? 🙂 )

mauricio.szabo19:04:28

Yes, but these are the good cases, it battle-tests the plug-in 😄

mauricio.szabo23:04:38

@seancorfield just published a new version that fixes this issue with namespace detection 🙂

seancorfield23:04:53

Confirmed, yes, that works beautifully!

🎉 4
seancorfield23:04:01

Thank you for such a quick fix!