Fork me on GitHub
#cider
<
2024-06-05
>
Eric Scott12:06:36

I wrote about this about a year ago, but didn't get a response. I'm revisiting this again. I've written a custom reader tag called #voc/lstr which behaves like this in the JVM repl:

> (def x #voc/lstr "gaol@en-uk")
> x
#voc/lstr "gaol@en-uk"
>  (type x)
ont_app.vocabulary.lstr.LangStr
> (str x)
"gaol"
> (ont-app.vocabulary.lstr/lang x)
"en-uk"
This also works when I launch a cljs repl using clojure -M:test -m cljs.main, with this difference (note ont_app vs ont-app):
(type #voc/lstr "gaol@en-uk")
ont-app.vocabulary.lstr/LangStr
However, when I launch cider-jack-in-cljs with REPL type node, I get the following behavior:
;;  Startup: /usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.30.0"} cider/piggieback {:mvn/version "0.5.2"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -Mdev:cider/nrepl
;;
;; ClojureScript REPL type: node
;; ClojureScript REPL init form: (do (require 'cljs.repl.node) (cider.piggieback/cljs-repl (cljs.repl.node/repl-env)))
;;

> #voc/lstr "gaol@en"
Unexpected error (ExceptionInfo) compiling at (REPL:1).
failed compiling constant: gaol; ont_app.vocabulary.lstr.LangStr is not a valid ClojureScript constant.
The problem seems to arise from the fact that the cljs.compiler/emit-constant* method is dispatched under ont-app.vocabulary.lstr/LangStr, but the compiler is looking for ont_app.vocabulary.lstr/LangStr. I have the impression that the problem is originating somewhere in here: https://github.com/nrepl/piggieback/blob/master/src/cider/piggieback_impl.clj
(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* tags/*cljs-data-readers*
              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))))))
But I don't really play much on the CLJS side of things, and I'm unclear as to how one gets visibility into compilation in a clojurescript REPL. Am I correct in the impression that this is a bug in piggieback, and would I be off-base if I logged an issue with them?

vemv14:06:59

Are you able to share the #voc/lstr implementation?

vemv14:06:45

In https://github.com/nrepl/piggieback/blob/540a57e871b72cb494d0049cb8c6b7485458ad25/src/cider/piggieback_impl.clj#L213 we only use the value of tags/*cljs-data-readers* while in the official clojurescript compiler/repl, they use:

(merge tags/*cljs-data-readers*
       (ana/load-data-readers))
So probably we need to imitate that pattern

vemv14:06:23

I'd suggest that you clone piggieback, add that change, perform a lein install, and try if it works. I can help making the lein install easier (we normally have it as a Makefile task but it's not there)

Eric Scott15:06:00

I'm about to commit a bunch of changes after being away from the project for a long time, but the current version should also have this problem: https://github.com/ont-app/vocabulary

Eric Scott15:06:14

Thanks I'll try cloning and making that change.

Eric Scott15:06:00
replied to a thread:I wrote about this about a year ago, but didn't get a response. I'm revisiting this again. I've written a custom reader tag called #voc/lstr which behaves like this in the JVM repl: &gt; (def x #voc/lstr "gaol@en-uk") &gt; x #voc/lstr "gaol@en-uk" &gt; (type x) ont_app.vocabulary.lstr.LangStr &gt; (str x) "gaol" &gt; (ont-app.vocabulary.lstr/lang x) "en-uk" This also works when I launch a cljs repl using `clojure -M:test -m cljs.main`, with this difference (note `ont_app` vs `ont-app`): (type #voc/lstr "gaol@en-uk") ont-app.vocabulary.lstr/LangStr However, when I launch `cider-jack-in-cljs` with REPL type `node`, I get the following behavior: ;; Startup: /usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "1.0.0"} cider/cider-nrepl {:mvn/version "0.30.0"} cider/piggieback {:mvn/version "0.5.2"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -Mdev:cider/nrepl ;; ;; ClojureScript REPL type: node ;; ClojureScript REPL init form: (do (require 'cljs.repl.node) (cider.piggieback/cljs-repl (cljs.repl.node/repl-env))) ;; &gt; #voc/lstr "gaol@en" Unexpected error (ExceptionInfo) compiling at (REPL:1). failed compiling constant: gaol; ont_app.vocabulary.lstr.LangStr is not a valid ClojureScript constant. The problem seems to arise from the fact that the cljs.compiler/emit-constant* method is dispatched under `ont-app.vocabulary.lstr/LangStr`, but the compiler is looking for `ont_app.vocabulary.lstr/LangStr`. I have the impression that the problem is originating somewhere in here: https://github.com/nrepl/piggieback/blob/master/src/cider/piggieback_impl.clj (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* tags/*cljs-data-readers* 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)))))) But I don't really play much on the CLJS side of things, and I'm unclear as to how one gets visibility into compilation in a clojurescript REPL. Am I correct in the impression that this is a bug in piggieback, and would I be off-base if I logged an issue with them?

I'm about to commit a bunch of changes after being away from the project for a long time, but the current version should also have this problem: https://github.com/ont-app/vocabulary