clj-kondo

https://github.com/clj-kondo/clj-kondo
seancorfield 2021-06-22T00:07:00.251100Z

Does clj-kondo do anything with :arglists metadata or does it use the underlying argument declarations? (this is in the context of Eastwood trying to check calls using :arglists which I recall having problems with in the past)

seancorfield 2021-06-22T00:12:58.252200Z

(and I guess the same Q applied to LSP @ericdallo? My quick experimentation suggests that both kondo and lsp rely on the actual argument declarations and ignore the :arglists metadata?)

ericdallo 2021-06-22T00:19:10.253700Z

clojure-lsp totally relies on clj-kondo https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md, in this case :arglist-strs from https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md#data. I'm not sure if clj-kondo fill it with that :arglists metadata

borkdude 2021-06-22T07:52:42.255800Z

Feel free to raise an issue about what should change (and optionally a PR)

seancorfield 2021-06-22T00:33:54.254100Z

Thanks @ericdallo — as far as I can tell, clj-kondo ignores the :arglists metadata, based on limited experimentation. The downside is that “show hover” in Calva seems to come from LSP which therefore shows the actual argument lists rather than any doc-friendly :arglists that doc would show — but at least the linting is done correctly, which is my main concern.

ericdallo 2021-06-22T00:38:20.254300Z

I see, yes, you are right, I confirmed that show hover for ns clojure.core macro shows [name & references] instead of the arglists metadata '([name docstring? attr-map? references*])

ericdallo 2021-06-22T00:39:45.254500Z

this is the analysis data returned from clj-kondo for the ns macro:

{:end-row 5809,
  :name-end-col 13,
  :name-end-row 5753,
  :name-row 5753,
  :added "1.0",
  :ns clojure.core,
  :name ns,
  :defined-by clojure.core/defmacro,
  :filename
  "/home/greg/.emacs.d/.local/etc/workspace/.cache/clojure.core.clj",
  :macro true,
  :col 1,
  :name-col 11,
  :end-col 71,
  :arglist-strs ["[name & references]"],
  :varargs-min-arity 1,
  :doc
  "Sets *ns* to the namespace named by name (unevaluated), creating it\n  if needed.  references can be zero or more of: (:refer-clojure ...)\n  (:require ...) (:use ...) (:import ...) (:load ...) (:gen-class)\n  with the syntax of refer-clojure/require/use/import/load/gen-class\n  respectively, except the arguments are unevaluated and need not be\n  quoted. (:gen-class ...), when supplied, defaults to :name\n  corresponding to the ns name, :main true, :impl-ns same as ns, and\n  :init-impl-ns true. All options of gen-class are\n  supported. The :gen-class directive is ignored when not\n  compiling. If :gen-class is not supplied, when compiled only an\n  nsname__init.class will be generated. If :refer-clojure is not used, a\n  default (refer 'clojure.core) is used.  Use of ns is preferred to\n  individual calls to in-ns/require/use/import:\n\n  (ns foo.bar\n    (:refer-clojure :exclude [ancestors printf])\n    (:require (clojure.contrib sql combinatorics))\n    (:use (my.lib this that))\n    (:import (java.util Date Timer Random)\n             (java.sql Connection Statement)))",
  :bucket :var-definitions,
  :row 5753}
It probably should check for the :arglists metadata, right @borkdude?

seancorfield 2021-06-22T00:46:43.254700Z

Well, anything involving actually checking calls should use the actual arguments, but documentation should probably use the :arglists metadata.

seancorfield 2021-06-22T00:47:50.254900Z

So I think clj-kondo is returning the correct information there — but perhaps should also return :arglists-metadata-strs or something which clients (like LSP) could use for documentation (only)?

ericdallo 2021-06-22T00:50:14.255100Z

Looks good to me, then clojure-lsp could use this new field if available fallbacking to arglist-strs

ericdallo 2021-06-22T00:50:34.255300Z

As we only use this field for hover documentation

ericdallo 2021-06-22T00:50:46.255500Z

And signature-help feature

1
Joshua E Cook 2021-06-22T17:13:49.256100Z

I have a namespace of macros definitions which are required using :refer :all … is it possible to convince clj-kondo to resolve those symbols without redoing the require forms to refer to them specifically?

borkdude 2021-06-22T17:20:13.256600Z

@jec yes. in that case you should lint that library code as well, so clj-kondo knows about the existence of the vars.

Joshua E Cook 2021-06-22T17:22:06.256700Z

Thanks @borkdude. In my case, the macros namespace is in a dependency package. Is there a way to tell clj-kondo how to lint that code as well?

Joshua E Cook 2021-06-22T17:22:55.256900Z

I'm trying to do this within VS Code btw.

Joshua E Cook 2021-06-22T17:23:25.257100Z

IntelliJ + Cursive is able to resolve these macros correctly, but I'd prefer to use VS Code if I can get this to work.

borkdude 2021-06-22T17:24:02.257300Z

@jec Yes. This info is in the readme of clj-kondo under "Project setup"

borkdude 2021-06-22T17:24:23.257500Z

This is probably similar to how Cursive does it: the analyzer just has to see all of the code first

Joshua E Cook 2021-06-22T17:24:35.257700Z

I think I see… you're refering to the --dependencies flag right?

borkdude 2021-06-22T17:26:31.257900Z

yes. so if you use lein:

clj-kondo --lint "$(lein classpath)" --dependencies --parallel --copy-configs

borkdude 2021-06-22T17:26:40.258100Z

you'll also need a .clj-kondo directory first

Joshua E Cook 2021-06-22T17:26:41.258300Z

Adding that flag on the commandline seems to quiet the linter. But is there a way to set that in the config file? I'm not sure how to send that flag from VS Code

borkdude 2021-06-22T17:27:09.258500Z

@jec you don't need to

borkdude 2021-06-22T17:27:21.258700Z

once it has linted your dependencies, the vars are known

borkdude 2021-06-22T17:28:28.258900Z

or at least should be

borkdude 2021-06-22T17:28:43.259100Z

but the requirement is: you have to have .clj-kondo dir. can you confirm you have this?

Joshua E Cook 2021-06-22T17:29:05.259300Z

yes I have that dir

Joshua E Cook 2021-06-22T17:29:27.259500Z

are you saying the dependencies only need to be linted once, then the results are cached there?

borkdude 2021-06-22T17:29:40.259700Z

yes

Joshua E Cook 2021-06-22T17:29:53.259900Z

cool ty

👍 1
Joshua E Cook 2021-06-22T17:39:29.260200Z

well that seems to work on the commandline but it still flags these as problems in the VS Code editor…

borkdude 2021-06-22T17:40:14.260400Z

If you can make a standalone minimal repro for that library, that I can clone locally, I could try it myself

borkdude 2021-06-22T17:41:28.260600Z

could you also lint the file that gives problems in VSCode from the command line?

borkdude 2021-06-22T17:41:34.260800Z

just with clj-kondo --lint src/foo.clj, no other flags

Joshua E Cook 2021-06-22T17:42:31.261100Z

yes, linting the single file on the commandline with no other flags is quiet

borkdude 2021-06-22T17:43:36.261300Z

Then that's weird. This is an issue for #calva then. Tell them that clj-kondo on the command line works, but not in VSCode

Joshua E Cook 2021-06-22T17:44:14.261500Z

ty, I will try over there

borkdude 2021-06-22T17:45:30.261700Z

Hmm come to think about it... It could be that you are using a different version on the command line than is used in VSCode. But VSCode / Calva should already have linted your deps as well btw

borkdude 2021-06-22T17:45:36.261900Z

Which library is giving problems?

borkdude 2021-06-22T17:45:42.262100Z

cc @pez @ericdallo

borkdude 2021-06-22T17:47:36.262300Z

You could also try upgrading clojure-lsp and re-open your workspace

borkdude 2021-06-22T17:47:57.262500Z

At this point it's hard for me to give other options since it's apparently a downstream problem

Joshua E Cook 2021-06-22T17:53:46.262700Z

On the cli I'm using clj-kondo v2021.04.23 and in VS Code I'm using Calva v2.0.200

borkdude 2021-06-22T17:58:05.262900Z

@jec which library namespace is giving the unresolved vars?

Joshua E Cook 2021-06-22T17:59:39.263100Z

@borkdude it's not a public library, I'm working with a private codebase

Joshua E Cook 2021-06-22T18:00:15.263300Z

I have to go now, but I will check in again later

borkdude 2021-06-22T18:01:09.263500Z

ok, my last advice would be to upgrade clojure-lsp and restart your project. Calva has an option to upgrade clojure-lsp.

ericdallo 2021-06-22T18:46:16.263700Z

Yeah, I can test if it's a Calva or clojure-lsp issue if you have a minimal repro

Joshua E Cook 2021-06-22T19:48:14.263900Z

hey! it looks like setting Calva's version of clojure-lsp to 2021.04.23-15.49.47 matches my cli behavior

✅ 1
borkdude 2021-06-22T19:49:05.264200Z

cool

borkdude 2021-06-22T19:49:32.264400Z

could you also upgrade lsp to see if it still works? you will have to restart vscode so lsp is going to lint your deps (that can take a few seconds, maybe a minute)

borkdude 2021-06-22T19:49:42.264600Z

to the newest I mean

Joshua E Cook 2021-06-22T19:58:47.264800Z

set to 2021.06.21-14.30.54 and it isn't working for me

borkdude 2021-06-22T19:59:37.265Z

so I guess LSP isn't automatically linting your deps. Did you restart VsCode?

ericdallo 2021-06-22T19:59:55.265300Z

I'm not sure it's a issue with the clojure-lsp version, could you just copy the macros or make a repro with them? probably you will be able to repro the issue

ericdallo 2021-06-22T20:00:33.265500Z

Try to remove .lsp/sqlite.db and .clj-kondo/.cache and restart vscode

Joshua E Cook 2021-06-22T20:30:00.265700Z

ok, lspVersion set to 2021.06.21-14.30.54, removed those databases, then restarted vscode

Joshua E Cook 2021-06-22T20:30:04.265900Z

it seems to be working

👍 2
ericdallo 2021-06-22T20:31:41.266300Z

I'm not sure why sometimes there are users that complain about those kind of issues and it's solved removing those cache files, I'd like to improve that somehow, I just don't know how 😅

Joshua E Cook 2021-06-22T20:34:30.266500Z

maybe because I had used a different clj-kondo version on the commandline?

ericdallo 2021-06-22T20:36:58.266700Z

or a old one via calva, yeah, makes sense I think

borkdude 2021-06-22T21:02:56.266900Z

The command line clj-kondo doesn't interact with Calva or LSP, so that's not the reason

borkdude 2021-06-22T21:04:21.267100Z

Next time, try removing .lsq/sqlite.db first, without the clj-kondo cache

borkdude 2021-06-22T21:05:00.267300Z

Then we know if it's a caching problem in lsp. If not, also remove the clj-kondo cache. Then we know it's in either lsp or clj-kondo. Then also try only removing the clj-kondo cache if the problem occurs again.

borkdude 2021-06-22T21:05:08.267500Z

That will give us more info than removing both at the same time.

ericdallo 2021-06-22T21:05:19.267700Z

Good idea