Fork me on GitHub
#calva
<
2023-06-24
>
Dallas Surewood15:06:27

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

pez15:06:42

Hi! Do you get this even with the example project you link to?

pez15:06:31

Yes, I get that too. Let me have a closer look.

pez15:06:14

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.

Dallas Surewood15:06:21

I thought with the lines I listed, it doesn't use clj-repl. Or is that wrong?

pez15:06:58

Sorry, not following… What do you mean doesn’t use clj-repl?

Dallas Surewood15:06:28

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.

Dallas Surewood15:06:46

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

Dallas Surewood15:06:16

I see now though that clj-repl is in the npx command

pez15:06:26

I meant literally with the command line you were using (and that the README tells us to use).

pez15:06:16

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.

pez15:06:17

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
`

pez15:06:59

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.

Dallas Surewood15:06:03

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

pez16:06:53

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

pez16:06:10

So, just one nREPL server proper (JVM). Then an nREPL server “proxy” (or whatever we should call this) is started inside the ClojureScript app.

Dallas Surewood16:06:18

So it's one nrepl server and two clients, a clj and cljs client?

pez16:06:24

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.

pez16:06:24

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.

Dallas Surewood16:06:41

I will take a look at that, thank you!

🙏 2
Dallas Surewood16:06:53

I will continue using Calva but I just have one more question

pez16:06:08

You have free credits, Dallas. 😃

😀 2
Dallas Surewood16:06:57

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

Dallas Surewood16:06:55

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

Dallas Surewood16:06:06

And typing app.user/query does not resolve in a symbol

pez16:06:26

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…

pez16:06:48

Calva hides this. Which is nice and easy, but it is really good to know how to do it manually as well, I think.

pez16:06:01

At the bottom of that page is an important section How things can go wrong.

Dallas Surewood16:06:05

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.

Dallas Surewood16:06:20

I'd like to know it enough that I can recover from from issues quickly

pez16:06:49

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.

bringe22:06:05

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

Dallas Surewood23:06:09

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

👌 2
pez13:06:24

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.

Dustin Getz21:06:38

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 line

Dustin Getz21:06:46

To 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

Dustin Getz21:06:00

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

Dustin Getz21:06:08

I will file a github issue if that is the preferred process (is it?)

seancorfield21:06:39

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?

seancorfield21:06:27

(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!)

Dustin Getz21:06:37

Another use case is ordinary clojure code with a multi-line string that contains, for example, inline markdown, which is indentation-sensitive

2
bringe22:06:08

An issue is welcome. Thanks for reporting it.

pez07:06:15

I don’t think there’s anything we can do about it. Probably better to file that issue in VS Code.

👍 2
Dustin Getz13:06:12

Ok, thanks, good to know

Dustin Getz13:06:01

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

pez13:06:14

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

2
Dustin Getz13:06:39

applications will not

pez17:06:17

Sounds good! I wasn’t aware.

bringe02:06:11

Yeah I didn't know about that until yesterday before I replied 😄