This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-25
Channels
- # anglican (2)
- # babashka (53)
- # beginners (99)
- # brompton (1)
- # calva (28)
- # circleci (43)
- # clj-commons (4)
- # clj-kondo (176)
- # cljsrn (22)
- # clojars (7)
- # clojure (175)
- # clojure-australia (2)
- # clojure-europe (20)
- # clojure-germany (1)
- # clojure-uk (5)
- # clojurescript (195)
- # cursive (18)
- # datomic (13)
- # emacs (2)
- # farolero (9)
- # find-my-lib (6)
- # fulcro (8)
- # graalvm (12)
- # gratitude (5)
- # helix (11)
- # improve-getting-started (36)
- # introduce-yourself (3)
- # jackdaw (21)
- # jobs (2)
- # joker (2)
- # malli (65)
- # meander (24)
- # nbb (2)
- # off-topic (4)
- # pathom (2)
- # polylith (17)
- # portal (5)
- # react (3)
- # reagent (22)
- # releases (1)
- # ring (4)
- # shadow-cljs (79)
- # show-and-tell (2)
- # testing (5)
- # tools-deps (9)
- # xtdb (12)
Is there a place to track enhancement requests for clj-kondo
? I noticed that clj-kondo
stops warning about a private function which is not used if that function is overloaded.
Would be nice to not only retain the warning but perhaps highlight the specific functions which are not called.
@mafcocinco Do you mean, e.g., warning about the 2-arity not being used if there's a 1-arity version and it is used?
(trying to figure out what you mean by "overloaded")
As for issues/discussions: https://github.com/clj-kondo/clj-kondo
yes, overloaded on arity. And yes to your first comment, though it seems like it also a bug as the warning never shows up for any arity.
That might be a little hard to track effectively since apply
exists.
That is, you can't just track places the symbol is used anymore if you want to track which arity is being used.
(defn some-func
([a] [a])
([a b] [a b]))
(map some-func data-1 data-2)
In order for this to know that the 2-arity is being used but not the 1-arity, it has to know what map
does, which means we have to have special casing or do much more advanced static analysis. Special casing breaks down on user-defined functions, and advanced static analysis is probably outside the scope of clj-kondo.The only relatively easy way to solve this issue as far as I can tell would be to only use this linter if the only place the var is used is directly as a function call with a fixed number of arguments, but then the linter isn't very useful imo.
But whether or not that use is enough to warrant the implementation is up to the people who would implement it I guess.
Good points, yeah.
Hello! Do I need to do something special to enable Schema support in kondo? Currently it complains about "Unresolved symbol: User" here:
(require '[my.schemas :refer [User]] '[schema.core :as s])
(s/defn admin-user?
[user :- User]
...)
Update: This is weird, running clj-kondo manually works just fine. The error is shown in Cursive via LSPSchema support is built into clj-kondo. Your example works in my emacs + vanilla clj-kondo: Are you perhaps using clojure-lsp?
exactly, clojure-lsp in Cursive
https://www.dropbox.com/s/bgu9eglc8vezvnz/Screenshot%202021-08-25%20at%2015.30.53.png?dl=0 - it seems coming from LSP server
Very interesting. Could you make a zip of .clj-kondo/.cache and send it to me, if it doesn't contain any sensitive info? @UKFSJSM38 and me are trying to solve this issue for some time now
The workaround is to remove .clj-kondo/.cache and .lsp/sqlite.db and then restart your workspace, but we would love to have some data to debug
Is that the same issue of cache removals?
The User
seems to be a schema from the project itself, not external deps
btw, it's interesting you're using Cursive. I think it would be useful to have some docs around how to use clojure-lsp in cursive
I will send the zip later today. Do y have Keybase or what do you prefer? The schema is defined in another ns and required with :refer :all
But how goes kondo cache help? I've run kondo from CLI and that was just fine, I assume it used the cache. Since the problem only appears in kondo via lsp, you perhaps need (also).lsp (or, in the case of IntelliJ, there is also lsp (without dot))
.lsp/sqlite.db
is the folder used by clojure-lsp just for caching external analysis, when we remove it, clojure-lsp re scan the whole classpath again using clj-kondo (which should cache that on .clj-kondo/.cache as well)
@U0522TWDA the command line version only uses the cache created by the editor if both clj-kondo versions are exactly the same
good point, probably your clj-kondo cli version is different from the one used by clojure-lsp
No, both versions are the same
you can check is to see if there is only one recent .clj-kondo/.cache/* dir in there
Sorry 😢 I have restarted LSP from Cursive and it does not show the error anymore.
Good news! I deleted kondo cache and restarted LSP and re-opened the file and see the error again
interestingly, I do NOT have .clj-kondo/.cache/
in the project dir now
the only relevant thing I seem to have is ./lsp/
hum, even if your classpath is cached on .lsp/sqlite.db
, clojure-lsp calls clj-kondo to lint the project paths at every startup, then it should create a .clj-kondo/.cache
(only if you have a .clj-kondo
folder)
Me too. Now the problem is there even in CLI:
❯ java -jar ~/Downloads/clj-kondo-2021.08.06-standalone.jar --lint src/mine/core.clj
src/mine/core.clj:4:35: warning: use alias or :refer
src/mine/core.clj:38:12: error: Unresolved symbol: User
what makes sense because there is no cache, right @U04V15CAJ?
it looks like you're using :refer :all
or something (from the linter warning I can see that)
Correct, the .clj-kondo/
dir that I deleted recently has not been recreated by running the CLI.
@U04V15CAJ I'd love to but it is company property so I cannot really share more than snippets 😿
Yes, I am using refer all, I think I mentioned it above
@U0522TWDA probably you will be able to repro if create a new sample project with schema.core dep?
(ns
(:require [company.schemas :refer :all] ; User lives here
[schema.core :as s]))
(s/defn backoffice-user?
[user :- User]
...)
> you need to make LSP re-index your project
for clojure-lsp, removing .lsp/sqlite.db
or changing anything in your project.clj/deps.edn should work
ok, will try to make a repro repo later today. Thank you for all the support!
Ok, so if I have (:require [kondo-lsp-cursive-schema-problem.core :refer [User]])
then kondo is happy but if I change it to ...:refer :all
then it says "Unresolved symbol: User"
@U04V15CAJ do you want a .tbz of the whole project repo or is this a known problem?
a public repo on Github would be the best, otherwise a zip/tar.gz is enough as well
@U0522TWDA That example is expected to work like that, if you don't have a .clj-kondo/.cache with the namespace kondo-lsp-cursive-schema-problem.core
linted
but if you do have .clj-kondo/.cache
dir and then you lint that namespace, after that, it should work
Ah, I expected that if I open a new project, LSP would index it automatically. Obviously it did not
How do I get LSP to index anything? I changed a comment in project.clj but still not .clj-kondo ...
and when you have a .clj-kondo
dir, only then will clj-kondo store cache info there
I wonder if clojure-lsp should always create the .clj-kondo dir in the project. what do you think @U04V15CAJ?
> perhaps also put a `config.edn` there automatically with just an empty map
I suppose people would think that .clj-kondo/config.edn
should not be commited if we do that automatically 😕
Added the config there , cache created, problem persists. Both ns are indexed: kondo-lsp-cursive-schema-problem.core.transit.json kondo-lsp-cursive-schema-problem.schemas.transit.json
@U0522TWDA I don't think this repro makes sense. You are referring the same namespace with :refer :all from the namespace itself
(ns kondo-lsp-cursive-schema-problem.core
(:require
;[kondo-lsp-cursive-schema-problem.core :refer [User]]
[kondo-lsp-cursive-schema-problem.core :refer :all]
[schema.core :as s]))
> I suppose people would think that `.clj-kondo/config.edn` should not be commited if we do that automatically That is much less of a risk/inconvenience than the current state when linting does not work fully out of the box. (Of course we can blame the user - me - for not reading kondo docs and expecting stuff to just magically do what I want :))
OMG, sorry, typo
When I change it to [kondo-lsp-cursive-schema-problem.schemas :refer :all]
then it works for me
Right, when I fix the require, it works at once
> That is much less of a risk/inconvenience than the current state when linting does not work fully out of the box. (Of course we can blame the user - me - for not reading kondo docs and expecting stuff to just magically do what I want :))
But not creating that would not cause the issue, it was just a suggestion, the issue here is the .clj-kondo
folder creation
I think creating the config.edn is a nice addition: it suggests where people should store their config
In the repro, yes. At work it did/does exist. But when I open it, the cache has only files for very few namespaces, not including the .schemas one. Why could that be?
> I think creating the config.edn is a nice addition: it suggests where people should store their config we can do that I think, and re-think if anyone complains
> Why could that be?
Probably removing both .lsp/sqlite.db
and .clj-kondo/.cache
would solve
anything on clojure-lsp server log? https://clojure-lsp.github.io/clojure-lsp/troubleshooting/#server-log
I do see this:
$ ls .clj-kondo/.cache/2021.08.07-SNAPSHOT/clj
kondo-lsp-cursive-schema-problem.core.transit.json kondo-lsp-cursive-schema-problem.schemas.transit.json
which is what I would expectthe .schemas transit file does contain the User (thanks, jet
!)
there was no .clj-kondo dir, clojure-lsp called clj-kondo that linted classpath and lsp saved .lsp/sqlite.db
, but nothing saved on .clj-kondo/.cache
as the did was not there. After creating the .clj-kondo folder we need to re-scan the classpath to fulfill the clj-kondo cache folder, that's why removing .lsp/sqlite.db
should fixes it, WDYT?
not sure where the sqlite is in Cursive+LSP, I have no .lsp, only lsp/ that contains log/ and conf/clojure.json
yeah, ATM it's suggested that you use clojure-lsp at the mono root, not sure if clj-kondo caches would conflict from subproject to subproject though
The .lsp folder is created by clojure-lsp though. Perhaps it should be called .clojure-lsp? ;)
ok, let's ignore the mono-repo situation for now, I'm not using that myself in that way, perhaps an edge case to consider later
> The .lsp folder is created by clojure-lsp though. Perhaps it should be called .clojure-lsp? 😉 Yeah, there is a issue about that, we would need avoid the breaking changes, but it'd be the ideal indeed
Any idea why I do not have that repo created? Is it because the IntelliJ LSP plugin runs clojure-lsp in some other dir or something?
@U0522TWDA follow the https://clojure-lsp.github.io/clojure-lsp/troubleshooting/section, the server logs should help
both lsp/log/clojure_out_20210825.log
and _err_
are empty though
I don't think both logs are related with clojure-lsp:https://clojure-lsp.github.io/clojure-lsp/troubleshooting/#server-log
according to https://github.com/gtache/intellij-lsp#faq those files have, I assume, stdout and stderr from clojure-lsp. I will study clojure-lsp docs to figure out where its actual logs are.
I think the _err_
is the stderr from the clojure-lsp process, which unless a huge bug prints to that
what we want is the custom log from the server, which the plugin (since it's a generic intellij LSP plugin) doesn't know about it, unless the plugin explicitly integrates with, which is what Calva does
hm, the newest log I found was <
which is from yesterday and has last log from 2021-08-24T13:01:27.545Z
you can easily add {:log-path "/tmp/clojure-lsp.out"}
in your .lsp/sqlite.db
, this will help get the log from the sample place
Will do. I have killed the processes and a new clj-kondo-lsp-server-standalone.jar was started but no new logfile
Hm, I've created
❯ cat .lsp/config.edn
{ :log-path "/tmp/clojure-lsp-myapi.out"}
in the [project dir and LSP plugin - restart server, which started a new kondo-lsp-server process, but the log file did not get created
(and there is no sqlite.db in the freshly created .lsp dir)Can you use a different folder than tmp? (that's why it's not the default to use tmp, but java tmp folder, for persmisions issues, specially on macos)
I have done that now and restarted, still no log
Interesting, According to Activity Monitor's Open Files, it does not have any log file open. Also, its CWD is wrong (I have 4 projects open in IntelliJ and it is one of them but not the one which I am actively using now)
are you really using clojure-lsp? Can you check if there is a clojure-lsp process running?
No, it is not, only clj-kondo-lsp-server-standalone.jar
Does it not include clojure-lsp?
I followed these instructions https://github.com/clj-kondo/clj-kondo/blob/master/doc/editor-integration.md#lsp-server-1
You are using https://github.com/clj-kondo/clj-kondo.lsp, not https://clojure-lsp.github.io/clojure-lsp/
I am sorry, I am new to all this and do not distinguish properly between what is what 🤯
they both are LSP servers for clojure and both use clj-kondo, but they do things different
even so, it seems that the clj-kondo.lsp has the cache issue as well @U04V15CAJ 😂
I see now. Which one of the two should I use? I picked the one b/c that is what clj-kondo pointed me to...
I think clojure-lsp is the closest to Cursive, I'd suggest giving it a try https://clojure-lsp.github.io/clojure-lsp/installation/
Ok, thx! Then I will switch to clojure-lsp and see how that works. Still, I do not understand why it fails to resolve User in my case because I see the transit file for the schemas ns, which I would believe means that kondo has indexed it. Or?
It indexes it if you lint it manually on the command line in the presence of a .clj-kondo directory, or if you edit the file in your editor and it gets linted then (also in the presence of a .clj-kondo dir)
Ah, somehow it works here now as well. I guess it was some timing issue, with kondo's updated info not being propagated all the way via LSP to Cursive.
@mafcocinco @seancorfield about the private self-referring var that is not considered being unused: this warrants an issue I think, please make one
I think I figured out what is going on. Not sure if it is exactly a bug, but seems like it should be. Posting code in a moment
yes, that's what I mean, I think self-references should not count as usages for the unused private var linter
Given that using one arity of a multi-arity function as an implementation of another is as fairly common pattern, perhaps clj-kondo
should ignore the internal usages within the definition of the function?
I will add an issue.
seems like this should apply for all functions, not just private ones, no?
nvm, I suppose you don’t get the warning for public functions. 🐶
well, clojure-lsp does that but perhaps @UKFSJSM38 already took that into account
yeah, that's something to improve/fix on both unused-private-var and clojure-lsp/unused-public-var linters IMO, they consider the function internal usage
ok, I'll first improve the private one and perhaps the same logic can be applied to the public one. perhaps by adding a :self-ref true
or so on the usage
I just wonder if we should just fix the lint, but references and code lenses should still show those usages
Does anybody have the valid hook for shadow.markup.css/defstyled macro? 😄 Example:
(css/defstyled Container :div
[env]
{:position "absolute"
:bottom "24px"
:right "24px"})
Yep! It works! Thanks @U04V15CAJ ❤️