Cider-nrepl

1 view
Skip to first unread message

Bran Cardello

unread,
Aug 5, 2024, 1:18:33 PM8/5/24
to standisvami
Despiteits name, cider-nrepl is editor-agnostic and is leveraged by several otherClojure editors, besides CIDER (e.g. vim-fireplace, iced-vim, Calva, CCW).While the project is officially a part of CIDER, its development is a jointventure between all interested tool authors.

All of the middleware that are currently part of cider-nrepl are relying onREPL state introspection to perform their work. While we might leveragestatic code analysis down the road for some tasks, cider-nrepl will alwaysbe a REPL-first tool.


cider-nrepl tries to have as little logic as possible and mostlyprovides thin wrappers over existing libraries (e.g. compliment,cljfmt, etc). Much of its core functionality lives inorchard, so thateventually it can be used by non-nREPL clients (e.g. Socket REPLclients).


Normally cider-jack-in would inject only cider-nrepl and cider-jack-in-cljs wouldadd piggieback as well. The injection, however, mechanism is configurable andyou can easily add more libraries there. Some CIDER extensions (e.g. sayid and clj-refactor) would usethis mechanism to auto-inject their own dependencies.


CIDER can also inject a Clojure dependency into your project, which is useful,for example, if your project defaults to an older version of Clojure than thatsupported by the CIDER middleware. Set cider-jack-in-auto-inject-clojureappropriately to enable this.


To use cider-jack-in with tools.deps on Windows set thecider-clojure-cli-command to "powershell". This happens by defaultif you are on Windows and no clojure executable is found. Using"powershell" will Base64 encode the clojure launch command beforepassing it to PowerShell and avoids shell-escaping issues.


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


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.


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.


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.


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


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.


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


@U0D5RN0S1 You might find -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).


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


The clojure-lsp stub is a clojure-lsp feature which uses -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


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.[foobar]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 typeBut coming up with that uses way more cognitive load than a simple Delete when the space is unwanted.


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 for some pointers.


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.


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:


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.


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.


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


When using Cider, C-c C-d C-d shows the doc for a given functions. There should be a "See also" section at the bottom of the doc, listing related functions(e.g. "doseq" refers to "for"). However it's gone somehow. Did I accidentally turned it off or something? How do I get it back?


Running M-x cider-version shows me that I'm running version 0.24.0. I have a fairly unmodified cider setup so C-c C-d C-d runs cider-doc. Executing this with the point on, say, doseq pops a buffer with the following contents:


I've dug into the implementation a bit and it appears the cider-doc function relies on functionality from cider/cider-nrepl, which in turn relies on functionality from cider/orchard, which in turn pulls the see-also information from ClojureDocs.


Check your version of cider as well as what version of cider/cider-nrepl and nrepl/nrepl is being used. If any of these are -SNAPSHOT versions, try moving back to a stable version to see if that fixes it. For reference, I'm using CIDER 0.24.0 with cider-jack-in, so it ends up pulling in cider/cider-nrepl 0.24.0 and nrepl/nrepl 0.6.0 on my machine.


But for these editor plugins to connect to the Clojure process something needsto be listening on the other side, accepting connections, allowing theinitiation of a program-to-program dialogue. The most common way to achieve thisis by leveraging the nREPL protocol, an asynchronous message-based networkprotocol for driving interactive development. The application process is startedwith an embedded nREPL server, so that the editor can connect as an nREPLclient.

3a8082e126
Reply all
Reply to author
Forward
0 new messages