Fork me on GitHub
#lsp
<
2021-09-14
>
simonkatz15:09:07

It seems that sometimes declarations to ignore unused public vars are behaving strangely. Example code:

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn foo []
  42)
If I open a new instance of Emacs and navigate to this code, then, after the workspace has started, the code can sometimes be highlighted as having an unused public var. If I then edit the file (eg enter a space and then undo the change), the error report goes away. If I restart the lsp workspace (with `lsp-worspace-restart`), the error report re-appears (or can re-appear), If I move the declaration to the project’s `config.edn` like this…
:clojure-lsp/unused-public-var {:exclude #{my-ns/foo}}
…then all is OK. I said “sometimes” and “can re-appear” above. It seems to work like this: In small projects, there’s never a problem; in large projects, the problem always happens; in projects of a certain middle size the problem sometimes happens and sometimes doesn’t. Any thoughts on what might be happening or what I can do to find out more? I’m now using clojure-lsp 2021.09.13-22.25.35, but I first noticed this some time ago.

all-clear 2
ericdallo15:09:58

yeah, I saw this behaviour recently, but couldn't understand exactly what is going on, I suspect it's related with the first clj-kondo analysis we do when starting the project which doesn't understand the ignore for some reason in the custom-lint-fn but the next analysis scan, did when you open a file or edit something works

ericdallo15:09:31

if you could repro in a simple repo that would help a lot

simonkatz15:09:09

Thanks. I’ll have a try at doing that.

simonkatz15:09:53

Does your suggestion account for it happening only sometimes? (I mean with the same code — ie it’s non-deterministic).

ericdallo15:09:24

no, for me it's deterministic, if I start clojure-lsp, and call lsp-treemacs-errors-list , I will see unused public var diagnostics that only go away if I enter the file (which will trigger a clj-kondo single-file analysis)

simonkatz15:09:41

Ah. For me, lsp-treemacs-errors-list deterministically gives me the erroneous reports, but the flycheck reports are non-deterministic. Still working on a repro repo.

ericdallo15:09:10

because I think the flycheck one can get the updated or outdated diagnostics

ericdallo15:09:40

that's why if we fix it we can confirm it won't happen if lsp-treemacs-errors-list show no warnings

simonkatz15:09:51

It has 1000 namespaces, each with an unused public var.

simonkatz16:09:15

Let me know if you want me to create an issue.

simonkatz16:09:09

If you want more than 1000 namespaces, the code in the create-ns-s namespace creates them.

ericdallo16:09:04

I think only 2 namespace are enough to repro the issue, but there is no problem keeping the 1000, I tested and confirmed the issue

ericdallo16:09:13

would you mind opening an issue to help tracking?

simonkatz16:09:56

Sure. Not right now, but within a few hours. Thanks.

👍 2
simonkatz16:09:45

BTW, I need many namespaces in order to get the non-deterministic behaviour with flycheck. (But I understand your point.)

👍 2
donavan09:09:35

I’m possibly hitting this though in my project all my declarations are in .lsp/config.edn. I’ve upgraded to the new brew version (clojure-lsp/brew/clojure-lsp-native) and I’ve updated to the latest clj-kondo. I’ve also updated to the new key (:clojure-lsp/unused-public-var)… anything else I’m possilby not thinking of?

simonkatz10:09:20

@U0VP19K6K It turns out that what I said about putting things in config.edn was only sometimes true. I edited the bug report to say so a little while ago.

simonkatz10:09:53

I think it’s a matter of waiting for a new release of clj-kondo (which has a fix merged), and then a new release of lsp-clojure that includes the new clj-kondo.

donavan10:09:11

Thanks, was just about to ask if it’s just a matter of waiting, thanks @U06A9U5RP!

ericdallo13:09:16

Yeah, clj-kondo just merged the improvement, I will add a unit test and then make the changes on clojure-lsp, then it should fix this issue :)

ericdallo13:09:29

Fixed on master, you can try building clojure-lsp local with make or waiting for the next release :)

👍 2
donavan12:09:14

I’m still having issues with this (I think!). Is there anything here that stands out to anyone? I have • clojure-lsp/brew/clojure-lsp-native 2021.09.13-22.25.35borkdude/brew/clj-kondo 2021.09.15 • I’ve cleared out both cache directories • I’m using the new config.edn format:

{:linters
 {:clojure-lsp/unused-public-var
  {:exclude #{FULLY_QUALIFIED_VARS}}}}

all-clear 2
ericdallo12:09:51

Looks correct to me

ericdallo12:09:38

would you mind trying on a simple repro repository?

donavan12:09:49

https://github.com/dcostaras/lsp-unused-vars-repro There is a screenshot in the root showing the warning

donavan12:09:34

Thanks! 😄

ericdallo13:09:12

Oh I see now

ericdallo13:09:54

your configuration content is correct, but it's on the wrong file 😅 The correct location for this lint config is on .clj-kondo/config.edn

donavan13:09:42

Oh right! Haha, yeah this is hold over from before (I think this used to the correct dir?) I changed the format but didn’t read that paragraph properly. Thanks again 🙌

ericdallo13:09:56

yeah, some months ago this was on clojure-lsp but this was causing a lot of other issues, since we started using as a custom clj-kondo lint-fn, this now needs to be configured there

ericdallo13:09:36

You can think: when this is related to lint, should be configured on clj-kondo otherwise probably lsp

donavan13:09:48

Yeah, I did actually think it was a bit less ergonomic having two config files for linting. All good 🙂

👍 2
donavan12:09:14
replied to a thread:It seems that sometimes declarations to ignore unused public vars are behaving strangely. Example code: #_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]} (defn foo [] 42) If I open a new instance of Emacs and navigate to this code, then, after the workspace has started, the code can sometimes be highlighted as having an unused public var. If I then edit the file (eg enter a space and then undo the change), the error report goes away. If I restart the lsp workspace (with `lsp-worspace-restart`), the error report re-appears (or can re-appear), If I move the declaration to the project’s `config.edn` like this… :clojure-lsp/unused-public-var {:exclude #{my-ns/foo}} …then all is OK. I said “sometimes” and “can re-appear” above. It seems to work like this: In small projects, there’s never a problem; in large projects, the problem always happens; in projects of a certain middle size the problem sometimes happens and sometimes doesn’t. Any thoughts on what might be happening or what I can do to find out more? I’m now using clojure-lsp 2021.09.13-22.25.35, but I first noticed this some time ago.

I’m still having issues with this (I think!). Is there anything here that stands out to anyone? I have • clojure-lsp/brew/clojure-lsp-native 2021.09.13-22.25.35borkdude/brew/clj-kondo 2021.09.15 • I’ve cleared out both cache directories • I’m using the new config.edn format:

{:linters
 {:clojure-lsp/unused-public-var
  {:exclude #{FULLY_QUALIFIED_VARS}}}}

all-clear 2