This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-29
Channels
- # announcements (44)
- # architecture (12)
- # babashka (45)
- # beginners (56)
- # calva (16)
- # cider (34)
- # clj-kondo (6)
- # clojure (47)
- # clojure-austin (2)
- # clojure-brasil (3)
- # clojure-europe (39)
- # clojure-germany (2)
- # clojure-nl (1)
- # clojure-norway (39)
- # clojurescript (7)
- # cursive (1)
- # datahike (2)
- # datomic (28)
- # emacs (8)
- # gratitude (3)
- # humbleui (4)
- # hyperfiddle (45)
- # kaocha (1)
- # lsp (94)
- # nbb (2)
- # off-topic (29)
- # practicalli (8)
- # releases (2)
- # shadow-cljs (6)
- # squint (17)
- # tools-deps (12)
- # vim (11)
Is it possible to run clojure-lsp/unused-public-var linter when running clj-kondo from a command line? I’d like to get the same level of warning regardless of CLI/editor.
In order to avoid unused-public-var linter warning I tried to modify a clj-kondo hook to generate a usage of a var defined by my macro but that didn’t affect the linter. Basically it was replacing my macro call with
(do
(declare unused-var)
(unused-var ...)
...)
Is this expected?Could you elaborate why you do that to avoid the linter? There are plenty settings to configure the linter to avoid false positives https://clojure-lsp.io/settings/#clojure-lspunused-public-var
One reason is that I want to co-locate macro and any configuration it requires. Another is that I didn’t manage to make it work yet. And third, I didn’t realize this linter is external to clj-kondo. So I assumed hook would cover the case.
Ideally I want to put these configs inside the macro body similar to:
(defmacro my-macro
{:clj-kondo/lint-as 'clojure.core/defn}
I think clj-kondo should support that config via code for custom linters like the ones from clojure-lsp, if not you can open an issue
I think there is a way to control how linters are applied to a particular file where a macro is used. But I don’t see how I can control how a linter should be applied to a particular macro. My wild guess would be that the linter should see what is specified in the attr-map of the macro and correct its behavior based on that.
Hello, I installed clojure-lsp in EndeavourOS from the AUR. When I run lsp in vterm (in Emacs, the terminal) it runs fine, but when I try to use it in Emacs normally (in a project) it stays stuck on starting and never runs. The error I get is simply Internal Error. Any idea what might be causing the issue?
Here are the clojure-lsp-server-logs, not sure how to get the buffer error:
2023-06-29T12:16:50.418Z INFO [clojure-lsp.server:596] - [SERVER] Starting server...
2023-06-29T12:16:50.423Z DEBUG [clojure-lsp.nrepl:21] - nrepl not found, skipping nrepl server start...
2023-06-29T12:16:50.429Z INFO [clojure-lsp.server:483] - Initializing...
2023-06-29T12:16:50.434Z ERROR [clojure-lsp.server:55] - Error receiving message: Internal error (-32603)
{:id 1, :method "initialize"}
com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine PosixPlatformThreads.java: 203
com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine PlatformThreads.java: 775
java.lang.Thread.run Thread.java: 829
java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java: 628
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java: 1128
...
clojure.core.async/thread-call/fn async.clj: 487
lsp4clj.server/thread-loop/fn server.clj: 121
lsp4clj.server/dispatch-input/fn server.clj: 174
lsp4clj.server.ChanServer/receive-request server.clj: 342
lsp4clj.server/pending-received-request server.clj: 236
...
clojure-lsp.server/fn server.clj: 493
clojure-lsp.handlers/initialize handlers.clj: 154
clojure-lsp.startup/initialize-project startup.clj: 187
clojure-lsp.config/resolve-for-root config.clj: 71
clojure-lsp.config/resolve-project-configs config.clj: 57
clojure-lsp.shared/uri->filename shared.clj: 222
clojure-lsp.shared/uri-obj->filepath shared.clj: 179
java.nio.file.Paths.get Paths.java: 97
java.nio.file.Path.of Path.java: 203
sun.nio.fs.UnixFileSystemProvider.getPath UnixFileSystemProvider.java: 103
sun.nio.fs.UnixUriUtils.fromUri UnixUriUtils.java: 87
java.lang.IllegalArgumentException: Bad escape
is it possible to provide a sample github project where that happens so I can try myself?
Also, check if you are using latest clojure-lsp, clojure-lsp --version
Here is the version: clojure-lsp 2023.05.04-19.38.01 clj-kondo 2023.04.15-SNAPSHOT
Do you want me to create a new github project and try there? Sadly I can't share the project I tried this in..
yeah, it's probably something with your project, maybe you can try if that happens in https://github.com/ericdallo/clojure-sample that I use to test things
Ah thank you very much, let me try it out!
It works fine in your project
@U05CWBL3BQX it's something with the project-root-uri as the exception happens https://github.com/clojure-lsp/clojure-lsp/blob/b318465bec4932b9e05ab1f2d6535c64441c07d0/lib/src/clojure_lsp/config.clj#L57, we can check what the client (emacs) is sending to the server
I see, it seems to be an issue on my end
Do I need to open the project.clj file then? Or is it internal to emacs?
While in the project, correct?
then seek for the initialize request, we want to know what is being sent in the project-root-uri
Thanks, let me try this
I think I know what the issue is!
The URI has Japanese kanji and it seems like UTF8 didn't work (or it wasn't encoded properly), so it gave me a bunch of nonsense
Here, let me paste it
[Trace - 02:29:10 午後] Sending request 'initialize - (7)'.
Params: {
"processId": 10099,
"rootPath": "/home/mayumin/Documents/Programming/文析",
"clientInfo": {
"name": "emacs",
"version": "GNU Emacs 28.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.36, cairo version 1.17.6)\n of 2023-01-03"
},
"rootUri": "file:///home/mayumin/Documents/Programming/%E6%96%87%E6%9E%90",
"capabilities": {
"general": {
"positionEncodings": [
"utf-32",
"utf-16"
]
},
I assume this is what interests us
It is displaying %...% instead of 文析 (the name of the folder)
Should I simply rewrite it in English?
I'm confused because the rootPath is set correctly...
Here's the other part of the logs that displays the error:
[Trace - 02:29:10 午後] Received notification '$/progress'.
Params: {
"token": "1",
"value": {
"kind": "begin",
"title": "clojure-lsp",
"percentage": 0
}
}
[Trace - 02:29:10 午後] Received response 'initialize - (7)' in 42ms.
Result: {
"code": -32603,
"message": "Internal error",
"data": {
"id": 7,
"method": "initialize"
}
}
I can send the full logs if necessary, let me know 🙂
yes, there is a huge chance that clojure-lsp code doesn't handle kenjis properly 🙃 I'd say to name it in english for now, you can open a issue on clojure-lsp to support that, I'm not sure how easy would be, I feel like we would face that issue in other places as well
Ahh this is fine then, I can live with it being written in English 🙂
ah, actually it may even be a lsp-mode bug, I think not using kenjis is the easiest way
Can I simply close emacs, rename the folder and restart emacs/lsp?
Thank you, let me see if that does it
Wonderful, it works!
Thank you very much, I'm glad we caught that 🙂
How can I print clj-kondo config for clojure-lsp diagnostics
command? I’m trying to configure clojure-lsp/unused-public-var
linter but it seems to ignore my settings - I tried both .clj-kondo/config.edn
and in namespace attr-map.
Hmm. :level :off
worked but not :exclude #{my-ns/my-macro}
.
Oops, I should’ve used instead :exclude-when-defined-by {my-ns/my-macro}
. My bad.
But that doesn’t work for me. I have :exclude
option working to disable the linter in a namespace, but :exclude-when-defined-by
with a specific macro name still triggers the warnings.
Here is a full example:
(ns demo
{:clj-kondo/config
'{:linters {:clojure-lsp/unused-public-var
{:exclude-when-defined-by #{demo/defabctest}}}}}
(:require
[clojure.test :refer [is deftest]]))
(defmacro defabctest
{:clj-kondo/lint-as 'clojure.core/defn}
[name [sym] & body]
`(deftest ~name
(let [~sym 5]
~@body)))
(defabctest my-test [x]
(is (= x 5)))
@UHS6PHL31 unused-public-var is a clj-kondo custom-linter defined by clojure-lsp, AFAIK there is a clj-kondo bug that doesn't handle clj-kondo configs in code for custom-linters
But it doesn’t work in config file too.
I tried
BTW, if your macro behaves like a deftest, you could lint-as clojure.test/deftest
as well
It doesn’t behave like deftest unfortunately, it has bindings like defn
.
When I use config file, :level
and :exclude
work but not :exclude-when-defined-by
.
Hmm, I can try a clean version - so far I was using calva’s clojure-lsp installation.
What’s your config file content?
Hmmm, I cloned it and it gives me this:
[100%] Project analyzed
Finding diagnostics...
test/clojure_sample/core_test.clj:11:1: warning: [redefined-var] redefined var #'clojure-sample.core-test/a-test
src/clojure_sample/client.clj:11:13: info: [clojure-lsp/unused-public-var] Unused public var 'clojure-sample.client/my-test'
$ clj-kondo --version
clj-kondo v2023.05.18
$ ~/.vscode/extensions/betterthantomorrow.calva-2.0.372/clojure-lsp --version
clojure-lsp 2023.05.04-19.38.01
clj-kondo 2023.04.15-SNAPSHOT
Installing a clean version of clojure-lsp now.
Same thing:
$ clojure-lsp --version
clojure-lsp 2023.05.04-19.38.01
clj-kondo 2023.04.15-SNAPSHOT
$ clojure-lsp diagnostics
[100%] Project analyzed
Finding diagnostics...
test/clojure_sample/core_test.clj:11:1: warning: [redefined-var] redefined var #'clojure-sample.core-test/a-test
src/clojure_sample/client.clj:11:13: info: [clojure-lsp/unused-public-var] Unused public var 'clojure-sample.client/my-test'
It also happening in VSCode + Calva
anyway, that's definitely a clojure-lsp bug, please open an issue so I can fix it later
Thanks, will do. Here is my screenshot.
@UHS6PHL31 I found out the issue doesn't happen in clojure-lsp master, but happens on latest release, so I suspect next release will fix it, could you confirm running a nightly clojure-lsp in Calva? (you can just type nightly
in calva clojure-lsp version setting)
Verified that it works in nightly
. Thanks!
But for my other macro it is still the issue. The pattern is the same - :level :off
works but :exclude-when-defined-by
and :exclude-when-defined-by-regex
do not work. I’ll need to spend a bit more time to come up with a reproducible test case.
Also, I’m wondering what’s happening with the hooks. Aren’t they affecting clojure-lsp
linter? I see hooks as the only tool that is capable of completely resolving all macro issues and I’m wondering whether it can be used to somehow instruct clojure-lsp linter to ignore public vars a particular macro generates.
yes, they can be related, we added to clj-kondo a option to defined a :defined-by in your hook, then clojure-lsp will use that when checking the exclude-when-defined-by, check how we did forhttps://github.com/nubank/state-flow/blob/master/resources/clj-kondo.exports/nubank/state-flow/nubank/state_flow.clj#L35
I finally got to look deeper at it. Now I see that when a macroexpand hook is configured with a macro, then clojure-lsp sees the hook-specified defining var (`def` or deftest
) but not the custom macro that does it. I’m checking if I this trick works for me but that currently requires to replace :macroexpand
hook with an :analyze-call
hook. Is there a way to support this with a :macroexpand
hook?
In other words, the :defined-by
trick for the nubank’s state flow you mentioned, makes the following definition for my similar example:
:defined-by a/defmytest,
:defined-by->lint-as clojure.core/defn,
Whereas without it all notion of the original macro a/defmytest
is gone.
:defined-by clojure.core/defn,
:defined-by->lint-as clojure.core/defn,
As I find :macroexpand
hooks much more user-friednly. Is it possible to support such a feature for them?Looking at https://github.com/clj-kondo/clj-kondo/blob/586bf972f55c87f75ad5787a7925f4b4fb4a674e/src/clj_kondo/impl/hooks.clj#L208 it seems that this is currently not setting :defined-by
but it might be possible to update the code to allow that.
Probably we can just add one more line here to make it work: :defined-by (symbol (name ns-sym) (name var-sym))
WDYT? @U04V15CAJ
Sure, I’ll open an issue with a good description.