This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-06
Channels
- # announcements (1)
- # babashka (7)
- # beginners (93)
- # bristol-clojurians (1)
- # cider (7)
- # clj-kondo (42)
- # cljs-dev (9)
- # clojure (67)
- # clojure-europe (4)
- # clojure-france (4)
- # clojure-germany (2)
- # clojure-italy (3)
- # clojure-nl (10)
- # clojure-uk (62)
- # clojurescript (11)
- # clojurex (3)
- # conjure (77)
- # cursive (16)
- # datomic (105)
- # docker (4)
- # editors (3)
- # events (5)
- # fulcro (34)
- # jobs (1)
- # juxt (7)
- # kaocha (7)
- # lambdaisland (3)
- # lein-figwheel (2)
- # leiningen (19)
- # malli (14)
- # meander (6)
- # mid-cities-meetup (6)
- # off-topic (20)
- # pedestal (2)
- # reagent (17)
- # reitit (7)
- # remote-jobs (1)
- # shadow-cljs (17)
- # spacemacs (23)
- # specter (2)
- # tools-deps (34)
I think even if you're starting your REPL on a specific (not random) port, it's useful to write a port file because it means you don't have to coordinate so that Conjure uses that same port. You can configure Conjure to read the port file, and then you can decide to change the port you're using on a whim without needing to reconfigure Conjure
@pez had some opinions on bb writing an .nrepl-port
file. I first implemented it, but then he said something about it which made me remove it. I can't recall the exact discussion. Maybe I should just add it again then?
i have some opinions too: https://github.com/borkdude/babashka/issues/157 🙂
so writing an .nrepl-port is option one and seems to be what a lot of tooling is already doing. maybe it makes sense to choose that one then?
since there is no clear winner and not a lot of people have responded to that issue, nothing happened
As I recalled it, it creates an .nrepl-port
in the root and some other file in .shadow-cljs/
shadow-cljs creates .shadow-cljs/nrepl.port
. .nrepl-port
only when configured to do so.
ah and in shadow-cljs the name of the file is nrepl.port
in the .shadow-cljs dir -- sorry i had that wrong
if you guys can fight it out and give a summary in issue 157 of babashka, I'd be happy to implement that 🙂
it seems clear to me that shadow-cljs has opted for only one instance of shadow-cljs per project. that sounds right, correct?
if pretty much all other folks use the same model of one program instance at a time per project, it seems like shadow-cljs' approach of a .<name-of-tool> directory and state files within makes sense
the thing that doesn't make sense for me is dumping dot files in the project root that multiple tools read/write willy nilly
That was my use case. I think it would be a very nice way to make people aware of babashka as a thing.
--socket-repl Start socket REPL. Specify port (e.g. 1666) or host and port separated by colon (e.g. 127.0.0.1:1666).
--nrepl-server Start nREPL server. Specify port (e.g. 1667) or host and port separated by colon (e.g. 127.0.0.1:1667).
Yeah. I guess it can be put like that. Calva first starts the server, waits for the file, reads the content, then connects to that port.
so the existence of the file acts as a signal that the receiving side is ready -- this is how shadow-cljs behaves iirc
It is a stupid limitation in Calva that I should try to fix. But VS Code makes it a bit hard.
you can find a random port like this:
$ bb -e '(import .ServerSocket) (with-open [sock (ServerSocket. 0)] (.getLocalPort sock))'
51611
and you can wait for a port like this:
$ bb -e '(wait/wait-for-port "localhost" 51611)
I think those ingredients are sufficient to get by without writing a fileif you do need a file, you can write it after the waiting for the port is finished, in the same script
I think that's the most flexible thing to do, especially when you also need a classpath
I think it's on topic since this discussion started with Olical asking for the .nrepl-port 😉
I tend to lean towards "start your repl yourself and write a portfile for automatic connection". Jack in would require some retry until it's there logic I guess.
But if you start it yourself specifying a port in the editor is fine too. Like with a prompt.
i was thinking today to put something together to launch my project and editor from the same script 🙂
fwiw I don't ever use jack-in. I want to be able to kill my REPL just in case my editor freezes
the jack-in ad feature for babashka can be entirely implemented using this I think: https://clojurians.slack.com/archives/CK143P6D7/p1586174810213100 without any changes
iiuc, pez wants to use the file-watcher capability because it's already tested. to implement another method (instructing babashka to start on a certain port and then wait) isn't clearly a win within the confines of vscode iiuc.
something like:
(import .ServerSocket)
(require '[babashka.wait :as wait] '[clojure.java.shell :refer [sh]])
(let [nrepl-port (with-open [sock (ServerSocket. 0)] (.getLocalPort sock))
fut (future (sh "bb" "--nrepl-server" (str nrepl-port)))]
(wait/wait-for-port "localhost" nrepl-port)
(println "Aaaaand it's ready!")
(spit ".nrepl-port" nrepl-port)
@fut)
VSCode can kick off this script from the editor. And then watch the .nrepl-port file.
I'll do it something like that. No worries. Still think it makes sense to have a bb option for creating this file, as well as for using a random port, but it is cool that bb itself can be used to get around the lack. 😃
Even better:
(import [ ServerSocket]
[java.lang ProcessBuilder$Redirect])
(require '[babashka.wait :as wait])
(let [nrepl-port (with-open [sock (ServerSocket. 0)] (.getLocalPort sock))
pb (doto (ProcessBuilder. ["bb" "--nrepl-server" (str nrepl-port)])
(.redirectOutput ProcessBuilder$Redirect/INHERIT))
proc (.start pb)]
(wait/wait-for-port "localhost" nrepl-port)
(spit ".nrepl-port" nrepl-port)
(.waitFor proc))
You can even make that script interactive:
(import [ ServerSocket]
[java.lang ProcessBuilder$Redirect])
(require '[babashka.wait :as wait])
(let [nrepl-port (with-open [sock (ServerSocket. 0)] (.getLocalPort sock))
pb (doto (ProcessBuilder. ["bb" "--nrepl-server" (str nrepl-port)])
(.redirectOutput ProcessBuilder$Redirect/INHERIT))
proc (.start pb)]
(wait/wait-for-port "localhost" nrepl-port)
(spit ".nrepl-port" nrepl-port)
(println "Press enter to kill the nREPL server.")
(read-line)
(.destroy proc))