So related to my question yesterday: how does Calva determine whether ClojureScript evaluation via shadow-cljs is available?
Hmm, well, I finally got it to work, so never mind I guess. 🙂
First it needs to know it is supposed to be available. If so it clones the CLJ session and converts the clone to a CLJS session. Then it is a matter of shadow-cljs to connect the app to this session, which it will do once the app is running.
Although only by connecting, not jacking in, but that'll get me started.
Right, the first bit is what I was asking about.
The rest I'm familiar with.
It is the same, wether or not connecting or jacking in. The command Copy Jack-in Command line (or some such) will give you the command that Calva uses to start shadow-cljs.
CIDER middleware won't (necessarily) be available if I connect. though, right?
It needs to be injected or present in the project deps.
Yeah. Anyway, the question I'm interested in is how Calva knows ClojureScript evaluation is supposed to be available. 🙂
Have I answered that, or are you still wondering?
Still wondering.
Tell me what you are trying to do and the steps you use and I might be able to help figure.
I jack in -> Choose "Leiningen" -> start shadow-cljs watch from the REPL -> run (shadow.cljs.devtools.api/nrepl-select :app)
.
Can't evaluate ClojureScript, because Calva won't let me.
My question is, why not? 🙂
Because Calva doesn’t know you want CLJS. You’ll need to use a project type which includes that knowledge. I know it failed with “Leiningen + shadow-cljs”, but you could try with only shadow-cljs
or the lein-shadow
one.
Yes, so my question is, how does Calva determine whether I want CLJS? I'm asking so that I could dig into the Calva code a bit to figure out whether there's a way to make it work without changing the project configuration.
It knows it by the project type you choose when connecting.
Okay, I see, so that's the only thing it uses for making the determination. That won't help me, then.
Is anyone using CIDER with the project?
shadow-cljs
presumably won't work, because the shadow-cljs nREPL server isn't running yet.
No.
Anyway, this is enough information for me to go on. Tack ska du ha! 🙏:skin-tone-2:
Är du från Sverige?
:flag-fi:
Awesome.
Why isn’t the shadow-cljs nREPL server running?
Because we start it from the REPL.
I see. Maybe you will need to configure a custom connect sequence then. https://calva.io/connect-sequences/
Thanks! I'll give that a try.
startCode
would be where to put the (server-start!)
(probably in a do
with the require
)
Let me know how you fare. I’m curious.
Will do. Giving it a try now.
All right! I got it to work by defining a connect sequence like this:
{
"name": "App",
"projectType": "Leiningen",
"cljsType": {
"startCode": "(user/start)",
"connectCode": "(user/cljs-repl)"
},
"isConnectedRegExp": "To quit, type: :cljs/quit",
}
It's not exactly what I want, because I'd prefer to leave the things startCode
and connectCode
do up to the user. Based on the documentation, it sounds like isStarted: true
should do what I want, but if I set that, I can't evaluate from the ClojureScript buffer.Anyway, this is good enough for me (my colleague, really). Thanks for the help!
I don’t quite recall right now what isStarted
is supposed to do, but maybe it is just that, that Calva expects it to be started.
Yeah, that's how I understood it. However, if I set it, it seems to assume that ClojureScript isn't necessary.
Also, this is unrelated, but I just happened to notice that if you evaluate a form such as (do (Thread/sleep 5000) {:a 1})
in one view, then open another view before the sleep is done, Calva shows the inline evaluation result in the currently active view, not the view where you evaluated it.
Please report as an issue.
> Yeah, that’s how I understood it. However, if I set it, it seems to assume that ClojureScript isn’t necessary. It will still try to connect. So the repl really needs to be started. Which it isn’t in your case, iiuc.
Oh, I see.
When reporting the issue, “views” are called “editors” in VS Code.
If you really want it to be manual steps you might get away with something like
"calva.replConnectSequences": [
{
"name": "foo",
"projectType": "Leiningen",
"cljsType": {
"dependsOn": "shadow-cljs",
"startCode": "",
"connectCode": ""
}
}
]
}
Calva will lie about it being a cljs repl at first, but once the commands have been run it should be good.
(I’m not sure about this, but from what I remember of the implementation, I think it might work.)
All right, I'll give that a try.
Thanks!
I think it makes sense to have some kind of “User managed” cljs repl, btw. So regardless if that trick I speculated about works or not, I’d appreciate an issue about making it a first class citizen option. Thinking it could work a bit like you expected it to work, but it would be choosen something like : > Project type: Leiningen + Manually started ClojureScript REPL
Yeah, I think that might be useful. I don't use Calva myself, though, so I think I'll leave it to someone else to create the issue. 🙂 Only got so many hours in the day...
Fair enough. 😃
Unless it becomes a real pain point for the colleague I'm mentoring, that is. 🙂
Then maybe your colleague will file the issue? 😃
I can ask. 🙂
To me the important thing is to have someone who’ll be willing to test any attempts to fix the issues. So it is nice with someone with stakes in it filing them.
Exactly.
Hi. I am using the "Getting Started REPL" in VSC. I'm trying to use the (source) function to find the code behind the (map) function. I understand that I am to type (source map) into the REPL. I have tried doing this into the output REPL, and into the bottom terminal. What REPL am I suppose to use? As you probably understand, I'm not only new to Clojure but very green in programming. So please keep it simple for me!
In Calva you seldom need to use those functions. Just hover the symbol in the regular files. Use ctrl/cmd to see definitions. Ctrl/cmd-click to navigate to the source.
@pez Thanks here, as well 🙂
You are welcome, söta bror! 😀