nrepl / piggieback

nREPL support for ClojureScript REPLs
480 stars 48 forks source link

Custom data readers do not appear to be supported. #128

Open ont-app opened 4 months ago

ont-app commented 4 months ago

I have defined a custom reader macro that is supported elsewhere in the cljs infrastructure, but does not work in the Cider REPL.

> #voc/lstr "gaol@en-uk"
Unexpected error (ExceptionInfo) compiling at (REPL:1).
failed compiling constant: gaol; ont_app.vocabulary.lstr.LangStr is not a valid ClojureScript constant.

It has been hypothesized that this code might fix the problem:

(defn read-cljs-string [form-str]
  (when-not (string/blank? form-str)
    (binding [*ns* (create-ns ana/*cljs-ns*)
              reader/resolve-symbol ana/resolve-symbol
              reader/*data-readers* (merge tags/*cljs-data-readers*
                                                   (ana/load-data-readers))  ;; <<<<< note this change
              reader/*alias-map*
              (apply merge
                     ((juxt :requires :require-macros)
                      (ana/get-namespace ana/*cljs-ns*)))]
      (reader/read {:read-cond :allow :features #{:cljs}}
                   (readers/source-logging-push-back-reader
                    (java.io.StringReader. form-str))))))

I cloned the project and attempted to try it, but ran into technical difficulties I couldn't resolve.

See this discussion on Slack for context:

https://clojurians.slack.com/archives/C0617A8PQ/p1717590636580699