Fork me on GitHub
#calva
<
2021-10-05
>
Stefan06:10:27

Hi all! I have a question about custom repl connect sequences. I’m working in a monorepo with multiple projects, each with their own deps.edn file. When I jack-in though, 99% of the times I want one specific project to jack-in, the “main” project if you will. I made a custom repl connect sequence that picks some aliases and runs some code after jack-in, but here’s what I’m missing: I would like to be able to specify which of the projects in the monorepo has to be jacked-in. The way it works now is that the project of the file that I happen to have open in my editor is picked, but that’s often not what I need. So is this possible currently? Thanks!

seancorfield06:10:20

@stefan.van.den.oord Simple answer: don't try to "jack in" via your editor, start a REPL at the terminal that is exactly what you want.

seancorfield06:10:43

I run my REPLs for weeks. I have to restart my editor every few days.

Stefan06:10:35

Ah right that didn’t even occur to me 😅 I’ll give that a try and see how that works for me, thanks for the suggestion!

seancorfield06:10:36

We have a monorepo at work (that is partially migrated to Polylith) and we start a REPL at the terminal and connect our editor to it.

Stefan06:10:07

(Does it matter in terms of calva features/capabilities whether you start the REPL yourself or through jack-in?)

seancorfield06:10:27

No. A REPL is a REPL.

seancorfield06:10:01

But starting it yourself -- outside of your editor -- gives you full control.

Stefan06:10:41

Reason I’m asking is because it seems Calva is adding some stuff to the REPL when jackin in.

seancorfield06:10:44

We don't use nREPL at all. We just use plain Socket REPLs 🙂

seancorfield06:10:09

You can start a REPL yourself that is exactly the same as Calva would start.

pez06:10:41

Regardless if you jack-in or connect, Calva will pick the project root from the current file you have open and up to where it finds a project file. So you will not fix this problem with switching from jack-in to connect. Please upvote and cheer on this issue for Calva to be smarter about monorepos. https://github.com/BetterThanTomorrow/calva/issues/1254

1
seancorfield06:10:46

That's really not relevant. For Polylith, you should start the REPL outside your editor with clj -A:dev:test plus whatever aliases you need to start a connectable REPL of your choice. You really can't expect Calva to "solve" that problem.

Stefan06:10:46

Indeed I just found that connect still has that same requirement of being in the right project.

Stefan06:10:20

Also, I just realised that jack-in allows me to share the repl port easily over live share, which connect does not.

seancorfield06:10:21

I run this at work

SOCKET_REPL_PORT=5000 clojure -Sforce -M:rebel:portal:everything:dev:test:runner:build:dev/repl

👍 1
seancorfield06:10:02

I mean, seriously, you cannot expect "jack-in" to work for every project -- people have to do some work, you know?

seancorfield06:10:56

Don't get me wrong: jack-in is great for simple projects, using "defaults".

pez06:10:50

As for the differences. Calva manages the lifecycle of the REPL if you jack-in. Otherwise there is no difference as long as you provide the same dependencies as jack-in does. A way to make that easier is to use the Calva command Copy Jack-in Command line (I don’t recall the exact name) and then use that modified or verbatim, depending on circumstances. But I would stick to Jack-in, it keeps you honest around having an easily started REPL. 😃 > Also, I just realised that jack-in allows me to share the repl port easily over live share, which connect does not. TIL

Stefan06:10:17

Oh haha I just noticed that using “connect” and then sharing that via live share does actually work, I forgot I implemented it that way :rolling_on_the_floor_laughing:

😂 1
1
pez06:10:09

UnTIL. 😃

🙃 1
Stefan06:10:47

Anyway, conclusion for now: I upvoted the abovementioned #1254 and I’ll try whether keeping my REPL running longer will bring me anything, even though it doesn’t seem to help with my original question. Thanks for your thoughts guys, have a nice day!

❤️ 1
seancorfield06:10:37

dev=> (up-since)
#inst "2021-09-25T23:37:12.873-00:00"

pez06:10:39

VS Code keeps processes in its terminals running and reconnects them between restarts. I think we can make the jack-in process persistent as well, since it’s using a pseudo-terminal, but I haven’t looked in to it.

Stefan06:10:42

Cool 🙂 I assume that this means you also use things like ns-unmap now and then? I tend to end up in a situation where I “have to” restart my REPL now and then.

seancorfield06:10:25

Very rarely but yes, occasionally. You can see my hotkeys/shortcuts in my vscode-clover-setup repo (combined with my dot-clojure repo).

Stefan06:10:28

That (using clover and custom commands) looks interesting, I’ll try that as well, thanks again! 🙂

Hukka08:10:37

I would be super surprised if a repl launched by calva would stick around even after closing calva/vs code

pez08:10:26

As you would be super surprised to see it stick around if you start it in an integrated terminal and then connected to it, right? It’s because that behaviour is new. Once VS Code users are accustomed to that, I think we will start getting questions about why jack-in behaves differently. But we’ll see. I doubt I’ll get the time to look into this before the questions arrive. 😃

Hukka08:10:26

Yeah, I wouldn't expect to have my terminals to go to a magic vscode land and come back when the ide starts again. I expect them to die 🙂

pez08:10:15

If you want them to die, then there is a setting for that. But default is that they hang around in magic vscode land. Which I think is consistent with other VS Code behaviour, keeping unsaved files around and such.

Hukka09:10:33

I'll go look for that setting right now, I could see this biting me when I have forgotten

Hukka09:10:34

Hm, I can see a setting for confirming whether to kill terminals, but not when to actually terminate them. Need to google a bit, I guess

Hukka09:10:48

I found a few closed bug reports about the terminals staying alive, but seemed like that wasn't the intended behaviour and was fixed. Also the VS Code docs say that the terminals will reconnect after a window reload, for example after an extension upgrades or installs. But nothing really about terminals sticking around after closing the IDE, and starting it again.

pez09:10:43

Ah, I might have it confused with reload. I almost never restart VS Code, but I reload the extension development host a lot.

Hukka09:10:13

Ok, sounds plausible. I've also tried to have something in the shell, but can't get it ever to come back after restart

Hukka09:10:54

Of course if something forked completely, it would be super tricky and really not even expected to die with the editor, but something like having an echo in a while loop straight in the shell does really seem to die

Hukka09:10:35

So I guess the conclusion is that long lived repls need to be, and should be, launched externally

pez09:10:27

Indeed. Even if many of my REPLs live for quite long, it’s not explicit goal I have.

Hukka09:10:36

I think the current system is very good. Calva can manage the repl lifecycle, or I can.

Hukka09:10:12

The only thing I could forsee ever wanting is an explicit detach command, where I notice that some calculation I started is going to take a while, so I'd like the repl to live on even after closing the IDE. Mostly to release the resources calva is using. But that's very theoretical, I'm not running out of ram due to calva

bringe01:10:51

Do you mean detaching from an external repl? Would the disconnect command achieve what you want?

Hukka05:10:40

I mean the repl that the calva starts when doing a jack-in

👍 1
borkdude08:10:13

When I evaluate an expression, my cursor is stuck behind the text of the output. Is it possible to have the cursor always at the end of the expression, rather than the output?

Hukka08:10:18

Which way you evaluate? I haven't seen that behaviour, either with alt-enter or ctrl-shift-enter

borkdude08:10:06

Same with both:

Hukka08:10:06

Ah, I see! I think I'm never neatly just after the expression I'm evaling, but usually inside it

borkdude08:10:58

This behavior trips me over, in emacs the output text doesn't change the cursor position

pez08:10:04

It is partly because of emacs you stick your cursor neatly behind the bracket. 😃

pez08:10:45

I don’t like this behavior either. It’s a conflict with GitLense which uses :after CSS decorations, so we need to use :before. We could make it a setting for people who don’t use GitLense (or some other conflicting extension).

Hukka08:10:52

Surely then it conflicts with something else, that tries not to conflict with GitLense? I mean, having just two slots sounds just marginally better than one

pez08:10:39

It seems unusual with extensions decorating like this. Once one arrives and gets commonly used, I think both GitLense and Calva will start to get complaints. The API sucks a bit.

bringe01:10:27

I just had a friend who’s learning Clojure and Calva ask me about this too.

bringe01:10:39

What’s the deal with Gitlens? I don’t use it, but I see that behavior as well. I don’t think I understand what you mean, @U0ETXRFEW, regarding how Gitlens is related.

Hukka05:10:04

Looking at that extension screenshots, it seems to also put "stuff" next to the lines, and if that works with css :after and :before, different CSS rules would override each other

pez06:10:41

Exactly. We are decorating the last character on the line (the end-of-line character) with the results as content on a CSS :before style rule. Gitlense is using :after and would most often win the race (by being late to the party) if Calva also used that. So I switched to :before, with the unfortunate side effect that if your cursor is on that character, it will be pushed away by the inline displayed results. They are :before after all.

👍 1
bringe16:10:09

It’s unfortunate if there is not another mechanism for showing content in the editor like that, without actually inserting it into the file, and still having it stick around (which cannot be achieved with hovers, I think).

pez17:10:26

Consider putting some extra attention on this age-old VS Code issue: https://github.com/microsoft/vscode/issues/3220

👍 1
pez17:10:48

A ton of thumbs up on this comment would maybe help (probably not, but anyway): https://github.com/microsoft/vscode/issues/3220#issuecomment-430124153

Jakub Holý10:10:43

Hi! How do I know what version of clojure-lsp is included in Calva? Thanks!

1
pez11:10:42

I think you see it in the output channel “Calva says” at startup.

1
🙏 1
bringe01:10:25

You can also run the LSP info command (don’t remember the exact name) to get the version plus more info about the clojure-lsp instance running.

Jakub Holý06:10:22

Not sure Calva installs its bundled lsp globally on the OS

pez06:10:21

I can’t unpack that sentence, @U0522TWDA 😃

Jakub Holý06:10:22

Calva bundles Clojure-lsp, right? But unless it puts it in /user/bin or similar, I cannot just run it on the CLI. Of did @U9A1RLFNV an not CLI but Calla "lsp into command"?

pez06:10:14

There’s a Calva command for showing clojure-lsp info. It won’t show you a different version than what’s shown in Calva says, though. If you want to find the executable, you can use the VS Code command Extensions: Show Extensions Folder and you’ll find the executable in the betterthantomorrow.calva-2.0.214 directory.

❤️ 1
☝️ 1
Tomas Brejla13:10:23

Hello. I've just skimmed trough this new on the code again youtube video (they're great!) and I believe Daniel might be hitting some bug in calva. Watch the segment between 4:00 and 4:10. https://www.youtube.com/watch?v=n0BTsKVs1Lw&amp;t=240s When he evaluates the (into ["a"] ["b"]) form, he gets the result in output.calva-repl window, but then after a while the Print stacktrace appears. Weird, isn't it?

❤️ 1
pez13:10:27

Good catch! I think it is because he clears the output window now and then, it happens again at 5:36. Please file an issue about it. It should not be super hard to fix it, if we just decide on what the Ux should be for a stacktrace that is not examined.

Tomas Brejla13:10:53

Btw to everyone around: feel free to subscribe to Daniel's youtube channel, I really like the way he's making his videos - they're often short and informative. He already made quite a few! https://www.youtube.com/channel/UCKlYSDBb1KBcZyCRbniW1ig

❤️ 1
Tomas Brejla13:10:52

> Please file an issue about it. Will do. :thumbsup:

pez13:10:33

Also, Daniel is a happy learner, so if you comment on his videos with tips, hints, questions, he will take care of your feedback.

truestory 1
pez13:10:42

I added the link as a comment on the video. 😃

👍 1
Tomas Brejla16:10:35

I don't see that comment you mentioned.

pez17:10:11

Neither do I. Maybe it got marked as spam.

Tomas Brejla22:10:57

Perhaps Daniel has to approve it as non-spam first in order to show up. We shall see..

Jakub Holý16:10:42

https://calva.io/remote-development/ doesn't really provide any instructions on how to set up a dev container with Clojure installed. Perhaps it should?

pez16:10:47

If you, or anyone, knows about this, please PR. Maybe start with an issue. I copied that page from the wiki, I don’t recall who wrote it, but it certainly wasn’t me because I know zero about the issue. 😃

👍 1
Jakub Holý16:10:21

I am setting this up for myself so if I get it working, I will contribute it

❤️ 1
pez16:10:05

Deal! And first an issue? 🥺 🙏

Jakub Holý17:10:14

too late 😅 Will make it now

😂 1