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
if i "go to defintion" on clojure core library functions, it goes to the right clojure file
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
hum, could you try removing your .lsp/sqlite.db
file and restart the lsp?
I forgot to mention that I'm using vim and coc.nvim, so maybe there's some funny business happening with that configuration
will do!
odd, is your project a lein one?
it is
could you run lein classpath
on your project root?
it's very long lol
I just want to know if it's pointing to the correct clojure only classpath
is your project clojure only? or clojurec or clojurescript?
all 3
hum, maybe clojure-lsp is not getting the right one when there are the clojure and cljs available
could you confirm if that happens in a minimal repro project?
sure, let me see what i can whip up for you
if i run lein new minimal
and then open the "core.clj" file, it works correctly
yeah, I think it'll only happen for projects where it has clojure core and cljs core on classpath
if i change the :dependencies
to those from my primary project, it shows the error again
nice, I think I can try to repro with that
I'll let you know, thanks
looks like it happens with
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.238"]]
thanks so much, and good luck!
Fixed https://github.com/clojure-lsp/clojure-lsp/commit/076ee8055078c87d2441ba317c00c911da9a9bee, I'll probably release next version this weekend 🙂
ayyyyyy! Thank you so much!
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?If not, then the problem is #calva specific and not something in the (latest) lsp
I get both unused-binding on a
and b
:
that's bad then, because that's a false positive
and it isn't happening with vanilla clj-kondo
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
huh
that's interesting
Not sure, but maybe https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/namespace.clj#L233 is affecting that
but analysis data should not have an effect on unused defaults
yeah, you are right, must be something else
Smaller repro:
(fn
[{:keys [a] :or {a 1}}]
a)
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 wrongso I think we'll have to pull the reg-binding apart for analysis
or dissoc some stuff before it's registered into the other bucket
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
yes, I just used the same args from clojure-lsp, but yeah, it's the locals that cause that
ok, I'll work on a fix
fixed. @seancorfield
Wow! Nice detective work!
Thanks! I should bump and release a new clojure-lsp with that fix tomorrow, then @brandon.ringe can bump on Calva soon 🙂
@ericdallo cool. I think people can bump their lsp version manually now in #calva
so as soon as there is a new version, Sean should be able to use it already
:male-detective: