One of my pet peeves is namespace management. I have a prototype to https://github.com/clojure-lsp/clojure-lsp/issues/1810, if no one is working on that now. (prototype action in thread, suggestions welcome)
This notices that clojure.string is in the require without an alias. When there's a use of the namespace in the code, clojure-lsp makes some suggestions for the alias and changes the :require and the expression
Question about dep-graph/ns-aliases-for-langs:
I'm calling it like this
(dep-graph/ns-aliases-for-langs db #{:clj})
It works fine if :dep-graph doesn't have any clojurescript files in it, or if the clojurescript and clojure namespaces are distinct.
But if I create some clojurescript files with namespaces that overlap with the clojure files, I found that it will return the namespace with a :usage-count including both the clojurescript and the clojure (despite me passing only #{:clj}).
Example, I have a test with xyz.cljs and xyz.clj that share the same namespace (http://my.ns.xyz). There's one clojurescript and one clojure file that references the respective namespace.
(h/reset-components!)
(h/load-code-and-locs "(ns )" "file:///xyz.cljs")
(h/load-code-and-locs "(ns )" "file:///xyz.clj")
(h/load-code-and-locs "(ns my.ns.b (:require [ :as xyz])))" "file:///b.clj")
(h/load-code-and-locs "(ns my.ns.c (:require [ :as xyz])))" "file:///c.cljs")
But
(dep-graph/ns-aliases-for-langs db #{:clj})
returns two usages
#{{:alias xyz, :to , :usages-count 2}}
Indeed, if I try looking for the dependencies by hand:
(get dep-graph ')
I see that both :clj and :cljs are there, but the count comes from both
{:aliases {xyz 2},
:aliases-breakdown {:external {}, :internal {xyz 2}},
:dependencies {cljs.core 1, clojure.core 1},
:dependents {my.ns.b 1, my.ns.c 1},
:dependents-internal? true,
:dependents-langs {:clj 1, :cljs 1},
:internal? true,
:uris #{"file:///xyz.clj" "file:///xyz.cljs"}}
Looking quickly at the code, it seems like if there's a language match in :dependents-langs, it uses the count in :aliases. I'm thinking it might want to add the matches in :dependents-langs instead.
Can I assume this is a bug?(albeit a minor bug! 🐜 )
at this point, if there is no test for it, probably a bug, I already touched those things so many times in the past but always add a test to fix or ensure a behavior. one thing crossed my mind: how common is this? I mean, is it common to have a classpath with both cljs + clj and equal namespaces? I'm no cljs heavy user so not sure
I would imagine that it isn't common to have similar classpaths. I only happened across this when my tests failed on the count for cases when that happens. I'll see if I can fix it myself, but won't bother filing a github issue unless I can find the fix. (But maybe it would be worth documenting what's going on if it isn't fixed.)
I have a prototype to collect a per-alias-per-language count, but it does add one line to the data collection in dep-graph/update-usage to collect that extra data
(update-in [:dep-graph name :aliases-by-lang alias] f (first usage-langs))
I'm not sure it's worth it, since the count only kinda needs to be directionally correct in this case. Instead, in the https://github.com/clojure-lsp/clojure-lsp/pull/2417 I just added some documentation that the count may be inflated.I know how to turn off (and customize) clj-kondo lint warnings, but how/where do I do similar config changes for LSP-level, project-wide lint warnings (such as unused public var)?
at .lsp/config.edn
more about it https://clojure-lsp.io/settings/#diagnostics-linter, seek for clojure-lsp/unused-public-var
Ah, perfect! Thanks.