Fork me on GitHub
#calva
<
2022-03-29
>
wevrem04:03:38

Somehow I’ve managed to get Calva confused about re-frame event and subscription registrations. It doesn’t happen in every file in my project, but in many of them, I’m getting errors about unused bindings and unresolved variables in the function returned by these registrations. How do I fix?

pez04:03:49

Maybe it can be some stale clj-kondo caching? See if it helps to stop clojure-lsp, wipe .clj-kondo/cache, then start clojure-lsp again.

wevrem12:03:52

Hmmm. I tried that and it didn’t help. I found an example within the same file where one reg-event call is okay, and the other reports warnings.

wevrem13:03:09

I did notice, experimenting, that if I use reader ignore form (#) on the event name (for example: #::display-edit) then it suddenly is okay again. Of course, I do need that event name, so I can’t leave it commented out.

pez13:03:45

Could be something to report in #clj-kondo which is what Calva is using for this. See if you can reproduce using the clj-kondo command line tool.

wevrem15:03:43

At the command line clj-kondo reports no errors for the file.

pez15:03:24

Calva reports the clj-kondo version it uses. Is it the same as the one you used on the command line?

wevrem15:03:55

I was just checking that. So on the command line (I installed clj-kondo with brew) it is 2022.03.09. Calva is reporting 2022.03.10-SNAPSHOT. So different versions.

wevrem15:03:46

I tried but didn’t have much success installing 2022.03.10-SNAPSHOT on the command line.

pez16:03:32

Ask in #clj-kondo how to find it. @U04V15CAJ usually makes builds of his tools super accessible.

borkdude17:03:39

👋 This is clj-kondo from master. You can try it like this:

clojure -Sdeps '{:deps {clj-kondo/clj-kondo {:git/url "" :git/sha "2cc9777752d9f54ed91baa4c6ddaa0c2b8812049"}}}' -M -m clj-kondo.main --lint ...

borkdude17:03:25

with the right SHA in place

wevrem20:03:24

So I can’t see a branch or tag for “2022.03.10-SNAPSHOT”. How do I find the SHA for that?

wevrem20:03:06

I’m just looking around in github. I’ll clone it and look more closely…

borkdude21:03:49

you can't :) but you can find the SHA of clojure-lsp and look which clj-kondo version they used

borkdude21:03:59

and then use that exact version

borkdude21:03:51

which clojure-lsp version are you using?

borkdude21:03:46

and is it possible to share this code or a reproduction so I can try it locally?

borkdude21:03:10

there has been a chance to re-frame linting. /cc @U0508JT9N

borkdude21:03:09

Yep, I can repro it like this:

(ns dude (:require [re-frame.core :as re-frame]))

(re-frame/reg-event-fx
 ::setup
 (fn [_ [_ {show-key :show-key}]]
   {:fx [[:dispatch [:path show-key]]]}))

borkdude21:03:22

Will post an issue and fix it.

borkdude21:03:49

For now you could use a #_:clj-kondo/ignore annotation until the next release

wevrem21:03:46

Thanks @U04V15CAJ. Not sure if you still need this info, but this is what Calva prints out regarding versions:

clojure-lsp version used: 2022.03.26-18.47.08
clj-kondo version used: 2022.03.10-SNAPSHOT

borkdude21:03:33

OK, so this is how you can find out which clj-kondo version it is, navigate to the release. Then select the commit. Then select browse files: https://github.com/clojure-lsp/clojure-lsp/tree/323bfabf585f0cc933ce6b1b87809f7a3597eb5d

borkdude21:03:31

And then you can see it's version 2022.03.10-20220323.200333-13

bringe15:03:04

>

clj-kondo version used: 2022.03.10-SNAPSHOT
> And then you can see it’s version 2022.03.10-20220323.200333-13 @UKFSJSM38 Is clojure-lsp reporting an incorrect clj-kondo version that it’s using? Calva gets that info from the serverInfo from clojure-lsp.
function sayClientVersionInfo(serverVersion: string, serverInfo: any) {
  const cljKondoVersion = serverInfo['clj-kondo-version'];
  const calvaSaysChannel = state.outputChannel();
  calvaSaysChannel.appendLine('');
  calvaSaysChannel.appendLine(`clojure-lsp version used: ${serverVersion}`);
  calvaSaysChannel.appendLine(`clj-kondo version used: ${cljKondoVersion}`);
}

borkdude15:03:42

It would be nice if clojure-lsp reported the non-SNAPSHOT version

ericdallo15:03:51

yeah, there is a TODO for that

👍 1
pez15:03:37

Ah, thanks for asking that @U9A1RLFNV. I got confused but thought I just must have missed something. 😃

👍 1
bringe15:03:49

Where’s it getting that snapshot version from? Just curious, as I don’t see it in the deps.edn @U04V15CAJ pointed to.

borkdude15:03:19

clj-kondo has a file called CLJ_KONDO_VERSION on the classpath which has SNAPSHOT on in-between releases

☝️ 1
borkdude15:03:57

I have suggested in the past that lsp should overwrite that file with their fully qualified non-SNAPSHOT version

borkdude15:03:00

when building

ericdallo15:03:07

sounds a little bit tricky, maybe we could make kondo return/have that somehow

borkdude15:03:35

that is not possible since that version you're using is not known before clj-kondo deploys to clojars

😔 1
borkdude15:03:08

but you know that version so you should overwrite the file or have some other means to give Calva that version number :)

ericdallo15:03:43

yeah, sounds a little bit odd to me we need to manually do that

borkdude15:03:09

you would not have to do this manually if you automated it

ericdallo15:03:42

yeah but I mean, we are automating knowing the version of a external lib, IMO the external lib should know its version right?

ericdallo15:03:10

maybe CI could receive that from top, so clj-kondo could know this before

borkdude15:03:15

I already explained why that's not possible

borkdude15:03:45

but once again: if you deploy a SNAPSHOT to clojars, it does get assigned such a "date" suffix

borkdude15:03:59

but you don't know this suffix in advance

borkdude15:03:24

you could also use clj-kondo as a git dependency and report the SHA. Whatever works.

pez15:03:41

> you would not have to do this manually if you automated it 😂

ericdallo15:03:47

I see, still sound to like we are fixing a thing clj-kondo should return somehow, maybe have do not use SNAPSHOT but a commit count or something else

borkdude15:03:40

It's unusual that libraries report their clojars version as part of their artifact. I've already done more than I should have by including this file. You're including this dependency so ultimately you know the version you're using. :P

borkdude15:03:20

We could include the SHA as part of the artifact but this would create a difference with git deps.

ericdallo15:03:19

well, this looks something would need to be fixed on clojars or change the way clj-kondo release snapshots which sounds lot of work So I think we would need to do this on clojure-lsp, feel free anyone who wants to give a try

borkdude15:03:57

Or clojure-lsp should just never use a SNAPSHOT version, that's also an option

👍 1
borkdude15:03:04

Is it possible to include the SHA of a commit in a pre-commit hook? I guess not, so that's a bit hard to get right in all cases

ericdallo15:03:56

yeah, maybe use the date? something like

VERSION=$"$(date -u +"%Y.%m.%d-%H.%M.%S")"

borkdude15:03:44

but that still wouldn't get you the exact commit

borkdude16:03:20

So hopefully you by now understand why I suggested what I suggested a few times already 😂

borkdude16:03:59

Which is: include the same mvn version you're using and overwrite the CLJ_KONDO_VERSION in your jar which you use to build your binary/jar

ericdallo16:03:25

yeah, little bit ugly but easier indeed

borkdude16:03:44

"Not everything is awesome" - Rich Hickey

😂 2
benedek06:03:05

back to the bug in question. it seems that it shows its face only when analysis and linting is done in one go. which makes sense for lsp i guess

borkdude09:03:10

I've been thinking, I could update the CLJ_KONDO_VERSION before lsp wants to do a release so it will be available on clojars, without doing an "official" clj-kondo release perhaps, which includes the binary version and lsp version. I'm willing to try this until I experience problems with this approach.

borkdude09:03:08

@U0508JT9N yes, that is very common. also, when linting says there are unresolved symbols, it's very likely the analysis is plain wrong too with respect to locals

benedek09:03:09

my point is that I *think* this only breaks linting if it is run with re-frame analysis

borkdude09:03:52

yes, could be, but lsp also uses that I think?

borkdude09:03:06

either way, it should not break anything :)

borkdude09:03:36

I think the bug was that analysis happens without the locals being in scope

borkdude09:03:37

maybe the safest is to just get the relevant keyword out, register that and then let clj-kondo analyze the whole expression as always

benedek12:03:24

yeah that or dbl analysing (and some locals not being avail at the re-frame analysis stage). yeah my fix is along those lines, still wip

ericdallo12:03:30

@U04V15CAJ you want to try the CLJ_KONDO_VERSION right now before I release a new lsp version today?

borkdude12:03:34

@UKFSJSM38 I've been thinking also, how does Calva get clojure-lsp's version at startup?

ericdallo12:03:31

from clojure-lsp serverInfo/raw command which clojure-lsp just get from https://github.com/clojure-lsp/clojure-lsp/blob/master/lib/src/clojure_lsp/kondo.clj#L17

borkdude12:03:53

clojure-lsp's version

borkdude12:03:03

@UKFSJSM38 ok, maybe you could just write another file instead of overwriting and use that one

ericdallo12:03:04

maybe, I'll leave it for next release so

ericdallo12:03:30

FYI will use latest clj-kondo master version for this one

borkdude12:03:39

ok, please go ahead

ericdallo17:03:40

Released!

🎉 1
Thierry08:03:28

Did mouseover tooltip stop working without jack-in again?

pez09:03:35

Sounds like clojure-lsp might have either not started or is misconfigured or something. Try stop/start it via the statusbar item (or the Calva commands). If that doesn't help, try stop it and wipe .lsp/ and .clj-kondo/ caches and then start again. If this doesn't help I suspect a config error. When was the last time it worked?

Thierry09:03:32

Ill try that thanks. I havent coded since last week, so a week ago.

pez09:03:08

Thanks for reporting back. I don't think anything has changed during that week that should cause this.

Thierry08:03:34

Or is it me?

🧵 2
bortexz11:03:16

Hi, where should I start looking if I want to have a keybind to wrap some selected code with more code? (e.g wrap in (c/quick-bench <code>))

pez11:03:38

Do you want to call c/quick-bench with some <code>, or do you want a quicker way to type (c/quick-bench <code>)?

bortexz11:03:47

Was looking for the latest, but the former will do too, whatever is easier

pez12:03:57

At least I know how to do the former. 😃 A custom repl command should do the trick https://calva.io/custom-commands/ With a snippet like (c/quick-bench $current-form)

bortexz12:03:32

Didn’t know about custom repl commands, thanks that’s really useful 👌

calva 2
Michael Agres23:03:39

Hi all -- I've gone through the 3 tutorials in VS Code and I'm still wondering: what's the Equivalent of lein new app clojure-noob? I tried Calva: Start a REPL Project and Connect, but that didn't work.

phill00:03:16

lein new app clojure-noob! Then you can go to VS Code, and "open the folder" which contains your new project's project.clj.

1
pez01:03:16

What @U0HG4EHMH says. Even lein new app clojure-noob && code clojure-noob. That said, this is lacking from the material we so far have. We should fix that.

Michael Agres00:03:16

Got it, thanks. I installed Leiningen and got it to work.

Michael Agres00:03:40

Also, couldn't I run those commands in VS Code's Terminal after I open my project folder? It will be in the proper folder anyway.