lsp

:clojure-lsp: Clojure implementation of the Language Server Protocol: https://clojure-lsp.io/
NoahTheDuke 2021-04-02T16:18:56.191Z

maybe a bug? in a clojure file, i have (:require [clojure.string :as string]) in my ns macro, and then hover over (string/join ", " ...) and press my keys for "go to definition". it loads the clojurescript string file in my ~/.m2 directory

NoahTheDuke 2021-04-02T16:19:57.191600Z

if i "go to defintion" on clojure core library functions, it goes to the right clojure file

NoahTheDuke 2021-04-02T16:21:21.193Z

even if I [clojure.string :refer [join]], when i "go to definition" on join, it loads ~/.m2/.../clojurescript-1.10.238.jar::clojure/string.cljs

ericdallo 2021-04-02T16:23:44.193200Z

hum, could you try removing your .lsp/sqlite.db file and restart the lsp?

NoahTheDuke 2021-04-02T16:24:17.194Z

I forgot to mention that I'm using vim and coc.nvim, so maybe there's some funny business happening with that configuration

NoahTheDuke 2021-04-02T16:24:20.194100Z

will do!

NoahTheDuke 2021-04-02T16:26:11.194300Z

ericdallo 2021-04-02T16:26:40.194700Z

odd, is your project a lein one?

NoahTheDuke 2021-04-02T16:27:00.194900Z

it is

NoahTheDuke 2021-04-02T16:27:05.195100Z

ericdallo 2021-04-02T16:27:34.195500Z

could you run lein classpath on your project root?

NoahTheDuke 2021-04-02T16:27:53.195700Z

it's very long lol

ericdallo 2021-04-02T16:28:14.195900Z

I just want to know if it's pointing to the correct clojure only classpath

ericdallo 2021-04-02T16:28:35.196100Z

is your project clojure only? or clojurec or clojurescript?

NoahTheDuke 2021-04-02T16:28:46.196300Z

all 3

ericdallo 2021-04-02T16:29:54.196500Z

hum, maybe clojure-lsp is not getting the right one when there are the clojure and cljs available

ericdallo 2021-04-02T16:30:09.196700Z

could you confirm if that happens in a minimal repro project?

NoahTheDuke 2021-04-02T16:30:42.196900Z

sure, let me see what i can whip up for you

1
NoahTheDuke 2021-04-02T16:34:03.197200Z

if i run lein new minimal and then open the "core.clj" file, it works correctly

ericdallo 2021-04-02T16:34:42.197600Z

yeah, I think it'll only happen for projects where it has clojure core and cljs core on classpath

NoahTheDuke 2021-04-02T16:34:47.197800Z

if i change the :dependencies to those from my primary project, it shows the error again

NoahTheDuke 2021-04-02T16:35:20.198Z

ericdallo 2021-04-02T16:35:37.198400Z

nice, I think I can try to repro with that

ericdallo 2021-04-02T16:35:41.198600Z

I'll let you know, thanks

NoahTheDuke 2021-04-02T16:36:33.198800Z

looks like it happens with

:dependencies [[org.clojure/clojure "1.9.0"]
                 [org.clojure/clojurescript "1.10.238"]]

NoahTheDuke 2021-04-02T16:36:39.199Z

thanks so much, and good luck!

ericdallo 2021-04-02T17:29:32.199200Z

Fixed https://github.com/clojure-lsp/clojure-lsp/commit/076ee8055078c87d2441ba317c00c911da9a9bee, I'll probably release next version this weekend 🙂

NoahTheDuke 2021-04-02T18:01:42.199500Z

ayyyyyy! Thank you so much!

👍 1
borkdude 2021-04-02T20:32:10.200400Z

Can people who use lsp linting (not clj-kondo standalone) try this snippet:

(defmulti foo :bar)
(defmethod foo :test
  [{:keys [a b] :or {a 1 b 2}}]
  (let [q (* 10 (dec a))]
    (+ b q)))
Do you get any warnings?

borkdude 2021-04-02T20:32:25.200800Z

If not, then the problem is #calva specific and not something in the (latest) lsp

ericdallo 2021-04-02T20:36:49.201Z

I get both unused-binding on a and b :

borkdude 2021-04-02T20:50:11.201400Z

that's bad then, because that's a false positive

borkdude 2021-04-02T20:50:22.201600Z

and it isn't happening with vanilla clj-kondo

ericdallo 2021-04-02T20:50:47.201800Z

Hum, it seems clj-kondo standalone doesn't print that unless you pass :locals true

clj -Sdeps '{:deps {clj-kondo {:mvn/version "2021.03.31"}}}' -m clj-kondo.main  --lint src/clojure_sample/lsp/definition/a.clj --config '{:output {:analysis {:arglists true :locals true :keywords true} :canonical-paths true}}

/home/greg/dev/clojure-sample/src/clojure_sample/lsp/definition/a.clj:6:22: warning: unused default for binding a
/home/greg/dev/clojure-sample/src/clojure_sample/lsp/definition/a.clj:6:26: warning: unused default for binding b
linting took 156ms, errors: 0, warnings: 2 
clj -Sdeps '{:deps {clj-kondo {:mvn/version "2021.03.31"}}}' -m clj-kondo.main  --lint src/clojure_sample/lsp/definition/a.clj --config '{:output {:analysis {:arglists true :keywords true} :canonical-paths true}}'

linting took 160ms, errors: 0, warnings: 0

borkdude 2021-04-02T20:51:07.202Z

huh

borkdude 2021-04-02T20:51:48.202200Z

that's interesting

borkdude 2021-04-02T20:53:40.202400Z

@snoe?

ericdallo 2021-04-02T20:57:41.202800Z

Not sure, but maybe https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/namespace.clj#L233 is affecting that

borkdude 2021-04-02T20:58:55.203100Z

but analysis data should not have an effect on unused defaults

ericdallo 2021-04-02T21:00:05.203300Z

yeah, you are right, must be something else

borkdude 2021-04-02T21:04:44.203500Z

Smaller repro:

(fn
  [{:keys [a] :or {a 1}}]
  a)

👍 1
borkdude 2021-04-02T21:09:40.203800Z

I think it might be in here:

v (cond-> (assoc m
                                          :name s
                                          :filename (:filename ctx)
                                          :tag t)
                             (:analyze-locals? ctx)
                             (-> (assoc :id (swap! (:id-gen ctx) inc)
                                        :str (str expr))
                                 (merge (scope-end scoped-expr))))
So there is a condition if locals are being analyzed or not, and if so, something is added, which may cause some comparison to go wrong

👀 1
borkdude 2021-04-02T21:11:57.204100Z

so I think we'll have to pull the reg-binding apart for analysis

borkdude 2021-04-02T21:12:29.204300Z

or dissoc some stuff before it's registered into the other bucket

borkdude 2021-04-02T21:14:08.204500Z

so I can repro with this:

$ clj-kondo --config '{:output {:analysis {:locals true}}}' --lint /tmp/sean.clj
/tmp/sean.clj:3:20: warning: unused default for binding a

👍 1
ericdallo 2021-04-02T21:14:46.204900Z

yes, I just used the same args from clojure-lsp, but yeah, it's the locals that cause that

borkdude 2021-04-02T21:15:45.205100Z

ok, I'll work on a fix

🙌 1
borkdude 2021-04-02T21:47:57.205400Z

fixed. @seancorfield

seancorfield 2021-04-02T21:50:59.205600Z

Wow! Nice detective work!

ericdallo 2021-04-02T21:52:08.205800Z

Thanks! I should bump and release a new clojure-lsp with that fix tomorrow, then @brandon.ringe can bump on Calva soon 🙂

👍 2
borkdude 2021-04-02T21:52:36.206Z

@ericdallo cool. I think people can bump their lsp version manually now in #calva

1
borkdude 2021-04-02T21:52:51.206200Z

so as soon as there is a new version, Sean should be able to use it already

pez 2021-04-02T22:31:29.206800Z

:male-detective: