This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
@pez I have been following this guide to the https://github.com/PEZ/shadow-w-backend and I'm still getting :missing-nrepl-middleware
. Is there a chance this doesn't work anymore? I've been using the shadow-cljs route. So I'm running in this order.
npx shadow-cljs -d cider/cider-nrepl:0.28.5 clj-repl
(shadow.cljs.devtools.api/watch :app)
(shadow.cljs.devtools.api/nrepl-select :app)
Indeed, it seems that the middleware is not added when starting with clj-repl. Otoh, it’s not needed for that scenario, so maybe that’s why. Use (shadow.cljs.devtools.api/repl :app)
instead.
I thought with the lines I listed, it doesn't use clj-repl
. Or is that wrong?
This might be too advanced for me, but from what I understand, there's starting a fullstack app with a clojure nrepl and then there's starting it with npx shadow-cljs
. I have set :deps true
and so I was hoping I'd be able to remotely start a repl that uses both clj and cljs namespaces.
This works in Calva, but I was trying to do it via the terminal itself so I could understand it better.
So when you said "it seems that the middleware is not added when starting with clj-repl" I thought that meant it wasn't being started with CLJS in mind
I see now though that clj-repl is in the npx command
I meant literally with the command line you were using (and that the README tells us to use).
The reason I made that project was to help with deeper understanding the way you are trying to use it. I will need to fix this error in the README.
To simulate more closely what Calva does. Start the REPL like so:
npx shadow-cljs -d cider/cider-nrepl:0.28.5 watch :app
This will not give you a prompt. You will need to use an nREPL client to get a prompt. So either Calva or a terminal one started something like so:
clojure -Sdeps '{:deps {reply/reply {:mvn/version "0.5.1"}}}' -M -m reply.main --attach `< .shadow-cljs/nrepl.port
`From this prompt the nrepl middleware is available.
(shadow.cljs.devtools.api/nrepl-select :app)
I don’t quite understand why it isn’t when using clj-repl
.Okay interesting. So when we do this, are there two nrepl instances at this point or just one? I noticed that Calva automatically switches between CLJ and CLJS depending on which file I evaluate
It’s complicated 😃 I dunno if you’ve found these? • https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/ • https://www.youtube.com/watch?v=islMjv55cN8
To answer your question: At that particular point you will have one nREPL server. And then on top of that you will have created one nREPL client session (from attaching the reply
nrepl client). This was a clj
nREPL client session to start with, but then we promoted that session to a cljs
session with nrepl-select
. You can exit this session with :cljs/quit
and you will be back with the clj
session. But rather, what I think you want to do, is to create a new clj
session, by connecting with reply
again. Then you will have a cljs
repl prompt in one terminal and a clj
repl prompt the other terminal. This is more like what Calva does (even if Calva is using an nREPL facility to clone the first session, but this is just a technicality with no relevance). When you work with a cljs
file in Calva, it will use the cljs
session. And for clj
files, the same. For cljc
files you get to choose which session should be used, using the toggle command (via the command palette or from the status bar cljc/clj(s)
button).
So, just one nREPL server proper (JVM). Then an nREPL server “proxy” (or whatever we should call this) is started inside the ClojureScript app.
So it's one nrepl server and two clients, a clj and cljs client?
One more thing to note is that shadow-cljs supports builds, on top of the cljs
(n)repl server. This is how you can interpret the “select” semantics.
Yes, one nrepl server and two clients. Though you can also think of that “proxy” as an nrepl server of sorts, for all practical purposes. But, at least there is only one nREPL port. Hmmm, well, as I said, it’s complicated. I might succeed to explain it better in that video with @U02KYBC5WJY, because he’s good at asking the right questions when I start to ramble.
I will continue using Calva but I just have one more question
When i'm in my first client, which is the CLJ client, is there anything special I need to do to read the namespace I'm in? I tried switching to a user namespace where I have some convenient repl functions, and none of those functions are "in scope" if you will
For instance if I defined a "query" function in app.user
, I can switch to it from the clojure repl with (ns app.user)
, but none of the functions are registered
And typing app.user/query
does not resolve in a symbol
This goes for both clients/sessions. You need to either require app.user
, or switch to it using (in-ns …)
, but there is a bit more to switching, because the namespace also needs to be loaded. Let me find you the place to read a bit about this…
Thank you
Calva hides this. Which is nice and easy, but it is really good to know how to do it manually as well, I think.
I'll have to absorb all of this. I have had a few times where I'm evaluating something that has an error in Calva and it knocks me out of my session for some reason. I hear most people just leave their repl up for weeks but I have not been able to do that.
I'd like to know it enough that I can recover from from issues quickly
I don’t think I ever am knocked out of my session… Sounds like the right approach to try understand the mechanics to be able to figure out what to do about it.
> I have had a few times where I'm evaluating something that has an error in Calva and it knocks me out of my session for some reason. I hear most people just leave their repl up for weeks but I have not been able to do that. Does your session / repl process get killed? If not, you should be able to reconnect using the command that's something like "Connect to a running REPL...". Maybe I'm not understanding the issue though.
Usually when this happens my session is killed. I'm not always clear on why it happens, but sometimes it's from a java null pointer exception
I stick to that I think it is good that you learn about the tooling used and how it is used. Though, it won’t help with an issue like java null pointer exceptions bringing down your app. Other than clarify that the REPL is part of your app, and so is the nREPL server.
Bug report: calva improperly code folds the following whitespace style:
(defn foo
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
[])
Expectation: all of foo
would be folded; Actual: foo
is only folded up to the first non-indented lineTo defend the style, this is because some clojure editors (and/or web-based docstring renderers) render docstrings as preformatted whitespace, so adding indentation will add undesired tabs to the docstring
Missionary library also uses a similar dosctring style for similar reasons - see https://github.com/leonoel/missionary/blob/54af74dc5bd3e1e7c0e174a40198a703eaf7d854/src/missionary/core.cljc#L41-L44 - and calva folds it improperly
I will file a github issue if that is the preferred process (is it?)
I thought most tooling had been fixed to support leading two spaces in docstrings these days? Are there still tools out there not getting that right?
(and, for me, Calva indents 3 spaces in docstrings now -- I have no idea how/why it changed or how to "fix" it to use 2 space indents!)
Another use case is ordinary clojure code with a multi-line string that contains, for example, inline markdown, which is indentation-sensitive
I don’t think there’s anything we can do about it. Probably better to file that issue in VS Code.
Ok, thanks, good to know
@U04V70XH6 - do you recall which tools mitigate indented docstrings or have had recent changes to their support of it? Given that this can't be fixed from Calva, and we want Calva users to have a good experience with our libraries, maybe we can revisit the indented docstring strategy that clojure.core uses > I thought most tooling had been fixed to support leading two spaces in docstrings these days? Are there still tools out there not getting that right?
> Another use case is ordinary clojure code with a multi-line string that contains, for example, inline markdown, which is indentation-sensitive Calva will render markdown correctly, disregarding the leading indents, I think.
applications will not
@pez Can we not use a https://code.visualstudio.com/api/references/vscode-api#FoldingRangeProvider to modify how folding works with Clojure?