nrepl

https://github.com/nrepl/nrepl || https://nrepl.org
djblue 2020-03-22T20:22:43.030900Z

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.

djblue 2020-03-22T20:25:14.032700Z

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.

bozhidar 2020-03-22T20:50:19.032900Z

> I have a quick question about the nrepl protocol. Is there a concept of a langauge when connected to a nrepl server?

bozhidar 2020-03-22T20:50:43.033500Z

Currently there’s nothing like this, but it can easily be added to the session metadata (for instance).

bozhidar 2020-03-22T20:51:00.033700Z

> 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.

bozhidar 2020-03-22T20:52:57.035600Z

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.

bozhidar 2020-03-22T20:53:52.036500Z

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.

bozhidar 2020-03-22T20:54:25.037200Z

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 .

bozhidar 2020-03-22T20:55:07.037900Z

> 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?

djblue 2020-03-22T20:56:46.039Z

Thanks for the quick and in-depth response @bozhidar!

djblue 2020-03-22T20:58:41.040500Z

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.

djblue 2020-03-22T20:59:10.041Z

It's a very rough prototype https://github.com/djblue/nrepl-cljs

djblue 2020-03-22T21:00:17.041200Z

How do they distinguish clojure from clojurescript from the nrepl protocol?

bozhidar 2020-03-22T21:27:39.042800Z

Glad to hear this!

bozhidar 2020-03-22T21:29:36.043900Z

I’m hear to help if you need me. Btw, on a similar note - @borkdude just started to work on nREPL for babashka!

borkdude 2020-03-22T21:30:48.044300Z

cool, I'll take a look at nrepl-cljs as reference

bozhidar 2020-03-23T08:32:12.056100Z

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.

djblue 2020-03-22T21:41:03.044700Z

The code is pretty rough 😆

djblue 2020-03-22T21:41:24.044900Z

The best part is probably https://github.com/djblue/nrepl-cljs/blob/master/src/nrepl/bencode.cljs

borkdude 2020-03-22T21:42:15.045200Z

no worries 😉

djblue 2020-03-22T21:43:33.045400Z

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:

djblue 2020-03-22T21:46:16.045700Z

It would be really cool if you made the nrepl_server.clj a cljc file and made the transport platform specific!

borkdude 2020-03-22T21:48:16.045900Z

The primary goal is to make it work for babashka. What's the goal of nrepl-cljs?

💯 1
djblue 2020-03-22T21:48:40.046100Z

I wanted to get it working with lumo or any other nodejs based runtime

djblue 2020-03-22T21:49:05.046300Z

Also found https://github.com/borkdude/nrepl-server#reverse-engineering-the-nrepl-protocol, so it seems we have done very similar things 😆

djblue 2020-03-22T21:50:21.046700Z

Basically I want people to be able to dev clojurescript without the jvm

borkdude 2020-03-22T21:51:02.046900Z

What nREPL clients don't use the JVM?

djblue 2020-03-22T21:52:38.047100Z

Vim-fireplace, calva, and other editors which act as clients don't require a jvm right?

djblue 2020-03-22T21:53:24.047300Z

They usually just connect to the server via something like python or typescript based on the editor

borkdude 2020-03-22T21:53:40.047500Z

right

borkdude 2020-03-22T21:53:58.047700Z

I just started working on this today

💯 1
djblue 2020-03-22T21:57:04.048100Z

I don't think you will run into as many problems as I did because babashka is more clojure than clojurescript.

borkdude 2020-03-22T22:21:10.049500Z

@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?

borkdude 2020-03-22T22:21:50.050Z

If bencode should still support clojure 1.8 we could just inline that expression

borkdude 2020-03-22T22:23:17.050300Z

for now I'm just going to copy the bencode code and modify it for babashka