I have a quick question about the nrepl protocol. Is there a concept of a langauge when connected to a nrepl server? Whenever I see nrepl implemented for Clojurescript, it's always like a side channel thing that takes over the session that the client has to side effect. The client can't easily ask what language it's connected to over nrepl.
I ask this because in implementing a native clojurescript nrepl server, I can't seem to find any clients (vim-fireplace, calva, etc.) that work out of the box, they all assume clojure and have specific hacks for piggieback, figwheel and shadow-cljs.
> I have a quick question about the nrepl protocol. Is there a concept of a langauge when connected to a nrepl server?
Currently there’s nothing like this, but it can easily be added to the session metadata (for instance).
> Whenever I see nrepl implemented for Clojurescript, it’s always like a side channel thing that takes over the session that the client has to side effect. The client can’t easily ask what language it’s connected to over nrepl.
To my knowledge there are no ClojureScript implementation of nREPL, so I’m a bit puzzled as to what you’re referring to. Piggieback simply changes a regular evaluation session to use the ClojureScript compiler, but it’s still written in Clojure. Therefore the need for clients to look for certain bindings in the session and determine whether it’s Clojure or ClojureScript session.
If we had native ClojureScript servers the clients would know they connected to one and there wouldn’t really be a need to query about the language, although I understand this might be useful in certain cases.
Obviously with a native ClojureScript server you won’t be able to host both Clojure and ClojureScript REPLs in the same server, but I doubt that’s an issue for most people .
> I ask this because in implementing a native clojurescript nrepl server, I can’t seem to find any clients (vim-fireplace, calva, etc.) that work out of the box, they all assume clojure and have specific hacks for piggieback, figwheel and shadow-cljs. Because so far there hasn’t been an alternative. 🙂 Are you working on a native ClojureScript implementation?
Thanks for the quick and in-depth response @bozhidar!
I started working on an nrepl server prototype that ran on lumo/nodejs last year and ran into these issues. I got busy with some other stuff but was inspired by https://www.youtube.com/watch?v=dZ4xczP5zDI to start looking into it again.
It's a very rough prototype https://github.com/djblue/nrepl-cljs
How do they distinguish clojure from clojurescript from the nrepl protocol?
Glad to hear this!
I’m hear to help if you need me. Btw, on a similar note - @borkdude just started to work on nREPL for babashka!
cool, I'll take a look at nrepl-cljs as reference
There are also OCaml, Python and Ruby clients for nREPL, btw. Probably some others as well, I never tried to keep track of all of them.
The code is pretty rough 😆
The best part is probably https://github.com/djblue/nrepl-cljs/blob/master/src/nrepl/bencode.cljs
no worries 😉
Although setting up a proxy https://github.com/djblue/nrepl-cljs/blob/master/src/nrepl/proxy.cljs and logging message with an existing implementation is really helpful :thumbsup:
It would be really cool if you made the nrepl_server.clj a cljc file and made the transport platform specific!
The primary goal is to make it work for babashka. What's the goal of nrepl-cljs?
I wanted to get it working with lumo or any other nodejs based runtime
Also found https://github.com/borkdude/nrepl-server#reverse-engineering-the-nrepl-protocol, so it seems we have done very similar things 😆
Basically I want people to be able to dev clojurescript without the jvm
What nREPL clients don't use the JVM?
Vim-fireplace, calva, and other editors which act as clients don't require a jvm right?
They usually just connect to the server via something like python or typescript based on the editor
right
I just started working on this today
I don't think you will run into as many problems as I did because babashka is more clojure than clojurescript.
@bozhidar I'm trying to use nrepl/bencode with babashka which is compiled with GraalVM. GraalVM doesn't like this part:
https://github.com/nrepl/bencode/blob/04287269237788811ee4726d5a51db72d5d600d1/src/bencode/core.clj#L317
Since 1.9 Clojure has a bytes?
predicate:
(defn bytes?
"Return true if x is a byte array"
{:added "1.9"}
[x] (if (nil? x)
false
(-> x class .getComponentType (= Byte/TYPE))))
Maybe we could use that in bencode?If bencode should still support clojure 1.8 we could just inline that expression
for now I'm just going to copy the bencode code and modify it for babashka