Fork me on GitHub
#babashka
<
2020-04-11
>
borkdude10:04:34

@wilkerlucio @jkrasnay Perhaps better luck with v0.0.82 and Cursive / vim nREPL. We changed to a BufferedOutputStream now when writing messages which maybe helps.

dominicm14:04:42

I think this is going to just make the error happen at another time,

dominicm14:04:20

Nvm, I see this got resolved and was unrelated

martinklepsch11:04:51

the nrepl stuff is seriously cool! Fireplace doesn’t auto detect the connection for me and I’m not seeing an .nrepl-port file, is that expected?

borkdude11:04:57

@martinklepsch that is expected, you have to just connect to the right port yourself

martinklepsch11:04:04

@borkdude got it. out of curiosity, did you actively decide against an .nrepl-port file? & if: why?

borkdude11:04:09

@martinklepsch There have been discussions about this in #dev-tooling-task-force (closed channel, I can invite you if you want) and #conjure recently. Also here: https://github.com/borkdude/babashka/issues/157 The gist of it is that multiple tools can write .nrepl-port files. Also it assumes just a single server at a time, which is not how everyone uses it. Maybe a nice compromise is: only write an .nrepl-port file if it doesn't exist? I don't know the right answer and honestly, I can live with manually entering the port number (cc @pez @sogaiu @bozhidar)

borkdude11:04:18

you can write an .nrepl-port file yourself using a small bb script which also launches the nrepl server, but that's up to the user

martinklepsch11:04:38

yep just saw, very cool. babashka is getting really impressive :star-struck:

martinklepsch11:04:35

alright, thanks for the explanation, i guess I’m fine with entering the port manually too 😄

martinklepsch11:04:41

It is something that I expected from an nREPL server though. Maybe a note on startup would help clear that kind of confusion. But then again probably not such a big deal 🙂

borkdude11:04:04

I think printing a link to some documentation about the bb nREPL at startup might be most flexible. Then we can also document that script there.

jkrasnay12:04:41

@martinklepsch aside from .nrepl-port do you have vim-fireplace working with the bb nREPL server?

martinklepsch12:04:25

@jkrasnay I actually don’t! I’m getting an error Error detected while processing function <SNR>63_printop[1]..<SNR>63_opfunc[35]..<SNR>63_buffer_path[3]..fireplace#path[4]..5:

borkdude12:04:14

some existing nREPL clients assume too much about the nREPL server they're connecting to, so that may be the issue here

borkdude12:04:20

environments that are known to work: - Emacs / CIDER - lein repl :connect - Calva - Chlorine - vim-iced - conjure?

borkdude12:04:27

For debugging you may start the server with BABASHKA_DEV=true bb --nrepl-server, it will print the last messages that it received

jkrasnay12:04:30

I’m getting a very similar error. Sadly I don’t know enough vimscript to try debugging it.

martinklepsch12:04:36

I’m gonna give bleeding edge conjure a try 🙂

borkdude12:04:29

ah that may also work yeah

borkdude12:04:32

also vim-iced works

borkdude12:04:59

If I knew how to exit vim, I would also give it a try, but I don't. Don't know which env@rahul080327 is using, I think vim-iced.

sogaiu12:04:34

exiting vim is a matter of colon followed by q and then enter, i think

sogaiu12:04:08

there's always the control-z followed by killing the process approach too...

borkdude12:04:16

joke as a way of expressing that I don't know enough about vim to give it a try without spending a lot of time on it

🙂 1
🎭 1
borkdude12:04:54

bb 0.0.82: release updated with windows binary https://github.com/borkdude/babashka/releases/tag/v0.0.82

👍 2
jkrasnay13:04:51

So :CljEval (+ 1 1) works! The form gets sent and eval’d by bb and the result is displayed in the Vim command area. The problem seems to arise when eval’ing forms in the source file. I think perhaps fireplace is choking when trying to figure out the namespace.

borkdude13:04:47

meanwhile Martin posted in #conjure that conjure worked for him in vim

jkrasnay13:04:30

Yep, definitely looks like a fireplace-specific quirk. Thanks for you help, and double-thanks for bb/sci. Awesome stuff!

👍 1
jkrasnay18:04:42

Looking at this a little closer. It looks like when fireplace first connects it sends two forms together in one request

"Received" {:code "(System/getProperty \"path.separator\") (or (System/getProperty \"fake.class.path\") (System/getProperty \"java.class.path\") \"\") (System/getProperty \"user.dir\")", :id "733e35a2-f6fa-4567-85af-b0e088d3e0d1", :op :eval}

jkrasnay18:04:24

Fireplace then shows an error like this: Vim(let):E684: list index out of range: 1

jkrasnay18:04:08

I wonder if fireplace was expecting to get back a two-element collection or something. Does this make any sense?

borkdude18:04:05

if it expects back a vector, why doesn't it wrap that expression in a vector... ? @bozhidar what are the semantics in nREPL when asking for :eval with multiple top-level expressions?

jkrasnay18:04:46

That’s a good question…

borkdude18:04:32

@jkrasnay is it possible to test if that fixes the issue, can you run fireplace from source somehow?

jkrasnay18:04:13

I’ll see if I can do that

borkdude18:04:28

fwiw, if I test against an nREPL server when started with lein repl and fire "(+ 1 2 3) (+ 1 2 3)" at it, I just get "6" back

jkrasnay18:04:04

If I send that with fireplace to a lein repl I get two sixes, printed on separate lines

borkdude19:04:10

@jkrasnay Gotcha!

(ns nrepl-client
  (:require [bencode.core :as b]))

(defn read-until-done [in]
  (loop []
    (let [msg (b/read-bencode in)
          value (get msg "value")
          status (get msg "status")
          status (when status (set (map #(String. %) status)))]
      (when value (prn (String. value)))
      (when-not (contains? status "done")
        (recur)))))

(defn nrepl-eval [port expr]
  (let [s (.Socket. "localhost" port)
        out (.getOutputStream s)
        in (.PushbackInputStream. (.getInputStream s))
        _ (b/write-bencode out {"op" "eval" "code" expr})]
    (read-until-done in)))

(nrepl-eval 64964 "(+ 1 2 3) (+ 1 2 3)")
;;=> "6"
;;=> "6"

borkdude19:04:32

I'll make a fix for that

borkdude19:04:43

thanks for debugging this issue, it's making sense now

borkdude19:04:12

@jkrasnay I now pushed a fix for that to master. Can you try with:

clojure -A:main --nrepl-server 1667
and then connect with fireplace?

borkdude19:04:30

@jkrasnay Binaries are now also being published to #babashka_circleci_builds so you could also try one of those. @martinklepsch Same for you btw, you can grab a new binary for testing from there with the reader issue fixed.

borkdude19:04:12

relevant commit for fireplace is e2bdd7eae231f63e52760daaf5d419d674957ba0

borkdude20:04:27

@wilkerlucio would be interesting to check if that commit also fixes nREPL for Cursive...

wilkerlucio20:04:21

@borkdude how can I try this version? I tried cloning and running clj -A:main, but got an error:

[email protected] babashka % clj -A:main
Syntax error (FileNotFoundException) compiling at (babashka/impl/async.clj:1:1).
Could not locate sci/impl/vars__init.class, sci/impl/vars.clj or sci/impl/vars.cljc on classpath.

Full report at:
/var/folders/19/s31k0b7j4gl5f4zdl2cd77nc0000gn/T/clojure-8830231708591233376.edn

borkdude20:04:56

@wilkerlucio Try

git clone  --recursive
and then clojure -A:main --nrepl-server 1667

wilkerlucio20:04:43

got same results as before on nrepl:

wilkerlucio20:04:44

Connecting to remote nREPL server...
clojure.lang.ExceptionInfo: Unable to resolve classname: java.lang.reflect.Method [at line , column ]
Error initialising completion
Error initialising locals clearing:
clojure.lang.ExceptionInfo: Could not resolve symbol: *compiler-options* [at line 1, column 6]
clojure.lang.ExceptionInfo: Could not resolve symbol: clojure.core/clojure-version [at line 1, column 57]
Error initialising REPL:Error updating completions:
clojure.lang.ExceptionInfo: Could not resolve symbol: cursive.repl.runtime/completions [at line 1, column 2]
3
=> 3
Error updating completions:
clojure.lang.ExceptionInfo: Could not resolve symbol: cursive.repl.runtime/completions [at line 1, column 2]

borkdude20:04:21

ok, it assumes a lot about the nREPL server it seems. yeah, thanks for testing

borkdude20:04:19

ok folks.. I'm trying vim / fireplace ... It seems to be connected to the nREPL server... but how do I eval an expression? The README says :Eval but that doesn't come up for me

borkdude20:04:49

Do I have to enter some minor-mode like in Emacs or something?

lispyclouds20:04:42

@borkdude yes you need to be on a clojure buffer to activate fireplace

borkdude20:04:53

I am now in a file called /tmp/foo2.clj

lispyclouds21:04:20

Eval should work now

borkdude21:04:41

when I type :E and press tab it says :Explore

lispyclouds21:04:44

also there is #vim too, more helpers there

borkdude21:04:58

when I type :Eval it says "not an editor command"

lispyclouds21:04:09

seems like fireplace is not loaded

lispyclouds21:04:25

how did you install it?

jkrasnay21:04:59

@borkdude try :CljEval (+ 1 1)

lispyclouds21:04:27

ah maybe it has changed in recent versions.

borkdude21:04:45

I did what the README said:

mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone 
vim -u NONE -c "helptags fireplace/doc" -c q

borkdude21:04:16

ah :CljEval does something

lispyclouds21:04:44

yeah im more used to vim-iced now

borkdude21:04:26

It does seem to connect but when I :CljEval something it says no live REPL connection

jkrasnay21:04:46

OK, try :FireplaceConnect <port>

jkrasnay21:04:52

…then the CljEval again

borkdude21:04:04

yeah, I did that already

borkdude21:04:17

I also see messages coming into the nREPL server

borkdude21:04:23

but still 'no live REPL connection'

borkdude21:04:41

oh now it worked!

jkrasnay21:04:17

Just tried latest babashka master and it all works perfectly! Yay!