lsp

2024-09-04T13:11:22.626099Z

funny thing i've noticed: symbols that match clojure.core functions but end in * aren't marked as errors. given:

(ns lazytest.malli)

run!*

foo*

foo
clj-kondo and clojure-lsp differ with their reported errors:
noah@Noahs-MacBook-Pro ~/personal/lazytest  [master ≡ +0 ~2 -0 !]
$ clj-kondo --lint src
src/clojure/lazytest/malli.clj:3:1: error: Unresolved symbol: run!*
src/clojure/lazytest/malli.clj:5:1: error: Unresolved symbol: foo*
src/clojure/lazytest/malli.clj:7:1: error: Unresolved symbol: foo
linting took 76ms, errors: 3, warnings: 0

noah@Noahs-MacBook-Pro ~/personal/lazytest  [master ≡ +0 ~2 -0 !]
$ clojure-lsp diagnostics
[ 99%] Project analyzed            Finding diagnostics...
src/clojure/lazytest/malli.clj:5:1: error: [unresolved-symbol] Unresolved symbol: foo*
src/clojure/lazytest/malli.clj:7:1: error: [unresolved-symbol] Unresolved symbol: foo

ericdallo 2024-09-04T13:54:17.203089Z

yeah that's weird 😂 we rely on clj-kondo findings for that, maybe some bug in the api? any thoughts @borkdude?

borkdude 2024-09-04T13:56:21.658829Z

this might be a leftover from the array notation thingie... let me check

borkdude 2024-09-04T13:56:46.567459Z

are you using the newest clj-kondo?

2024-09-04T13:57:14.606539Z

v2024.08.29

borkdude 2024-09-04T13:57:38.563319Z

I guess lsp is behind

2024-09-04T13:57:42.438839Z

$ clojure-lsp --version
clojure-lsp 2024.08.05-18.16.00
clj-kondo 2024.08.01

borkdude 2024-09-04T13:58:07.549589Z

"is there a way to run the newest clj-kondo with lsp"? yes

2024-09-04T13:59:02.448299Z

yeah, i've set it up in the past, just don't have it configured right now

2024-09-04T13:59:24.248189Z

i don't mind, i run both clj-kondo and clojure-lsp in my CI, just noticed in my editor this wasn't getting flagged

ericdallo 2024-09-04T13:59:50.115439Z

Just pushed this bump to clojure-lsp, should be a #clojure-lsp-builds nightly build soon

ericdallo 2024-09-04T14:00:17.165629Z

@nbtheduke any reason why not use in your CI clojure-lsp diagnostics ?

ericdallo 2024-09-04T14:00:31.877339Z

we are using for all Nubank services and it works great

ericdallo 2024-09-04T14:00:49.427729Z

(it adds the option to have clj-depend and other custom linters as well)

borkdude 2024-09-04T14:01:23.049489Z

btw @ericdallo can you bump to the latest master commit if you haven't? I fixed a post-release bug in there

ericdallo 2024-09-04T14:01:31.802239Z

ah ok

ericdallo 2024-09-04T14:04:39.998139Z

Done

István Karaszi 2024-09-04T14:08:53.828109Z

Is there a way to somehow ignore the callers from the test namespaces? I would like to get rid of the unused functions, but if the functions are covered, then those functions are excluded from the list.

✅ 1
István Karaszi 2025-03-31T10:14:01.809479Z

AFAICS the current implementation marks all the defs in all the test namespaces as unused

👀 1
István Karaszi 2025-03-31T16:05:48.687239Z

Because only test namespaces are referring to test defined functions and defs

István Karaszi 2025-03-31T16:06:12.541949Z

So I believe there the test references should not be excluded

André Camargo 2025-03-31T19:54:45.663219Z

gotcha, I was able to create a test scenario for this 😉 I'll have a look at it tomorrow, thanks for reporting it!

👍 1
🙏 1
André Camargo 2025-04-01T17:25:55.671109Z

reviewplease https://github.com/clojure-lsp/clojure-lsp/pull/2009

ericdallo 2025-04-01T20:28:09.427689Z

Merged, @ikaraszi could you test a nightly build later #clojure-lsp-builds and confirm it fixed for you?

André Camargo 2025-03-19T20:16:12.450589Z

@ikaraszi could you try https://github.com/clojure-lsp/clojure-lsp/pull/1992 branch?

István Karaszi 2025-03-19T21:10:45.940359Z

Thank you, I’ll try it. I didn’t have performance issues, so I can only test the functionality

István Karaszi 2025-03-19T21:12:29.698159Z

So the string/includes? vs string/ends_with? was the culprit?

István Karaszi 2025-03-19T21:14:16.036989Z

AFAICS this wont support cljs, right?

ericdallo 2025-03-17T12:28:37.616369Z

@andreribeirocamargo may have it, I don't remember exactly how we repro the problem when we found the regression, we should have commented on the issue

André Camargo 2025-03-17T16:32:45.354469Z

Hello, it was taking longer on some big internal Nubank projects. I'll have a look at this again and let's see how it goes.

👍 1
André Camargo 2025-03-20T10:22:42.113469Z

> So the string/includes? vs string/ends_with? was the culprit? no, the first algorithm is more resource-intensive than the new one. > AFAICS this wont support cljs, right? yes, it won't. is this an issue for you?

István Karaszi 2025-03-20T10:28:28.674929Z

> yes, it won’t. is this an issue for you? That is not an issue for me, just thought it is worth to mention

István Karaszi 2025-03-20T10:28:39.672949Z

Anyhow, I’ll give it a try

André Camargo 2025-03-20T17:20:20.040569Z

reviewplease https://github.com/clojure-lsp/clojure-lsp/pull/1994

ericdallo 2025-03-20T17:21:21.937039Z

@andreribeirocamargo remember to update all-available-settings.edn

André Camargo 2025-03-20T17:24:28.314739Z

What should I change there? There's no :clojure-lsp/unused-public-var linter configuration there 🤔

ericdallo 2025-03-20T17:24:50.236589Z

hum, true, that only applies for clojure-lsp settings, nvm

ericdallo 2025-03-20T17:26:36.542519Z

I wonder if we should move this setting to clojure-lsp settings itself... as there are other features that need to know if file is a test, the code lens for example to know if show a reference as a test or not

André Camargo 2025-03-20T17:35:23.055999Z

I like the idea, let's think more about this

André Camargo 2025-03-20T20:54:59.037539Z

I've made some changes to the PR in order to implement this vision

👍 1
István Karaszi 2024-09-04T14:10:25.258969Z

I can modify the settings and set the :source-paths to #{"src"}, but I was thinking a more convenient way to do this

ericdallo 2024-09-04T14:17:56.412919Z

https://clojure-lsp.io/settings/#clojure-lspunused-public-var You can use :exclude-when-defined-by or maybe :exclude

ericdallo 2024-09-04T14:18:40.314909Z

the main issue is: there is no canonical way to know if a function is using in a test, we can only infer that

István Karaszi 2024-09-04T14:22:20.640059Z

Yes, I understand that part. So I could do:

:exclude-regex #{"my-ns/.*-test$"}

ericdallo 2024-09-04T14:23:29.452799Z

Yeah, I guess Maybe we could have a option for that since we already infer those for code lens

István Karaszi 2024-09-04T14:23:53.225739Z

That would be great

ericdallo 2024-09-04T14:26:13.919179Z

Please create a issue so I can prioritize and discuss further more

István Karaszi 2024-09-04T14:26:27.862549Z

Thanks, doing it now

István Karaszi 2024-09-04T14:31:31.591319Z

https://github.com/clojure-lsp/clojure-lsp/issues/1878

István Karaszi 2024-09-04T15:10:35.046499Z

But this should work, right?

:clojure-lsp/unused-public-var {:level :warning
                                :exclude #{dev}
                                :exclude-regex #{".*?-test$"}}

ericdallo 2024-09-04T18:07:50.114439Z

Not sure about the regex, but looks correct

István Karaszi 2024-09-04T18:09:16.402499Z

I added the ? to turn off the greediness but I could not get it working

ericdallo 2024-09-04T18:11:09.528949Z

I didn't get that ? , shouldn't you use ".*-test$" to exclude everything that ends with -test ?

István Karaszi 2024-09-04T18:13:22.413919Z

I tried that as well, didn’t work.

István Karaszi 2024-09-04T18:13:29.782409Z

But I can try it again tomorrow

István Karaszi 2024-09-19T21:35:53.879069Z

It works like a charm! Thank you very much! 🙏

👍 1
István Karaszi 2024-09-05T08:05:12.448299Z

(re-matches #".*-test$" "foo.bar.something-test")
;; => "foo.bar.something-test"
user> (re-matches #".*?-test$" "foo.bar.something-test")
;; => "foo.bar.something-test"

István Karaszi 2024-09-05T08:05:27.339789Z

both of them are matching, but I’ll try to modify my config

István Karaszi 2024-09-05T08:48:46.800579Z

This is what I have in my .clj-kondo/config.edn:

:clojure-lsp/unused-public-var {:level :warning
                                :exclude #{dev}
                                :exclude-regex #{"metric.*-test.*"}}

István Karaszi 2024-09-05T09:45:24.495179Z

Okay, I believe I misunderstood the intention of the :exclude, it excludes the warnings in these namespaces, and not as I thought excludes the namespaces from the callers list.

István Karaszi 2024-09-05T09:45:35.733649Z

Then this is definitely a missing feature, I cannot have a workaround with a regex

ericdallo 2024-09-05T12:09:19.256519Z

Ah you are right, it's a different concept, maybe the flag should be: :disconsider-test-usages

István Karaszi 2024-09-05T12:24:53.222429Z

or maybe we can flip the logic by saying :include-tests false and per default it is true?

István Karaszi 2024-09-05T12:25:48.269639Z

but still it is orthogonal to the other exclude, so probably not the best choice

👍 1
ericdallo 2024-09-05T12:26:45.992579Z

I don't wanna change the default right now as there are lots of clients using this linter, but in the future it may be a good idea

István Karaszi 2024-09-05T12:26:59.744099Z

naming is hard, gosh

ericdallo 2024-09-05T12:27:09.111909Z

Yeah haha

István Karaszi 2024-09-05T12:28:27.065049Z

:ignore-tests true?

István Karaszi 2024-09-05T12:29:16.440459Z

or similar to your suggestion: :disregard-test-usages true

István Karaszi 2024-09-05T12:31:43.875969Z

“disconsider” is a rarely used word, probably that’s why it’s sounds strange to me

👍 1
István Karaszi 2025-03-14T15:26:48.726359Z

@ericdallo are you planning to bring back this feature?

ericdallo 2025-03-14T15:30:15.360419Z

sorry, what's the problem again?

István Karaszi 2025-03-14T15:34:46.007989Z

You know that you implemented an exclusion solution so references only by test namespaces did not show as usages

István Karaszi 2025-03-14T15:35:19.470609Z

And with this feature somebody could remove unused functions that only called from tests

István Karaszi 2025-03-14T15:35:59.110799Z

You needed to remove this feature in a later release because of a performance regression

ericdallo 2025-03-14T15:42:23.942179Z

Ah right, I lost your comment about reopening the issue, we still need to check how to implement it without losing performance

István Karaszi 2025-03-14T15:42:52.678919Z

Can I help in any ways?

ericdallo 2025-03-14T15:43:51.851189Z

well, you could try to re-implement https://github.com/clojure-lsp/clojure-lsp/commit/0f81895571bb1fb6fe77ca5746241942b17ab9d4 but try to improve the performance, unfortunately I don't have the answer on how to do it

István Karaszi 2025-03-14T15:49:00.184859Z

Thanks! I’ll check. I could only see this part which could be problematic: https://github.com/clojure-lsp/clojure-lsp/commit/0f81895571bb1fb6fe77ca5746241942b17ab9d4#diff-048949e9115a6b272d3aad1438dbd11269358c2198114ec28f23079cc3ecf422R268-R272

ericdallo 2025-03-14T16:20:11.983979Z

yes, maybe you could do a perf flamegraph to understand what is taking so long

István Karaszi 2025-04-02T07:05:30.846289Z

Yes, I’ll have time today. Thank you very much guys!

István Karaszi 2025-04-02T09:28:45.233309Z

Something is still off with:

clojure-lsp 2025.04.01-20.27.48-nightly
clj-kondo 2025.02.21-SNAPSHOT

André Camargo 2025-04-02T10:30:45.328319Z

My take is: the namespace metric.test-fixtures doesn't follow https://guide.clojure.style/#test-ns-naming of having a suffix -test, so Clojure-LSP is considering that code as application code. I'd rather suggest you to change :test-locations-regex in .lsp/config.edn from #{"_test\.clj[a-z]?$"} to #{"/test/metric/"} . This change will make Clojure-LSP to consider all files with "/test/metric/" in their path as test code. Ideally, you'd tailor the :test-locations-regex to reflect where the tests live (it's a Clojure set, you can have multiple regexes). Give it a try on this and let me know how it goes 😉

István Karaszi 2025-04-02T11:40:58.781769Z

Because that is a helper namespace that does not contain tests just functions that can be used in tests, but it is under the test folder. I’ll test the :test-locations-regex as you suggested.

István Karaszi 2025-04-02T11:44:37.845909Z

I believe it works! 🎉

André Camargo 2025-04-02T11:51:15.010769Z

Awesome! Clojure doesn't differentiate application from test code. That's why we have this convention of appending -test to test namespaces and functions. This also prevents clashing tests with application code. So Clojure-LSP relies on :test-locations-regex to understand what is test and what is not.

István Karaszi 2025-03-15T09:48:33.300669Z

do you have a repro?