tools-deps

flowthing 2023-08-07T20:29:42.753759Z

So the invocation to serve a clojure.main REPL over a network socket is a bit of a mouthful (`clj -J-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"`). I’m wondering whether it would make sense to add a built-in alias (like -X:deps) for launching a socket-based clojure.main REPL. Ideally, you’d be able to do something like clj -X:repl, which would launch a socket server serving a clojure.main REPL with :port 0. It’d then write the port number into a file (like Lein does with .nrepl-port). I believe Cursive can read a socket REPL port number from a file now, too, for example. Any trailing args would get passed to clojure.core.server/start-server. I know I’m probably the only person in the world who wants this, but still, figured I’d ask. 🙂

2023-08-07T20:32:49.082309Z

the jvm has built in support for unix domain sockets now, seems a shame for new stuff for local tooling to continue to use network sockets

seancorfield 2023-08-07T20:33:09.115259Z

Bear in mind that -J... combines with any options -- as soon as you tie it to -X:deps, you've excluded a whole bunch of invocations (including -M based stuff).

dpsutton 2023-08-07T20:35:03.305609Z

from my .zshrc:

# sample usage: clj -J"$(socket-repl 6000)" ... or java "$(socket-repl 6000) -jar ...
socket-repl()
{
 echo -n "-Dclojure.server.repl={:port $1 :accept clojure.core.server/repl}"
}

seancorfield 2023-08-07T20:35:20.983609Z

You can always put an alias in your user deps.edn: https://github.com/seancorfield/dot-clojure/blob/develop/deps.edn#L55

Alex Miller (Clojure team) 2023-08-07T20:35:35.106799Z

you can vote for adding something to the cli for this here: https://ask.clojure.org/index.php/7830/first-class-options-for-socket-repl?show=7830#q7830

seancorfield 2023-08-07T20:35:41.709019Z

Then you can use that with -A or -M or -X 🙂

flowthing 2023-08-07T20:36:04.738039Z

Yeah, I’m aware of those approaches (although neither automatically assigns an available port), but it’s an extra hurdle for brand new users, I think.

dpsutton 2023-08-07T20:36:05.745239Z

i use my socket-repl shell function all the time

flowthing 2023-08-07T20:36:12.440129Z

Thanks, Alex! I’ll do that.

flowthing 2023-08-07T20:36:34.886799Z

I do something like this:

(defn start-server
  [_]
  (let [server (server/start-server {:name "server" :port 0 :accept `server/repl :server-daemon false})
        port (.getLocalPort server)
        host (-> server .getInetAddress .getCanonicalHostName)
        port-file (io/file ".repl-port")]
    (.deleteOnExit port-file)
    (spit port-file port)
    (printf "Socket server listening on %s:%s\n" host port)))

👍🏻 1
Alex Miller (Clojure team) 2023-08-07T20:36:51.820089Z

anyone who wants to suggest things for this could also add those to that question if we wanted to collect ideas there

👍 1
flowthing 2023-08-07T20:37:10.020839Z

I juggle so many projects that I don’t want to think about whether a port number’s free.

flowthing 2023-08-07T20:39:06.616269Z

I also considered going with Unix domain sockets earlier, but I didn’t want to require Java 16. Also, it’s handy to be able to connect to a remote socket, too. I’m also not sure whether there’s any benefit to using Unix domain sockets over a network socket (other than avoiding the port number file hassle).