@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...
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?
(not sure whether this would be in repl-tooling or chlorine itself)
Okay, it's on this line: https://github.com/mauricioszabo/repl-tooling/blob/master/src/repl_tooling/editor_helpers.cljs#L176
(the specific case I'm trying to use is clj-kondo
metadata which is quite complex)
Ah, ok. so simple-read
is where I should start looking...
Yes, it just uses cljs.reader/read-string
to parse the ns form
OK, so this metadata is probably not value EDN...
@seancorfield Are you trying to put metadata in the ns form?
(ns foo { ... } ;; <-- metadata
also worksinstead of (ns ^{ ... } foo)
@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.ok, yeah, because EDN cannot contain quotes. I guess this is in Chlorine then.
I think the quote is the problem here (not valid EDN) but without the quote it isn't legal Clojure 🙂
@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
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
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..
(I'm such an edge case, aren't I? 🙂 )
Weeeellll... worth a try 👍
I'm using it in sci/babashka to parse code
Do you know if it performs better, or worse, than rewrite-cljs?
I think better, since it doesn't read into intermediate forms, straightly into the sexprs
Yes, but these are the good cases, it battle-tests the plug-in 😄
but benchmarking is knowing
it's based on tools.reader, so it's not faster than tools.reader
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)
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
so it's basically this:
https://github.com/borkdude/edamame/blob/master/src/edamame/impl/parser.cljc#L486-L490
+ parse-next
@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}})
@seancorfield just published a new version that fixes this issue with namespace detection 🙂
Confirmed, yes, that works beautifully!
Thank you for such a quick fix!