Is there a way to "jack in" to the REPL without a project?

Heya guys, I have a total rookie question:

tl;dr:
Am I supposed to always have a project before attempting to jack-in to a repl? Or is it possible to just start a repl and connect it to a single .clj file?

full story:
I’m using vscode/calva for my clojuring needs & wondering if there is a way to have a playground/sandbox experience with clojure… I mean the repl is supposed to have already solved that problem, but just typing “lein repl” in command prompt means I’ll have to do everything in the command prompt, which is not ideal (I for one prefer an actual code editor)
So far the only solution I’ve found is to make a project (with “lein new”) open said project & then do the whole jack-in process to finally have a “watched” output file inside vscode
But then if I just open a single .clj file (outside of a project context) & try to jack-in, calva spits in my rookie face with a “Cannot read property ‘0’ of undefined”
What’s missing here? Any clue?

1 Like

If you run lein repl it will start an nREPL server and it prints out the port on which it is running. Calva should be able to connect to a running REPL – just not using the jack-in command – and you can tell it to connect to localhost on whatever port lein repl printed out.

I’m assuming Calva can do this based on my experience with several other Clojure editors that can all do this.

1 Like

Calva uses a text document for the repl output, which vscode requires to be stored on disk somewhere, so Calva puts it in a dot directory at the top of the workspace. No workspace, nowhere to put the file. The “cannot read 0” message, I believe, is it trying to select the folder from a list. There is no list, so it’s undefined. Choosing the first one from a non-existent list gives the error.

Opening the folder your file is in might work, that’ll set the directory as the vscode workspace. I haven’t tried it, though.

1 Like

So that’s it then, instead of bothering the calva team with a feature request I should just have a pretend sandbox project somewhere on disk to open up & play with… It’s a workaround, but at least it makes a bit of sense.
And thanks for the explanation :slight_smile:

Not sure about a feature request, but opening a usability bug would make sense. It should check if there’s a workspace and give an error around that instead of what is the JS equivalent of an NPE.

1 Like

I think it’s good to open a ticket for it. Cider supports jacking into non project files or even buffers. So I’m sure it’s a feature Calva would aspire to support as well.

Calva maintainer here. Yes, please file a ticket. We can find somewhere to create the repl file when there is no project opened.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.