Fork me on GitHub
#clj-kondo
<
2021-07-04
>
ikitommi07:07:34

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:

borkdude07:07:37

Can you paste the code? I can try in emacs

ikitommi07:07:15

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

borkdude07:07:04

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

ikitommi07:07:32

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

ikitommi07:07:40

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

borkdude07:07:33

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

ikitommi07:07:55

file-watcher

borkdude07:07:57

Be back in an hour or so

borkdude07:07:11

Try the LSP thing, might work better

ikitommi07:07:49

it works. will start using that.

ikitommi07:07:09

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

ikitommi07:07:36

default cursive:

borkdude09:07:04

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

borkdude09:07:08

not sure if there's anything I can do

borkdude09:07:18

perhaps ask in #cursive

ikitommi20:07:50

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.

ikitommi20:07:31

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

ikitommi20:07:04

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

borkdude20:07:55

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.

borkdude20:07:17

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

borkdude20:07:48

@UKFSJSM38 might have some ideas here

ikitommi20:07:11

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)

borkdude20:07:56

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

ericdallo20:07:53

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

borkdude20:07:41

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

ericdallo20:07:26

Yeah... @U04V15CAJ 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

ericdallo20:07:50

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

borkdude20:07:30

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

👍 3
ikitommi20:07:52

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

ericdallo20:07:20

Are you using the clojure-lsp official brew one?

ikitommi20:07:14

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

ericdallo20:07:13

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

ikitommi20:07:23

don’t have that folder, will create

ericdallo20:07:17

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

ericdallo20:07:28

And the same for boot and shadow-cljs projects

ikitommi20:07:07

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

ikitommi20:07:39

I do have clojure available :thinking_face:

ericdallo20:07:44

You need clojure installed

ericdallo20:07:00

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

ericdallo20:07:12

Never saw this kind of error

ikitommi21:07:47

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

ericdallo21:07:39

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

ericdallo21:07:48

Its available on GitHub releases page

ericdallo21:07:59

As clojure-lsp

ikitommi21:07:39

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

ericdallo21:07:21

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

ikitommi21:07:58

same thing.

ericdallo21:07:29

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

ericdallo21:07:47

I never saw anyone complaining about this error :/

ericdallo21:07:18

What OS are you using?

ericdallo21:07:43

It's a clojure.java.shell/sh

ericdallo21:07:44

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

borkdude21:07:56

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

ikitommi21:07:32

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

ikitommi21:07:45

I’ll write an issue, thanks both!

borkdude21:07:11

@U055NJ5CC sure, but the startup should happen only once

borkdude21:07:13

per project

ericdallo21:07:42

Not if the classpath scan didn't work @U04V15CAJ

ericdallo21:07:03

Then clojure-lsp doesn't cache the analysis

borkdude21:07:04

I mean for clj-kondo.lsp

borkdude21:07:52

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

borkdude21:07:56

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

ericdallo21:07:42

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

ericdallo21:07:30

And that folder exists?

ikitommi21:07:50

yes, exists

ikitommi21:07:14

and copied clojure there too just for making sure

borkdude21:07:29

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

👍 3
borkdude21:07:22

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

borkdude21:07:44

or perhaps it's in the gtache plugin

ikitommi21:07:48

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

ericdallo21:07:18

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

borkdude21:07:47

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

borkdude21:07:58

so you can inspect what it gets to see

ericdallo21:07:07

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

borkdude21:07:41

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

👍 3
ericdallo21:07:34

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

borkdude21:07:36

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

borkdude21:07:53

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

ericdallo22:07:28

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

ikitommi07:07:34

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 ...

ikitommi07:07:29

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

ikitommi07:07:31

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

ikitommi07:07:07

➜  ~ 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

ikitommi07:07:43

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

ikitommi07:07:02

➜  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

ericdallo12:07:12

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

ericdallo12:07:51

Or the lsp plugin is sending malformed URLs

ikitommi12:07:28

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

ikitommi12:07:14

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

ericdallo12:07:45

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

ikitommi12:07:18

e.g. add file: to the urls

ericdallo12:07:19

I can try to repro that with IDEA + LSP plugin

🙇 3
ikitommi12:07:25

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

ericdallo12:07:41

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

ikitommi12:07:19

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

ericdallo12:07:09

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

ericdallo13:07:59

I managed to make it work without any errors

ericdallo13:07:30

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

ericdallo13:07:32

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

ericdallo13:07:43

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

Karol Wójcik13:07:50

@U055NJ5CC what font/theme are you using btw?

ikitommi17:07:14

@UJ1339K2B Borealis + Ligaturzed Menlo.