Fork me on GitHub
#clj-kondo
<
2021-11-23
>
chrisn18:11:10

I would like to add clj-kondo support to dtype-next. Is the method used in https://github.com/clj-python/libpython-clj/pull/135/files the best way to add it the the dtype-next jar and thus enabling support for many downstream projects?

borkdude18:11:58

@chris441 yes. additionally you can add your own exported config to your own .clj-kondo/config.edn using :config-paths ["../resources/clj-kondo.exports/org/lib"]

borkdude18:11:38

and additionally there is now also a :macroexpand hook which allows you to write a macro in the same fashion as clojure - this is easier than writing a hook but gives less precise locations of errors

chrisn18:11:04

What I would like most is for tablecloth, http://metamorph.ml, http://tech.ml.dataset, etc. to all get automatic support for clj-kondo. I am specifically trying to avoid a pathway that is user-specific but instead update just the dtype-next jar and have the downstream systems work automatically. The end hope is to get auto-complete working for those systems in clojure-lsp and thus transitively in Calva.

ericdallo20:11:23

@chris441 I already did some of those configs on upstreams project so I can help you if you want

ericdallo20:11:49

IMO providing the hook on the upstream package is the best way to make downstream just work with minimal config

chrisn02:11:17

That is great to know - I appreciate the offer and I will be taking you up on that :-)

danielcompton19:11:02

Is there a way for clj-kondo to lint for incorrect kwargs usage? ClojureScript used to be more lenient in what it accepted but now matches Clojure https://clojurians.slack.com/archives/C07UQ678E/p1637632148130100

borkdude20:11:17

@danielcompton See my reaction over there.

seancorfield22:11:47

@borkdude Is anything needed to get clj-kondo to recognize the new core functions in Clojure 1.11 Alpha 3? Is it just a matter of deleting the caches and having LSP/clj-kondo regenerate them?

borkdude22:11:05

if you're lucky, yes

😂 1
seancorfield22:11:17

Thanks. Will try that and let you know 🙂

borkdude22:11:46

@seancorfield Actually I think just changing your deps.edn and restarting your editor should trigger lsp to rescan the deps. But @ericdallo can probably verify this.

seancorfield22:11:26

Well, it did rebuild the .caches etc, but clj-kondo still thinks random-uuid is unknown.

borkdude22:11:14

hmm, is there another clojure version on your classpath that overrides it?

seancorfield22:11:40

Not as far as I know.

borkdude22:11:52

I'll try it

seancorfield22:11:17

I checked the classpath that LSP uses:

/Users/sean/.m2/repository/org/clojure/clojure/1.11.0-alpha3/clojure-1.11.0-alpha3.jar
is the only Clojure on it.

seancorfield22:11:18

LSP config:

{:project-specs [{:project-path "clojure/deps.edn"
                  :classpath-cmd ["./.lsp/classpath.sh"]}]}
and that script is
#!/bin/sh
cd clojure && clojure -Spath -M:build:dev:everything:runner:test

borkdude22:11:14

When I lint clojure 1.11.0-alpha3 myself and use vanilla clj-kondo without LSP it works.

borkdude22:11:21

What does clojure -Spath -M:build:dev:everything:runner:test return?

borkdude22:11:41

Only clojure 11?

borkdude22:11:32

@ericdallo Does LSP skip linting clojure itself?

borkdude23:11:02

@seancorfield can you try ls -la .clj-kondo/.cache/2021.10.20-SNAPSHOT/clj/clojure.core.transit.json in your project? This should contain the cached analysis of clojure.core. The clj-kondo version might differ.

borkdude23:11:38

If that transit file is not there, then clojure.core wasn't analyzed

seancorfield23:11:52

-rw-r--r-- 1 sean admin 74976 Nov 23 14:42 .clj-kondo/.cache/2021.10.20-SNAPSHOT/clj/clojure.core.transit.json

seancorfield23:11:13

(at the top of the project, but the .clj-kondo in the clojure folder of the project does not have it.

seancorfield23:11:34

(this was my weird issue with having two .clj-kondo folders in the project)

seancorfield23:11:15

I could make ./clojure/.clj-kondo a symlink up to ./.clj-kondo

borkdude23:11:19

then it seems lsp picks the wrong root

borkdude23:11:46

lsp looks from the working directory upwards, not downwards

seancorfield23:11:50

LSP has the correct root. But clj-kondo seems to run against the directory the REPL is starting against.

borkdude23:11:28

how are you opening this project in vscode?

seancorfield23:11:53

It's a workspace with two folders wsmain and worldsingles. The Clojure code is in wsmain/clojure.

borkdude23:11:03

I think you should open the clojure directory in vscode, Calva is quite sensitive to what directory you open

seancorfield23:11:35

No, wsmain is the project folder. That's where git is rooted.

borkdude23:11:01

then why does your bash script cd into another directory?

seancorfield23:11:15

Because that's where deps.edn is.

borkdude23:11:46

yes. so your working directory is wsmain, but your actual clojure project is in wsmain/clojure. you should open wsmain/clojure in vscode I think, to set the correct working directory

seancorfield23:11:47

The repo has build, clojure, documentation etc.

seancorfield23:11:16

No. wsmain is the folder I need to have open in VS Code. Otherwise it screws up git behavior.

seancorfield23:11:53

I'll just use a symlink for .clj-kondo. I think that solves it.

borkdude23:11:58

this seems to be a downstream issue. clj-kondo behaves similar in emacs like you want it. but vscode / calva /lsp does not agree with this. :)

borkdude23:11:04

you can also try the standalone clj-kondo plugin for vscode which works similar to the one in emacs I think

borkdude23:11:09

and then disable lsp diagnostics

borkdude23:11:27

but it doesn't automatically lint deps. you should do that from the command line with the same version

borkdude23:11:49

perhaps this can be fixed with calva/lsp. what clj-kondo does by default is, it tries to resolve the config directory from the file you're editing. but lsp is passing the config dir explicitly which overrides this and if it picks the wrong one then it doesn't work as you expect.

seancorfield23:11:52

Using a symlink "fixes" the problem. I can live with that.

ericdallo23:11:32

I didn't understand exactly what clojure-lsp is doing wrong, LMK if need help debugging that

seancorfield23:11:08

I'll try to explain: my repo root is wsmain LSP creates .lsp there (as expected for Calva usage). My REPL is started in wsmain/clojure. The classpath script for LSP cd's into clojure to run clojure -Spath ... because that's where deps.edn is.

seancorfield23:11:32

However, I end up with TWO .clj-kondo folders. One in wsmain and one in wsmain/clojure.

seancorfield23:11:14

Both of them get the exported configs from dependencies. Both of them get a .cache folder -- but the contents seem to be different.

seancorfield23:11:38

I don't know why the clojure/.clj-kondo folder is created.

seancorfield23:11:14

I thought the setup with Calva was such that it only ran clj-kondo via LSP and so I expected that wsmain/.clj-kondo would be the only folder created.

ericdallo23:11:55

I'd suggest not having your root not on the same folder of your deps.edn but I think you have your reasons, you probably need to setup more than just project-specs if you are doing that

ericdallo23:11:03

like :source-paths

ericdallo23:11:52

anyway, it doesn't make sense create a clojure/.clj-kondo indeed since clojure-lsp creates that from the passed project-root-uri that calvas sends on the initialize request

seancorfield23:11:21

Not sure what :source-paths you are referring to?

seancorfield23:11:42

.lsp/config.edn is

{:project-specs [{:project-path "clojure/deps.edn"
                  :classpath-cmd ["./.lsp/classpath.sh"]}]}

ericdallo23:11:25

since the source-paths discovery will not work because there is no deps.edn on the project-root, you should specify manually it with the :source-paths lsp settings

seancorfield23:11:33

This is a monorepo with dozens and dozens of subprojects that are :local/root deps.

seancorfield23:11:59

The classpath will contain all those directories tho'

ericdallo23:11:40

yeah, the classpath thing should work, but other clojure-lsp features like rename namespaces and some others that rely on correctly configured source-paths won't

seancorfield23:11:53

I don't care about refactorings.

ericdallo23:11:42

alright, so it should work, not sure why is creating the clojure/.clj-kondo dir, are you sure there are no extra plugins anything?

ericdallo23:11:35

This is clojure-lsp code that creates the kondo dir, it only checks the project-root-uri sent by the client (calva): https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/crawler.clj#L176-L185

seancorfield23:11:40

Just Calva and Clover and I'm pretty sure the latter doesn't do anything with clj-kondo?

ericdallo23:11:56

yeah I think so

ericdallo23:11:50

well, clojure-lsp logs when it's creating the kondo dir, maybe you can search there

ericdallo23:11:15

search for "creating for necessary clj-kondo analysis..."

ericdallo23:11:28

I think there is a calva command to get clojure-lsp logs

ericdallo23:11:52

Calva Diagnostics: Open Clojure-lsp Log File

seancorfield23:11:22

Looks like I'd need to do a clean restart without those folders to see what it is doing? That's going to be too disruptive right now but I'll try to set aside some time for that tomorrow.

pez06:11:09

Not sure I follow fully, but I'll try to see what Calva gives to clojure-lsp in this scenario.

pez08:11:04

I can’t see that Calva configures any project root for clojure-lsp. Should we?

borkdude08:11:08

@U0ETXRFEW It has to do with the concept of workspace / working directory. I think Calva and LSP have just one concept of what the project root is.

borkdude08:11:32

So if you work inside a sub-directory in your workspace the project root is still the root directory.

pez08:11:09

Calva has a concept of project root that is used for various things. This is currently determined from the current file and then upwards looking for a project file. I have on my todo to revisit this to better support monorepos, polylith, etc. I don’t see that we send this info to clojure-lsp, though. And from what I take from this thread, it would risk mess things up if we did? Maybe VS Code is giving clojure-lsp some project root automagically


borkdude08:11:47

ok, then we should ask @ericdallo.

borkdude08:11:22

This is how the clj-kondo LSP plugin does it: for every file that you edit, regardless of what is your working directory, it looks up from the path of that file for the config directory, https://github.com/clj-kondo/clj-kondo.lsp/blob/b1097c318c0d51b3c7e45192005c0f7d8765cd68/server/src/clj_kondo/lsp_server/impl/server.clj#L130

borkdude08:11:43

This approach should work for Sean's situation

ericdallo12:11:36

The project-root-uri is a mandatory string that clients should send, if calva is not sending manually then vscode is, probably it uses the current folder root opened or something. It's possible to get that in LSP logs like I mentioned above

borkdude12:11:40

@ericdallo the clj-kondo.lsp plugin doesn't care about it though. it just uses the file path to scan upwards for a config

borkdude12:11:11

EDIT: I meant clj-kondo.lsp, not clojure.lsp.

👍 1
pez12:11:23

I think it makes sense that clojure-lsp does what clj-kondo.lsp does for this. Calva should probably share what it thinks is the project root anyway, but it seems to be a bit unrelated?

ericdallo12:11:51

We could improve that on clojure-lsp I think, but that would work for single file edits only, not full project lint on startup as we pass project sources to kondo

ericdallo12:11:02

But it'd solve most issues I think

ericdallo12:11:13

Actually, this is the first one I see

borkdude12:11:32

I wonder what the reason is that Sean doesn't just open the sub-project directory. He mentioned issues with git that way

ericdallo12:11:40

yeah, I agree clojure-lsp could have better mono-repo support, I improved that for polylith and other mono-repos, but threre are lot of cases

pez12:11:39

I know that feeling!

bringe23:11:37

Just FYI, you can see what root path is being sent from VS Code / Calva in the Clojure Language Client output channel, if the setting clojure.trace.server is set to verbose . The info is in the initialization message.

👍 1
seancorfield19:11:40

That's what showed up with verbose tracing and a fresh setup (no .clj-kondo folder)

borkdude19:11:11

for context: your .clj-kondo folder is in wsmain/clojure/.clj-kondo, correct?

seancorfield19:11:26

No, it's in wsmain/.clj-kondo

seancorfield19:11:39

I've removed the wsmain/clojure/.clj-kondo folder.

seancorfield19:11:59

LSP creates it in the root of the tree.

seancorfield19:11:32

I'll keep an eye out for wsmain/clojure/.clj-kondo appearing -- that was what broke things before, but as long as that doesn't get created I think this setup will work just fine.

borkdude19:11:55

LSP might create it if you open VSCode at wsmain/clojure

borkdude19:11:36

not sure though.

seancorfield19:11:40

Will report back if I see that reappear. For a while, it was randomly reappearing, while I was using VS Code, but I don't know what triggered it.