Fork me on GitHub
#nrepl
<
2020-03-22
>
djblue20:03:43

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.

djblue20:03:14

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.

bozhidar20:03:19

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

bozhidar20:03:43

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

bozhidar20:03:00

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

bozhidar20:03:57

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.

bozhidar20:03:52

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.

djblue21:03:17

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

bozhidar20:03:25

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 .

bozhidar20:03:07

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

djblue20:03:46

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

djblue20:03:41

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.

bozhidar21:03:39

Glad to hear this!

bozhidar21:03:36

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

borkdude21:03:48

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

djblue21:03:03

The code is pretty rough 😆

borkdude21:03:15

no worries 😉

djblue21:03:33

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 👍

djblue21:03:16

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

borkdude21:03:16

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

djblue21:03:40

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

djblue21:03:05

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

djblue21:03:21

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

borkdude21:03:02

What nREPL clients don't use the JVM?

djblue21:03:38

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

djblue21:03:24

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

borkdude21:03:58

I just started working on this today

djblue21:03:04

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

bozhidar08:03:12

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.

borkdude22:03:10

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

borkdude22:03:50

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

borkdude22:03:17

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