Fork me on GitHub
#calva
<
2023-02-16
>
cjmurphy10:02:08

I'm attempting to get a REPL into an existing project that has an nREPL Server, running with particular deps.edn aliases. I'm accustomed to working on this project using IntelliJ IDEA/Cursive. With Cursive one sets up a configuration specifying a connection type of nREPL, and that the nREPL is running at localhost:5309. That's all! Running this configuration gives you the local REPL needed for starting the web server and doing REPL development. Is there an equivalent configuration with Calva? I think the answer is no, as I've tried https://calva.io/connect/ at the heading "Connecting Without Jack-in". There isn't a Connect to a running REPL (as specified in the docs) but I assume the equivalent is now Calva: Connect to a Running REPL Server in the project. Trying that gave me this:

The nREPL server does not support cider-nrepl info op, which indicates troubles ahead. You need to start the REPL with cider-nrepl dependencies met.
Is it true that Calva only works with cider? I've put the cider-nrepl dependency into the nREPL Server, but that didn't help. So I guess my next question is how to support the 'info op', and what info will need to be supplied?

pez10:02:07

Hi! I don't understand the part with how things work in Cursive and thus can't answer if it is possible in Calva. Can you describe what you need to work without framing it in how it works in Cursive? Calva works best with cider-nrepl, but doesn't strictly require it. There'll probably be some things that don't work. There's a command for copying a command line that will satisfy Calva's dependency needs. Calva: Copy Jack-in Command Line (or something like that). See if you can use that (with any adaptions you need) to start a REPL server that Calva does not complain about.

cjmurphy11:02:11

What (ideally) I need to work is connecting to a running nREPL Server by only specifying its host (localhost) and its port (5309). In our case the running nREPL Server has already setup everything via aliases, so I just need to get a local REPL that channels the commands back and forth to the nREPL Server. FWIW that's what I need to work without mentioning Cursive at all. I've now got the Jack-in command line. I'll try to work with that. Thanks.

pez11:02:12

What does a local REPL mean? Is it some kind of proxy? Generally if you have an application running with the nrepl dependencies and middleware configured, the Calva connect command should work. It will prompt you for a host and port. The prompt will be pre-populated if there is a repl port file present. Which file Calva looks for depends on the project type. You can also specify a custom REPL Connect Sequence, and change the port file there.

cjmurphy11:02:15

'local REPL' is my made up expression. It is a command line that I type Clojure into, that communicates with the nREPL Server. What should I call it?? Anyway 'Calva Connect' sounds promising. Got to run for something but will try it later. Thanks again...

pez11:02:15

Ah, sorry for being thick. That's what in Calva is referred to as the REPL client, I take it. I should have figured on channels the commands back and forth to the nREPL Server. Anyway, I think what's going wrong is that the cider-nrepl middleware isn't correctly injected. Let me know how you fare, I am pretty sure we can get this working. Possibly with one prompt more than you are used to.

cjmurphy13:02:07

Working now. The Calva: Copy Jack-in Command Line to Clipboard is a great idea and worked perfectly. I used it to augment what was already at the alias that has :main-opts ["-m" "nrepl.cmdline" ...]. Yes there might be one or two times I have to press <enter> with filled in defaults compared to what I'm used to with Cursive. And as you say I could even get past that with a repl port file to specify the port.

pez13:02:55

Great to hear! You can get an almost prompt free experience with https://calva.io/connect-sequences/, Though we need to fix https://github.com/BetterThanTomorrow/calva/issues/1908 to get rid of the port prompt entirely.

seancorfield17:02:56

@U0D5RN0S1 You might find https://corfield.org/blog/2022/12/18/calva-joyride-portal/ interesting as it talks about how we run plain nREPL servers in production processes at work and connect to them from Calva to debug stuff (we also run Portal servers and connect a browser to those, inside Calva, for visualization while debugging).

😍 4
alpox17:02:22

Thanks too @U04V70XH6 bookmarked that.

ericdallo13:02:50

I received some complains about Calva watched files sending to clojure-lsp analyze clojure-lsp stub files

ericdallo13:02:41

we could fix in calva or in clojure-lsp, specifically telling to ignore .lsp/.cache/stubs but I wonder if Calva should not do that, suppose there is a file my-root/my-random-folder/some-weird-file.clj , that is not in the source-path, calva will send and lsp analyze and report any found errors

pez13:02:07

Is there ever a case when we want notifications from the lsp cache? Calva could have an exclude list of globs, with some sane defaults, I think.

ericdallo13:02:05

if the user find a definition of datomic.api we should show the errors, the issue is that it's being shown even without opening the cache files

bringe19:02:57

Was it verified that those files were not somehow included in source paths? I’m guessing they weren’t, but anyway, I don’t know why those notifications are sent but I assume it’s something to do with how the vscode language client works by default. Maybe we can stop it from sending those notifications by default, but then make sure errors are still shown if they open a file like that. If we exclude files in .lsp/.cache/stubs, I’m guessing even if they open one they still won’t get errors since it’s excluded? An issue is welcome.

ericdallo21:02:12

Yeah, they are not in the classpath. Exactly, I suspect this is how vscode file watcher works, if we could add .lsp/.cache to a filter would probably be enough

👍 1
Isac13:03:35

So guys, do we have news of that topic?

bringe00:03:09

Not that I'm aware of. Is this still a problem for some users? I'm guessing it is for you, @U9N15525C? If so, would you mind creating a GitHub issue about it?

Isac20:03:01

I opened an issue and feel free to request more details if the isn't enough. https://github.com/BetterThanTomorrow/calva/issues/2465

👍 1
pez20:03:36

Thanks. Maybe you can include information about what a stub file is? Maybe I’m not the only one who doesn’t know. 😃

ericdallo21:03:27

The clojure-lsp stub is a clojure-lsp feature which uses https://github.com/clj-easy/stub lib to generate dummy clojure files to have clj-kondo analysis, so for example one would get auto complete for datomic.api for example, a lib which is closed source

👍 1
ericdallo21:03:21

This feature spawns under the hood a clj process which exports the ns and vars, it's only enalbed if one has a :stub setting in clojure-lsp config

👍 1
pez21:03:03

Sounds pretty awesome. Thanks for explaining!

👍 1
Craig McDaniel15:02:53

Is there a way to configure Calva to redirect REPL stdout to a file? I’d like to be able to use some unix command line tools on it (lots of noise).

pez16:02:26

Not possible to configure Calva for this. There's an issue about it here: https://github.com/BetterThanTomorrow/calva/issues/1104 Some options: • The Output/REPL window is a file. Run your unix commands on that file? • Set some dynamic variable for where stdout should go (I don't know if this works, but seems it should...) • Evaluate the things you are interested in via Calva's API https://calva.io/api/#replevaluatecode from #joyride, this API supports a callback function for stdout. (This option is not very nice if you want to redirect evaluations generally, but good to know about, I think.)

Craig McDaniel16:02:25

Can I configure it to use a custom shell command for starting the REPL?

Craig McDaniel16:02:51

… for jack-in

Craig McDaniel16:02:51

I’m sure I could start lein from the command line and connect Calva via REPL port. I realize I don’t get all the nice nrepl integrations that way, but I don’t need that in this case

pez16:02:51

Not sure I follow... You can copy the jack-in command to the clipboard and start the repl yourself.

Craig McDaniel16:02:20

that is exactly what I am trying now

Craig McDaniel16:02:26

piping it through tee

pez16:02:33

Jack-in does not support custom shell commands today. I've been wanting to add that a while.

pez16:02:03

Another option would be to add a tap that prints to where you want. That is similar to tee.

pez16:02:09

(In concept)

wevrem19:02:40

These actions produce an extra space that I wish weren’t there:

⏐:b
  ;; Want to wrap :b, type '['
[⏐]:b
  ;; slurp forward
[⏐ :b]
  ;; don't like that space, wish instead it were
[⏐:b]
There are ways to ‘fix’ it. I can immediately hit TAB and the space goes away, or I can select :b before hitting [. This isn’t specific to brackets, it’s the same result with any delimiter. Any suggestions?

pez20:02:58

I agree. We changed this a while ago to fix another problem, but this extra space is quite annoying. You are welcome to file an issue.

wevrem20:02:16

Thanks @U0ETXRFEW I filed an issue.

🙏 2
seancorfield20:02:14

Or ctl+alt+shift+p to wrap-with-`(`..`)`

seancorfield20:02:06

(similarly cas+ s/c for square/curly)

pez21:02:23

Yes, for some slurp operations there are alternatives. But not for all and this space is not cleaned away properly for more Paredit commands.

2
pez07:02:17

I've tried to add some context to the issue in a comment now. And the question's out to @ahtunget if you feel hungry for yet another PR? https://github.com/BetterThanTomorrow/calva/issues/2085

skylize05:02:22

Honestly, I quite like the current behavior. Yes, it can be slightly annoying sometimes. But what about the case where you want to keep typing where the cursor is?

; now I want to add foo
[|bar]
If you start typing immediately, there is no space between your cursor and the slurped-in symbol.
[foo|bar]
Type hinting is broken and clj-kondo throws a fit about foobar not being declared. The solution is, of course, is to type Space then Left-Arrow. before you start typing again.
[|bar]
[ |bar]         ; space
[| bar]         ; left
[foo| bar]  ; now we  can finally type
But coming up with that uses way more cognitive load than a simple Delete when the space is unwanted.

dabrazhe20:02:41

After a recent update of VSC/Calva, all symbols required as :refer :all from another workspace are highlighted in red by the editor. Any fixes?

pez21:02:42

It's clj-kondo that is discouraging you from bad habits. 😃 I thought it was doing that by default since long, but maybe I am wrong. Could be that it is new and clojure-lsp has been updated because Calva set to use latest clojure-lsp. You can disable this linting by adding clj-kondo config. See https://calva.io/linting/ for some pointers.

dabrazhe21:02:40

Thanks. How can I suppress this on the workspace level?

pez21:02:14

Edit the .clj-kondo/config.edn file (I don't know the exact config).

dabrazhe21:02:23

Ok. Thanks. Why is it a bad habit, what's wrong with refer all by the way? )

phill00:02:58

There are some answers to this at https://stackoverflow.com/questions/24463469/is-it-possible-to-use-refer-all-in-a-clojurescript-require, including that refer-all was omitted from ClojureScript because it is such poor style. :-)

phill11:02:16

Clojure aims at an ideal that program code should be "evident" - the meaning should be visible. I seem to recall Java's "import star" being cited as a motivating anti-pattern: it "saves time" for the first ten minutes and forever thereafter confounds you. Core-library symbols are excused, but every other symbol should be defined in the file where it is used. A single refer-all strains the principle because there is no positive indication of the source of a symbol, and a second refer-all suddenly drowns the reader in cluelessness.

✔️ 4
Brian smith22:02:17

Hello Calva friends! I have been using Calva in VS Code in WSL for quite a while but it looks like I may have to use VS Code in Windows now. I cloned a repo and when I opened it in VS Code I get this message:

pez22:02:41

Is lein installed in Windows?

Brian smith22:02:00

I can successfully do a lein run.

pez22:02:20

Can you do it from an integrated VS Code terminal?

Brian smith22:02:26

Hmmm Cannot run program "clojure" (in directory "C:\Projects\activity-indexer"): CreateProcess error=2, The system cannot find the file specified

Brian smith22:02:45

I am able to run one Clojure project and get no errors.

Brian smith22:02:51

So this must be project dependent.

Brian smith22:02:01

I noticed no .lsp directory.

pez22:02:16

There are a few things to consider here: • In the Leiningen project, clojure is not needed. • If you are starting the project with Calva Jack-in, and clojure is not installed, it will still work (Calva uses a fallback method)

Brian smith22:02:18

A lot of times I lein run and then connect to the project repl. Sometimes we spin up a repl port when running in dev.

pez22:02:59

Sometimes VS Code does not have the same environment as you have at a command prompt. So to see that lein works, use it from an integrated VS Code terminal. If that doesn't work, then clojure-lsp will fail for that project.

Brian smith22:02:29

All I do is run from the integrated terminal.

Brian smith22:02:33

Less windows. 🙂

pez22:02:08

I see. Then I actually don't understand why you get that error. Maybe @UKFSJSM38 has some input.

Brian smith22:02:14

Ok. I'll keep going. Not sure if stuff in my project is causing it. I'll try another one.

pez22:02:07

For the best Calva REPL experience: When using connect to connect to a running REPL, That REPL should be started satisfying some Calva dependencies. There is a command Calva: Copy Jack-in Command Line that gives you a command for starting the REPL in a Calva compliant way.

Brian smith22:02:45

Oh cool! I'll check it out! Thank you for responding so quickly.

Brian smith22:02:38

All this because I had to switch to a 3rd party VPN and my projects in VS Code in WSL2 can't connect to Postgres SQL now.

pez22:02:54

Also: A lot of Calva still works even when clojure-lsp fails to start, so you can still work on your project.

Brian smith22:02:05

Ok. Thanks, again.

pez22:02:27

Windows and Clojure is not exactly a love story...

Brian smith22:02:07

Yeah. My coworkers all have Macs and I went to the effort to set up a dev environment in WSL2 so we could be same-same.

pez22:02:02

Maybe try figure out how to connect that Postgres from WSL2. Sounds like it shouldn't be impossible?

ericdallo22:02:19

Not sure as well, the print shows that is trying to run lein.bat

Brian smith22:02:11

Yup. I would rather stay in WSL2. Thanks for your time.

seancorfield22:02:23

@U01925RGFC7 I'm curious which VPN doesn't work with WSL? We use the Cisco AnyConnect client at work and WSL is fine with that -- I ssh from WSL to servers at work all the time with the Windows VPN in place.

Brian smith22:02:27

CheckPoint Endpoint Security

seancorfield22:02:40

Good to know. Thanks.

Brian smith22:02:46

I can ping the Postgres server all day long. But can't connect.

bringe22:02:42

@U01925RGFC7 Have you tried running this exact command in a terminal (integrated and not)?

bringe22:02:28

I mean using that absolute path to that lein.bat file along with the args stated in that message.