This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-23
Channels
- # announcements (66)
- # babashka (41)
- # beginners (93)
- # calva (10)
- # cider (2)
- # clj-kondo (112)
- # cljs-dev (6)
- # cljsrn (1)
- # clojure (44)
- # clojure-dev (10)
- # clojure-europe (35)
- # clojure-italy (15)
- # clojure-nl (3)
- # clojure-uk (2)
- # clojurescript (38)
- # conjure (1)
- # datalevin (1)
- # datomic (16)
- # deps-new (4)
- # events (7)
- # figwheel-main (1)
- # fulcro (59)
- # graalvm (21)
- # integrant (3)
- # introduce-yourself (8)
- # jobs-discuss (2)
- # malli (23)
- # membrane (11)
- # membrane-term (2)
- # missionary (17)
- # off-topic (7)
- # pathom (23)
- # pedestal (6)
- # polylith (7)
- # portal (25)
- # releases (1)
- # remote-jobs (3)
- # reveal (5)
- # shadow-cljs (43)
- # spacemacs (7)
- # sql (18)
- # tools-deps (33)
- # vim (10)
- # xtdb (36)
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?
@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"]
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
That info is available on this page: https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md
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.
@chris441 I already did some of those configs on upstreams project so I can help you if you want
IMO providing the hook on the upstream package is the best way to make downstream just work with minimal config
That is great to know - I appreciate the offer and I will be taking you up on that :-)
:) Some libs I added clj-kondo hooks and custom config that worked for downstreams: https://github.com/nubank/state-flow/blob/master/resources/clj-kondo.exports/nubank/state-flow/config.edn https://github.com/marick/Midje/tree/master/test-resources/clj-kondo.exports/marick/midje
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
@danielcompton See my reaction over there.
@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?
Thanks. Will try that and let you know đ
@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.
It did not.
Well, it did rebuild the .caches etc, but clj-kondo still thinks random-uuid
is unknown.
Not as far as I know.
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.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
When I lint clojure 1.11.0-alpha3 myself and use vanilla clj-kondo without LSP it works.
@ericdallo Does LSP skip linting clojure itself?
@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.
-rw-r--r-- 1 sean admin 74976 Nov 23 14:42 .clj-kondo/.cache/2021.10.20-SNAPSHOT/clj/clojure.core.transit.json
(at the top of the project, but the .clj-kondo
in the clojure
folder of the project does not have it.
(this was my weird issue with having two .clj-kondo
folders in the project)
I could make ./clojure/.clj-kondo
a symlink up to ./.clj-kondo
LSP has the correct root. But clj-kondo seems to run against the directory the REPL is starting against.
It's a workspace with two folders wsmain
and worldsingles
. The Clojure code is in wsmain/clojure
.
I think you should open the clojure
directory in vscode, Calva is quite sensitive to what directory you open
No, wsmain
is the project folder. That's where git is rooted.
Because that's where deps.edn
is.
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
The repo has build
, clojure
, documentation
etc.
No. wsmain
is the folder I need to have open in VS Code. Otherwise it screws up git behavior.
I'll just use a symlink for .clj-kondo
. I think that solves it.
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. :)
you can also try the standalone clj-kondo plugin for vscode which works similar to the one in emacs I think
but it doesn't automatically lint deps. you should do that from the command line with the same version
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.
Using a symlink "fixes" the problem. I can live with that.
I didn't understand exactly what clojure-lsp is doing wrong, LMK if need help debugging that
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.
However, I end up with TWO .clj-kondo
folders. One in wsmain
and one in wsmain/clojure
.
Both of them get the exported configs from dependencies. Both of them get a .cache
folder -- but the contents seem to be different.
I don't know why the clojure/.clj-kondo
folder is created.
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.
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
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
Not sure what :source-paths
you are referring to?
.lsp/config.edn
is
{:project-specs [{:project-path "clojure/deps.edn"
:classpath-cmd ["./.lsp/classpath.sh"]}]}
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
This is a monorepo with dozens and dozens of subprojects that are :local/root
deps.
The classpath will contain all those directories tho'
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
I don't care about refactorings.
Only linting.
alright, so it should work, not sure why is creating the clojure/.clj-kondo dir, are you sure there are no extra plugins anything?
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
Just Calva and Clover and I'm pretty sure the latter doesn't do anything with clj-kondo
?
well, clojure-lsp logs when it's creating the kondo dir, maybe you can search there
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.
Not sure I follow fully, but I'll try to see what Calva gives to clojure-lsp in this scenario.
@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.
So if you work inside a sub-directory in your workspace the project root is still the root directory.
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âŠ
ok, then we should ask @ericdallo.
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
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
@ericdallo the clj-kondo.lsp plugin doesn't care about it though. it just uses the file path to scan upwards for a config
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?
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
I wonder what the reason is that Sean doesn't just open the sub-project directory. He mentioned issues with git that way
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
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.
That's what showed up with verbose
tracing and a fresh setup (no .clj-kondo
folder)
No, it's in wsmain/.clj-kondo
I've removed the wsmain/clojure/.clj-kondo
folder.
LSP creates it in the root of the tree.
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.
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.