Fork me on GitHub
#calva
<
2021-12-06
>
JR01:12:07

When I add an end-of-line comment, I’m sort of used to the cursor hopping to the comment-column. Is there a way to do this in calva? I looked at cljfmt but didn’t see anything obvious. I had this behavior in emacs years ago, and in Cursive recently. So if I type

(async/>!! tea-channel :cup-of-tea-5) ;
It would turn into
(async/>!! tea-channel :cup-of-tea-5)              ; 
with the semicolon on a predefined column, out of the way. The comments would line up nicely in the same column. Not a big deal, just wondering if I missed something.

seancorfield03:12:01

It's funny, that was always something I hated about Emacs doing that and I much prefer Calva's approach of putting the end of line comment exactly where I type it!

JR14:12:21

There is something to be said about that. What I’d really prefer is something like M-x ; to add an end-of-line (“margin”) comment, so it wouldn’t jump over all the time. It’s not really a high priority though, even for me I tend to have comments at the top of blocks. While learning though, I use the end-of-line comments as notes to myself.

bringe20:12:45

There is no way to do that in Calva, that I’m aware.

JR01:12:42

I was exploring the https://github.com/unclebob/spacewar and found that F12 (Goto Definition) lists two definition points for some functions. There are two points are for the same function, one is the line above the function and the other is line with the function defn itself. So far I’ve only seen it in this codebase, so it could be something there, like using .cljc. Or is this something I’ve done wrong?

JR01:12:13

Here I hit F12 on the (add-messages) call and got two add-messages listed, but they’re both the same function.

JR01:12:06

You’d have to be on add-messages on core.clj:291. It happens with lots of functions, but not all of them.

bringe20:12:13

Do you have a repl connected when you go to definition?

bringe20:12:25

If not, then that is clojure-lsp returning results, I think.

JR23:12:51

Interesting!

JR23:12:12

I just opened the project without doing anything to start a repl. I saw the double method problem. Then I looked for processes starting with “lein”, I found one (quite long path) and killed it. The double method problem went away! Then I started a repl myself, and the problem still isn’t there.

JR23:12:34

So maybe this is indeed a repl that calva uses? Is that what you mean by clojure-lsp?

JR23:12:54

In any case, I’ll try to cut it down to a reproducible test case

JR23:12:58

It does say

Calva is utilizing cider-nrepl and clojure-lsp to create this VS Code experience.
  nREPL dependencies configured:
    nrepl: 0.8.3
    cider-nrepl: 0.26.0
    cider/piggieback: 0.5.2
 clojure-lsp version configured: latest
in the Output window when starting.

JR00:12:42

I changed the file into a .clj (from .cljc) and F12 works now, without other changes. Even with the behind-the-scenes repl running. This makes calva work amazingly well, not as clunky as before. If I rename the file back to .cljc the problem comes back. It doesn’t happen at first, only after I see the “Connected to nREPL.” message popup. So maybe this is something to do with clojure-lsp and .cljc files?

JR01:12:33

@U9A1RLFNV Got it, I can easily reproduce it with this small archive: just one project.clj and one core.clj file. Just open it, wait for all of calva to be ready, open core.clj, stand on (doubleme) and hit F12. The popup will show up.

bringe01:12:41

Hmm I can’t reproduce it. I just tried with that project and my cursor goes to the definition of doubleme and no popup appears.

bringe01:12:51

You are not starting a repl, right? What do you mean by “wait for all of Calva to be ready”? Do you mean including waiting for clojure-lsp to finish starting (a startup message appears in the status bar while it’s starting)?

bringe01:12:39

What’s your OS?

bringe03:12:51

Actually, what might be best to know is what clojure-lsp is returning. Info on how to see the messages is here: https://calva.io/clojure-lsp/#viewing-the-logs-between-the-client-and-server.

bringe03:12:58

If you want, with the message logging enabled, reproduce the issue and then copy the logs and paste them into a new issue on GitHub, explaining the problem there too. We can continue troubleshooting there.

JR16:12:57

“wait for all of Calva to be ready” = I noticed three phases: 1) nothing happens when I hit F12, 2) when I hit F12 it goes directly to the function without a popup, and then 3) eventually a popup gets in the way when I hit F12. The whole process takes maybe 3 minutes on my old system

👍 1
JR16:12:33

OS = OS X, Big Sur

JR16:12:57

I’ll check into viewing the logs and create an issue

👍 1
JR14:12:59

Doh! Again! I had the Clojure extension installed.

bringe17:12:52

Aha! Glad you found the issue!

orestis08:12:26

Does Calva take over the Match Bracket functionality of vscode? I've put the following in settings.json

"workbench.colorCustomizations": {
      "editorBracketMatch.background": "#f008",
      "editorBracketMatch.border": "#f00"
    },
    
And I see the new colors in say a JSON file, but in CLJ files I see something more subtle.

pez08:12:51

Maybe you can get away with setting calva.highlight.matchBracketStyle to null (I haven’t tried). See for the settings available: https://calva.io/highlight/

orestis08:12:03

Doesn't seem to work. No worries, no big deal, if I ahve some time I might try to submit a patch 🙂

pez09:12:38

It’s probably that bracket matching is made unconditionally. We should add a setting for that, I think.

Michael W14:12:25

I have added a .clj-kondo/config.edn to my repo, but calva does not seem to read it for linting. The forms I added to be linted as def or defn are still showing problems in calva. Is there a special way to get calva to read my clj-kondo config?

pez14:12:27

You might need to reload the VS Code window, I’m not sure how dynamic this is. Do you know @U9A1RLFNV, @UKFSJSM38?)

borkdude14:12:31

Probably the deps need to be re-scanned

borkdude14:12:44

if your lint-as applies to an external library

Michael W14:12:38

Restarting everything from scratch I still see lint problems I would expect to be resolved from my config. Any way to see output from clojure-lsp on what config it is using for clj-kondo?

borkdude14:12:11

You can also try to lint from the command line to see if that works

ericdallo14:12:14

yes, use server-info command, there is a vscode command for that

ericdallo14:12:40

changing kondo config for your project code should work, it's not needed a restart

Michael W14:12:14

I have defsc-form set to lint as defn, and that seems to work, I don't have the line under the name, but I would expect it to see the AccountForm there as a resolved symbol, since it should think it's a function name, right?

ericdallo14:12:09

yes, sounds lke a wrong kondo config, could you paster you config?

Michael W14:12:11

{:lint-as                                                                                                               
 {mount.core/defstate                                      clojure.core/def                                             
  com.fulcrologic.fulcro.components/defsc                  clojure.core/defn                                            
  com.fulcrologic.rad.form/defsc-form                      clojure.core/defn                                            
  com.fulcrologic.rad.report/defsc-report                  clojure.core/defn                                            
  com.fulcrologic.fulcro.routing.dynamic-routing/defrouter clojure.core/defn                                            
  com.fulcrologic.rad.authorization/defauthenticator       clojure.core/defn}} 

Michael W14:12:28

that's in .clj-kondo/config.edn in the repo.

borkdude14:12:32

you should receive this automatically into your .clj-kondo folder

borkdude14:12:39

if you're using the newest fulcro version

borkdude14:12:01

and then add :config-paths ["com.fulcrologic/fulcro"] to your config

☝️ 1
borkdude14:12:04

can you show what is in your .clj-kondo folder with:

ls -la .clj-kondo

ericdallo14:12:20

@U04V15CAJ maybe this is a reason to auto consider imported config paths right? we were talking about that some other day

Michael W14:12:44

λ tree
.
├── com.fulcrologic
│   └── fulcro
│       ├── com
│       │   └── fulcrologic
│       │       └── fulcro
│       │           └── clj_kondo_hooks.clj
│       └── config.edn
├── com.wsscode
│   ├── async
│   │   └── config.edn
│   └── pathom
│       └── config.edn
└── config.edn

Michael W14:12:08

I've just set :config-paths and am restarting everything to see if it makes a difference

borkdude14:12:08

yes, so adding the above to your config should fix all linting issues with fulcro

Michael W14:12:49

Still the same thing, AccountForm from my screenshot still shows as an unresolved symbol.

Michael W14:12:20

λ cat .clj-kondo/config.edn
{:config-paths ["com.fulcrologic/fulcro"]}

borkdude14:12:02

@U0522TWDA Do you know what's going on here?

borkdude14:12:21

is that com.fulcrologic.rad.form/defsc-form?

Michael W14:12:39

It's also happening the same for com.fulcrologic.fulcro.components.defsc a bit further down from that screenshot.

borkdude14:12:04

then somehow your config isn't being used. you can make a repro repository for this problem

Jakub Holý (HolyJak)14:12:36

that is weird because it works just fine on other projects such as https://github.com/holyjak/minimalist-fulcro-template-backendless - could you try that one? Also, does it also fail when linting from CLI? Running clj-kondo --lint . in this repos gives some warnings about unsued imports but that is all. Defsc works fine

Jakub Holý (HolyJak)14:12:46

So I would suggest: 1. Try running kondo from the CLI as I did above; if that still errors => 2. Check out the backendless repo and run kondo from CLI there

Michael W14:12:13

Running from the CLI seems to work ok, I am not getting the warning about AccountForm as in my screenshot.

🎉 1
ericdallo14:12:40

BTW @UAB2NMK25 instead of restarting you can do any change to the file to clojure-lsp re-lint that file with kondo after you change the kondo config, insted of restarting it.

Michael W14:12:06

So it's like the calva/clojure-lsp is not reading my config.edn

borkdude14:12:07

yeah, do you do need to make a change to a file to trigger linting

ericdallo14:12:43

Also, make sure you are using a correct project root

1
borkdude14:12:48

Have you opened the correct directory in VSCode and not a parent directory of your project? This is a common problem

Michael W14:12:14

Yeah I start it with 'code .' from the top level directory of the repo

borkdude14:12:30

and .clj-kondo is also in the top level dir of the repo?

borkdude14:12:57

I'm running out of ideas but you can still follow Jakub's suggestion of trying the demo repo

ericdallo14:12:24

@UAB2NMK25 can you make a simple repro where we can see and debug the code?

Michael W14:12:30

Yeah I think I can just put this entire repo up, I'm barely into it but my intention is to release under MIT.

borkdude14:12:04

just release without a README, then nobody will use it ;)

😂 3
Michael W14:12:06

I can't do much with it till tonight, I can't work on it during work hours, I'll get a repo up tonight and update this thread.

Michael W14:12:33

The minimalist-fulcro-template-backendless repo lints correctly.

Michael W17:12:38

Ok so it appears this template I used as a base puts everything under src/dev and src/main. If I add a config.edn to src/main/.clj-kondo it is picked up for the files under src/main. With that extra main directory it seems clojure-lsp is restricting clj-kondo in some way so it does not use the config from the base of the repo.

ericdallo17:12:59

yes, I think we could improve that on clojure-lsp side, but for now it's only possible having a config.edn on the project-root

Michael W17:12:28

That is the template I used, and when I load up a clone it is doing the same thing for me here.

ericdallo17:12:12

@UAB2NMK25 I can't see any .clj-kondo/config.edn on this template with the :config-paths @U04V15CAJ mentioned

Michael W17:12:34

Yes I added those in .clj-kondo/config.edn

ericdallo17:12:54

IMO we should add to this template as well c/c @U0522TWDA

👍 1
Michael W17:12:57

If I add a :lint-as to src/main/.clj-kondo/config.edn then it works, but anything in main does not get the clj-kondo config from the root of the repo.

Michael W17:12:52

On my app I swapped datomic for xtdb and have that working well, everything is great except the linting.

ericdallo17:12:54

what is the project root? it should be on <repo>/.clj-kondo/config.edn

borkdude17:12:59

why do you add src/main/.clj-kondo?

Michael W17:12:28

I just tried it to see if it solved the problem

Michael W17:12:35

How do I see the project root?

Michael W17:12:23

I opened vscode in the root of the repo, the root of the repo is the top of the tree in my explorer

Michael W17:12:34

I think clojure-lsp added src/main/.clj-kondo, that directory existed and I just added the config.edn with a lint for defstate to test.

ericdallo17:12:45

so it's correct, now the config should go on <repo>/.clj-kondo/config.edn

ericdallo17:12:14

if clojure-lsp added that folder, is because it was setted as project root

ericdallo17:12:47

clojure-lsp creates a .clj-kondo folder if not exists in the specified project-root sent by the client (calva), that sends the root opened on vscode

Michael W17:12:10

Ok so at some point I must have opened vscodium in that directory

Michael W17:12:31

I deleted src/main/.clj-kondo and src/main/.lsp and it's working now.

👍 1
ericdallo17:12:22

I can't see why it was not working because of the presence of those folders on src/main :thinking_face:

Michael W17:12:39

Yeah that's tricky

Michael W17:12:03

I just made sure I only have 1 .lsp and 1 .clj-kondo in the whole repo tree and it's working now.

pez17:12:54

Currently, Calva does not explicitly send the root to clojure-lsp. But maybe we should. We keep a notion of projectRoot that is mostly used for the REPL things. I’m not sure if this is the right root to use. As we fall back on the folder root we would anyway be sending src/main if vscode was opened there.

Michael W17:12:45

It's really easy to open vscode in the wrong dir from a terminal and if that stops the config from working it's confusing.

Samuel McHugh15:12:40

Looks like there has been a lot of discussion recently. Just wanted to heads up that for me the latest release of Calva doesn’t automatically create balanced parens. That is to say that typing ( produces ( whereas before it would have produced () .

pez15:12:14

It’s probably your settings that was borked by the previous release. Check the User settings json file and remove anything like

"editor.formatOnType"
        "editor.autoClosingBrackets"
        "editor.autoClosingOvertype"
        "editor.formatOnPaste"
From the [clojure] scope. That should give you back the defaults.

Samuel McHugh15:12:16

that did it thanks!

🙏 1
Pepijn de Vos10:12:30

Huh what happened?