Fork me on GitHub
#calva
<
2021-04-15
>
flowthing11:04:29

So related to my question yesterday: how does Calva determine whether ClojureScript evaluation via shadow-cljs is available?

flowthing11:04:42

Hmm, well, I finally got it to work, so never mind I guess. 🙂

pez11:04:06

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.

flowthing11:04:14

Although only by connecting, not jacking in, but that'll get me started.

flowthing11:04:30

Right, the first bit is what I was asking about.

flowthing11:04:38

The rest I'm familiar with.

pez11:04:59

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.

flowthing11:04:32

CIDER middleware won't (necessarily) be available if I connect. though, right?

pez11:04:01

It needs to be injected or present in the project deps.

flowthing11:04:40

Yeah. Anyway, the question I'm interested in is how Calva knows ClojureScript evaluation is supposed to be available. 🙂

pez11:04:18

Have I answered that, or are you still wondering?

flowthing11:04:36

Still wondering.

pez11:04:43

Tell me what you are trying to do and the steps you use and I might be able to help figure.

flowthing11:04:20

I jack in -> Choose "Leiningen" -> start shadow-cljs watch from the REPL -> run (shadow.cljs.devtools.api/nrepl-select :app).

flowthing11:04:32

Can't evaluate ClojureScript, because Calva won't let me.

flowthing11:04:42

My question is, why not? 🙂

pez11:04:24

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.

flowthing11:04:25

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.

pez11:04:56

It knows it by the project type you choose when connecting.

flowthing11:04:23

Okay, I see, so that's the only thing it uses for making the determination. That won't help me, then.

pez11:04:31

Is anyone using CIDER with the project?

flowthing11:04:34

shadow-cljs presumably won't work, because the shadow-cljs nREPL server isn't running yet.

flowthing11:04:01

Anyway, this is enough information for me to go on. Tack ska du ha! 🙏:skin-tone-2:

pez11:04:17

Är du frĂ„n Sverige?

pez11:04:54

Awesome.

pez11:04:17

Why isn’t the shadow-cljs nREPL server running?

flowthing11:04:35

Because we start it from the REPL.

pez11:04:29

I see. Maybe you will need to configure a custom connect sequence then. https://calva.io/connect-sequences/

flowthing11:04:45

Thanks! I'll give that a try.

pez11:04:10

startCode would be where to put the (server-start!) (probably in a do with the require)

pez11:04:36

Let me know how you fare. I’m curious.

flowthing11:04:27

Will do. Giving it a try now.

flowthing12:04:38

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 startCodeand 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.

flowthing12:04:24

Anyway, this is good enough for me (my colleague, really). Thanks for the help!

pez12:04:56

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.

flowthing12:04:40

Yeah, that's how I understood it. However, if I set it, it seems to assume that ClojureScript isn't necessary.

flowthing12:04:27

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.

pez12:04:31

Please report as an issue.

pez12:04:54

> 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.

pez12:04:08

When reporting the issue, “views” are called “editors” in VS Code.

pez12:04:54

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": ""
            }
        }
    ]
}

pez12:04:47

Calva will lie about it being a cljs repl at first, but once the commands have been run it should be good.

pez12:04:22

(I’m not sure about this, but from what I remember of the implementation, I think it might work.)

flowthing12:04:46

All right, I'll give that a try.

pez13:04:22

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

flowthing13:04:51

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...

pez13:04:44

Fair enough. 😃

flowthing13:04:17

Unless it becomes a real pain point for the colleague I'm mentoring, that is. 🙂

pez13:04:44

Then maybe your colleague will file the issue? 😃

flowthing13:04:19

I can ask. 🙂

pez13:04:15

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.

Thomas16:04:00

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!

pez16:04:11

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.

Thomas17:04:49

@pez Thanks here, as well 🙂

calva 1
pez18:04:37

You are welcome, söta bror! 😀