clj-kondo

https://github.com/clj-kondo/clj-kondo
ikitommi 2021-07-04T07:24:34.307600Z

hi. there is an off-by-1 error either on Idea or on clj-kondo on reporting unused function argument location. see f in the pic. greyed out are from cursive, underlines from clj-kondo :thinking_face:

ikitommi 2021-07-05T07:49:34.332Z

tested from command line, the PATH is corrrect, but still doesn’t work, timeouts after 30sec:

2021-07-05T07:46:22.505Z UnknownHost INFO [clojure-lsp.crawler:27] - Finding classpath via ` clojure -Spath `
2021-07-05T07:46:22.566Z UnknownHost INFO [clojure-lsp.crawler:27] - Finding classpath via ` npx shadow-cljs classpath `
2021-07-05T07:46:51.574Z UnknownHost INFO [clojure-lsp.crawler:204] - Analyzing classpath for project root /Users/tommi/projects/metosin/malli
2021-07-05T07:46:51.575Z UnknownHost INFO [clojure-lsp.crawler:88] - Analyzing 15 paths with clj-kondo with batch size of 1 ...

ikitommi 2021-07-05T07:50:29.332200Z

IDEA logs this:

2021-07-05 10:47:52,122 [ 106969]   WARN - pper.LanguageServerWrapperImpl - Capabilities are null for rawCommand : /usr/local/bin/clojure-lsp
2021-07-05 10:47:52,123 [ 106970]   WARN - ub.gtache.lsp.utils.FileUtils$ - invalid url: ///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar!/clojure/core.clj (java.net.MalformedURLException: no protocol: ///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar)
java.net.MalformedURLException: invalid url: ///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar!/clojure/core.clj (java.net.MalformedURLException: no protocol: ///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar)
	at java.base/java.net.URL.<init>(URL.java:679)
	at java.base/java.net.URL.<init>(URL.java:541)
	at java.base/java.net.URL.<init>(URL.java:488)
	at com.github.gtache.lsp.utils.FileUtils$.VFSToURI(FileUtils.scala:101)
	at com.github.gtache.lsp.utils.FileUtils$.editorToURIString(FileUtils.scala:89)
	at com.github.gtache.lsp.client.languageserver.wrapper.LanguageServerWrapperImpl.connect(LanguageServerWrapperImpl.scala:181)
	at com.github.gtache.lsp.client.languageserver.wrapper.LanguageServerWrapperImpl.$anonfun$restart$1(LanguageServerWrapperImpl.scala:405)
	at com.github.gtache.lsp.client.languageserver.wrapper.LanguageServerWrapperImpl.$anonfun$restart$1$adapted(LanguageServerWrapperImpl.scala:405)
	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
	at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
	at com.github.gtache.lsp.client.languageserver.wrapper.LanguageServerWrapperImpl.restart(LanguageServerWrapper

ikitommi 2021-07-05T07:52:31.332400Z

tested from repl, that doesn’t work:

(java.net.URL. "///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar")
; =throws=> Execution error (MalformedURLException) at java.net.URL/<init> (URL.java:593).
; no protocol: ///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar

ikitommi 2021-07-05T07:53:07.332600Z

➜  ~ ls -l ///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar
-rw-r--r--  1 tommi  staff  3914649 Mar 11 20:47 ///Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar

ikitommi 2021-07-05T07:55:43.332800Z

so: 1. IDEA doesn’t set the PATH correctly 2. clojure -Spath returns URLs that the plugin doesn’t understand (uses java.net.Url.

ikitommi 2021-07-05T07:56:02.333Z

➜  malli git:(malli.instrument) ✗ clojure -Spath

src:resources:/Users/tommi/.m2/repository/borkdude/dynaload/0.2.2/dynaload-0.2.2.jar:/Users/tommi/.m2/repository/borkdude/edamame/0.0.11/edamame-0.0.11.jar:/Users/tommi/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar:/Users/tommi/.m2/repository/org/clojure/test.check/1.1.0/test.check-1.1.0.jar:/Users/tommi/.m2/repository/org/clojure/tools.reader/1.3.4/tools.reader-1.3.4.jar:/Users/tommi/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar:/Users/tommi/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar

ericdallo 2021-07-05T12:27:12.333200Z

@luis.tn the 2. seems a issue with clojure-lsp right? For some reason with IDEA it returns wrong urls

ericdallo 2021-07-05T12:27:51.333400Z

Or the lsp plugin is sending malformed URLs

ikitommi 2021-07-05T12:28:28.333600Z

above is what clojure -Spath returns. The plugin uses Url to handle those, which can’t

ikitommi 2021-07-05T12:29:14.333800Z

e.g. the plugin should be changed or the urls should be preprosessed to be compliant what Url accepts.

ericdallo 2021-07-05T12:29:45.334Z

Yeah, but probably is not following some convention somewhere in the plugin as all other editors like VSCode, emacs, vim works

ikitommi 2021-07-05T12:30:18.334200Z

e.g. add file: to the urls

ericdallo 2021-07-05T12:30:19.334400Z

I can try to repro that with IDEA + LSP plugin

1🙇
ikitommi 2021-07-05T12:30:25.334600Z

(java.net.URL. "file:/Users/tommi/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar")
works ok

ericdallo 2021-07-05T12:31:41.334900Z

BTW try to disable that timeout, that will not work as sometimes (first time) clojure-lsp will take a while to scan the project and other times it will be fast

ikitommi 2021-07-05T12:32:19.335100Z

yeah, did that. just that it doesn’t load any files from classpath as it can’t read the urls

ericdallo 2021-07-05T12:33:09.335300Z

Yes, let me try understand where the issue is, I'll try to repro

ericdallo 2021-07-05T13:32:59.335700Z

I managed to make it work without any errors

ericdallo 2021-07-05T13:33:30.336100Z

But I need to say this LSP plugin is missing a lot of features and its UX is not great IMO 😞

ericdallo 2021-07-05T13:33:32.336300Z

I'd suggest you try Calva for VSCode or Emacs if you want the better clojure development experience 😕

ericdallo 2021-07-05T13:34:43.336700Z

Anyway, I didn't get any URLs errors :thinking_face: (NixOS here)

borkdude 2021-07-04T07:25:37.308Z

Can you paste the code? I can try in emacs

ikitommi 2021-07-04T07:27:15.308200Z

(defn kikka [x y z] (+ y z))

ikitommi 2021-07-04T07:27:29.308400Z

borkdude 2021-07-04T07:29:45.308800Z

borkdude 2021-07-04T07:30:04.309200Z

Can you disable clj-kondo, to see if it's related?

ikitommi 2021-07-04T07:32:32.309400Z

disabling clj-kondo makes the underlining go away, as expected

ikitommi 2021-07-04T07:32:40.309600Z

➜ ~ clj-kondo -v clj-kondo v2021.06.01

borkdude 2021-07-04T07:34:33.310900Z

This is weird, might be an issue with the thing you’re using to integrate clj-kondo, what is that?

ikitommi 2021-07-04T07:34:55.311400Z

file-watcher

borkdude 2021-07-04T07:34:57.311600Z

Be back in an hour or so

borkdude 2021-07-04T07:35:11.312200Z

Try the LSP thing, might work better

borkdude 2021-07-04T07:35:17.312600Z

See docs

ikitommi 2021-07-04T07:35:18.312800Z

👍

ikitommi 2021-07-04T07:51:49.313Z

it works. will start using that.

ikitommi 2021-07-04T07:54:09.313400Z

ok, but, the existing cursive greying out doesnt work with LSP.

ikitommi 2021-07-04T07:54:27.313600Z

ikitommi 2021-07-04T07:58:36.314500Z

default cursive:

borkdude 2021-07-04T09:20:04.315Z

ok, I think the problem is not so much in clj-kondo but in the integration then

borkdude 2021-07-04T09:20:08.315200Z

not sure if there's anything I can do

borkdude 2021-07-04T09:20:18.315400Z

perhaps ask in #cursive

ikitommi 2021-07-04T20:29:50.315900Z

note on the LSP-version performance. for large/complex files, it’s really slow on IDEA. Trying to write (inc "kikka") into the end of malli.core ns, takes 10sec just to echo the characters into screen.

ikitommi 2021-07-04T20:30:31.316100Z

file-watcher does this only on save, so handles it much better.

ikitommi 2021-07-04T20:31:04.316300Z

do you have any ideas on how to make the LSP-version work better?

borkdude 2021-07-04T20:31:55.316500Z

I think it can be improved by borrowing some ideas from clojure-lsp, especially the implementation of incremental diffing. or you might want to try clojure-lsp altogether in Cursive, it uses clj-kondo so you would get that for free as well.

borkdude 2021-07-04T20:32:17.316700Z

actually I wrote part of that diffing code in clojure-lsp ;) (not sure if that code is still used)

borkdude 2021-07-04T20:32:48.317Z

@ericdallo might have some ideas here

borkdude 2021-07-04T20:33:16.317200Z

The code is here: https://github.com/clj-kondo/clj-kondo.lsp PRs are welcome

ikitommi 2021-07-04T20:34:11.317600Z

thanks. I would assume the LSP is on different thread and would not block the basic editor features. At least with clj-kondo, seeing result later is totally ok (different case with auto-complete etc)

borkdude 2021-07-04T20:34:56.317800Z

true. clojure-lsp might already have that and it could be ported

ericdallo 2021-07-04T20:36:53.318Z

I'd suggest test clojure-lsp on intellij and confirm if that issue happens

borkdude 2021-07-04T20:44:41.318200Z

it's kind of worrying that the lsp plugin for intellij is "on hold" since a year ago

ericdallo 2021-07-04T20:46:26.318400Z

Yeah... @borkdude the grey feature is a thing on the LS server, the server can add a tag on the diagnostic telling that is unused, then the LS client grey the variable

ericdallo 2021-07-04T20:47:50.318900Z

In case you want to add that to clj-kondo.lsp

borkdude 2021-07-04T20:48:30.319100Z

sure, PR welcome! I don't use the LSP plugin myself but I'm open to improvements for who do

1👍
ikitommi 2021-07-04T20:48:52.319400Z

hmm.. says classpath lookup failed in clojure-lsp. tried to add brew-installed clojure-lsp as the server.

ericdallo 2021-07-04T20:49:20.319600Z

Are you using the clojure-lsp official brew one?

ericdallo 2021-07-04T20:49:44.319800Z

https://clojure-lsp.github.io/clojure-lsp/installation/

ikitommi 2021-07-04T20:50:14.320100Z

➜ clojure-lsp --version
clojure-lsp 2021.07.01-19.49.02
clj-kondo 2021.06.18

ericdallo 2021-07-04T20:51:13.320300Z

Alright, check the clojure-lsp log file, you can set it with :log-path setting on .lsp/config.edn

ikitommi 2021-07-04T20:53:23.320500Z

don’t have that folder, will create

ericdallo 2021-07-04T20:55:17.320700Z

The lookup is directly related with clojure-lsp running lein classpath or clojure -Spath

ericdallo 2021-07-04T20:55:28.320900Z

And the same for boot and shadow-cljs projects

ikitommi 2021-07-04T20:56:07.321100Z

2021-07-04T20:54:19.454Z UnknownHost INFO [clojure-lsp.crawler:236] - Automatically resolved source-paths from deps.edn: #{"src" "resources" "test"}
2021-07-04T20:54:19.971Z UnknownHost WARN [clojure-lsp.db:55] - Could not load db [SQLITE_ERROR] SQL error or missing database (no such table: project)
2021-07-04T20:54:19.972Z UnknownHost INFO [clojure-lsp.crawler:27] - Finding classpath via ` clojure -A:dev -Spath `
2021-07-04T20:54:19.979Z UnknownHost ERROR [clojure-lsp.crawler:38] - Error while looking up classpath info in /Users/tommi/projects/metosin/malli Cannot run program "clojure" (in directory "/Users/tommi/projects/metosin/malli"): error=2, No such file or directory

ikitommi 2021-07-04T20:56:39.321300Z

I do have clojure available :thinking_face:

ericdallo 2021-07-04T20:56:44.321500Z

You need clojure installed

ericdallo 2021-07-04T20:57:00.321700Z

Hum for some reason it's not finding on your PATH or something

ericdallo 2021-07-04T20:57:12.321900Z

Never saw this kind of error

ikitommi 2021-07-04T21:04:08.322100Z

ikitommi 2021-07-04T21:04:47.322500Z

not sure how can I pass any PATH to LSP, copied clojure executable to the directory, still doesn’t see that.

ericdallo 2021-07-04T21:05:39.322700Z

Yeah, that seems that won't help, could you try the non Graalvm binary?

ericdallo 2021-07-04T21:05:48.322900Z

Its available on GitHub releases page

ericdallo 2021-07-04T21:05:59.323100Z

As clojure-lsp

ikitommi 2021-07-04T21:09:39.323300Z

sure, didn’t start in 10sec, need to set the timeout.

ericdallo 2021-07-04T21:10:21.323500Z

Yeah, it'll take 5-10s to start I think

ikitommi 2021-07-04T21:10:58.323700Z

same thing.

ericdallo 2021-07-04T21:11:29.323900Z

So it's not a issue with clojure-lsp, probably something with your OS not finding Clojure command

ericdallo 2021-07-04T21:11:47.324100Z

I never saw anyone complaining about this error :/

ericdallo 2021-07-04T21:12:18.324300Z

What OS are you using?

ikitommi 2021-07-04T21:13:48.324500Z

macOS 11.4

ikitommi 2021-07-04T21:13:55.324700Z

pasted the error here: https://gist.github.com/ikitommi/f2cacfe5c389c4459a89f397342293c3

ericdallo 2021-07-04T21:14:19.324900Z

This is how clojure-lsp call that command: https://github.com/clojure-lsp/clojure-lsp/blob/master/src/clojure_lsp/crawler.clj#L32

ericdallo 2021-07-04T21:14:43.325200Z

It's a clojure.java.shell/sh

ericdallo 2021-07-04T21:16:44.325400Z

Feel free to open an issue, I'm out of suggestions ATM

borkdude 2021-07-04T21:16:56.325600Z

btw 10 seconds linting is quite extreme, most files take just a few milliseconds

ikitommi 2021-07-04T21:17:32.325800Z

it was the non-graalvm-thing, slow startup.

ikitommi 2021-07-04T21:17:45.326Z

I’ll write an issue, thanks both!

borkdude 2021-07-04T21:18:11.326200Z

@ikitommi sure, but the startup should happen only once

borkdude 2021-07-04T21:18:13.326400Z

per project

ericdallo 2021-07-04T21:18:42.326600Z

Not if the classpath scan didn't work @borkdude

ericdallo 2021-07-04T21:19:03.326800Z

Then clojure-lsp doesn't cache the analysis

borkdude 2021-07-04T21:19:04.327Z

I mean for clj-kondo.lsp

ericdallo 2021-07-04T21:19:10.327200Z

Oh, ok

borkdude 2021-07-04T21:19:52.327400Z

clj-kondo.lsp doesn't use a classpath scan, unless you do that yourself from the command line

borkdude 2021-07-04T21:20:56.327600Z

(currently, it might be something it could borrow from clojure-lsp in the future)

ericdallo 2021-07-04T21:21:42.327800Z

Oh, @ikitommi does /`Users/tommi/projects/metosin/malli` is the correct project root?

ericdallo 2021-07-04T21:22:30.328100Z

And that folder exists?

ikitommi 2021-07-04T21:23:50.328300Z

yes, exists

ikitommi 2021-07-04T21:24:14.328500Z

and copied clojure there too just for making sure

borkdude 2021-07-04T21:24:29.328700Z

it seems clojure cannot be found? what do you get for which clojure in the shell?

1👍
borkdude 2021-07-04T21:25:22.329Z

intellij/cursive might have an issue with passing through the PATH, I've seen such an issue in #cursive before

borkdude 2021-07-04T21:25:44.329200Z

or perhaps it's in the gtache plugin

ikitommi 2021-07-04T21:25:48.329400Z

➜  ~ which clojure
/usr/local/bin/clojure
➜  ~ clojure
Clojure 1.10.3
user=>

ericdallo 2021-07-04T21:26:18.329600Z

Oh, good point, it must be something with Intellij/cursive not using the correct PATH

borkdude 2021-07-04T21:27:47.329800Z

perhaps you could use as the lsp plugin a bb script which spits out the PATH to a file and does nothing else

borkdude 2021-07-04T21:27:58.330Z

so you can inspect what it gets to see

ericdallo 2021-07-04T21:32:07.330200Z

@ikitommi I can try to setup Intellij later, what plugins for intellij are you using to setup clojure-lsp?

borkdude 2021-07-04T21:34:41.330400Z

probably the gtache lsp plugin as documented in the clj-kondo docs

1👍
ikitommi 2021-07-04T21:41:09.330700Z

yes, this: https://github.com/gtache/intellij-lsp

ikitommi 2021-07-04T21:41:28.331Z

🙇 *2

ericdallo 2021-07-04T21:42:34.331200Z

Almost sure it's a bug in that plugin, not configuring the PATH correctly

borkdude 2021-07-04T21:44:36.331400Z

well, IntelliJ is a UI program which might not use the same PATH as bash or whatever?

borkdude 2021-07-04T21:44:53.331600Z

at least it could find java in the clj-kondo.lsp plugin

ericdallo 2021-07-04T22:21:28.331800Z

Yeah, maybe try to start Intellij from a terminal which has clojure on it