hello,
i have issue with lsp reference navigation in clojurescript. It very stubbornly tries to navigate into compiled folder that has cljs copied files. This is extremely frustrating as one can guess.
I tried setting the ~/.config/clojure-lsp/config.edn with content:
{:paths-ignore-regex ["target.*"
"public/js/.*"
"js"
"ui/dev-resources/public/js/compiled/out/*"]
:source-paths-ignore-regex ["public/js/.*"
"js"
"ui/dev-resources/public/js/compiled/out/*"]}
to stop lsp from traversing there, but to no avail. The lsp-find-reference is also showing the compiled folder results before the actually correct source. How can i proceed with this issue?We had this problem multiple times in the past, and I think I solved adding the :source-paths-ignore-regex which the default value is ["target.*"] indeed to avoid your problem.
Make sure you don't have any target file opened - clojure-lsp lint opened files in editor, if you open target file it will lint (although not sure if with the source-paths-ignore-regex setting it should ignore it anyway).
Double check if your regex is correct, https://clojure-lsp.io/troubleshooting/#server-log the used source-paths when starting, check the server logs
If that's it's not working yet, please make a small cljs project repo where the problem does happen so I can try myself and understand the problem
will do. Just for my own sanity check, as i go a bit crazy by now, the source path i land in, that i never actually want to see is:
~/dev/my-project/ui/dev-resources/public/js/compiled/out/ui/component.cljs
What would a regex to exclude it look like? And is this the source-paths or paths-ignore setting?Let me check the config, it's been a while I don't look to that part of the code
Did a restart with config for lsp deleted and i get the same set of paths being read in, as per below message from server logs. Starts to look like the config files are not read in at all... Is there some easy way to make sure which config is read and that it indeed is processed? some trace/debug? or maybe just some simple and obvious setting that
2025-04-04T17:37:12.825Z INFO [clojure-lsp.source-paths:85] - [Startup] Using source-paths from classpath: ["/Users/karoladamiec/dev/fortum/madhouse/dev-resources" "/Users/karoladamiec/dev/my-project/palantir-resources" "/Users/karoladamiec/dev/my-project/test" "/Users/karoladamiec/dev/my-project/dev" "/Users/karoladamiec/dev/my-project/ui/resources" "/Users/karoladamiec/dev/my-project/ui/dev-resources" "/Users/karoladamiec/dev/my-project/ui/src" "/Users/karoladamiec/dev/my-project/resources" "/Users/karoladamiec/dev/my-project/src"]Can you try the config in .lsp/config.edn in the project root dir
The log for the config is a interesting suggestion we could add
ERROR [clojure-lsp.config:22] - WARNING: error while reading /Users/karoladamiec/dev/my-project/.lsp/config.edn (Map literal must contain an even number of forms)
ok, it does try to read it 😄
2025-04-04T17:49:23.478Z INFO [clojure-lsp.source-paths:85] - [Startup] Using source-paths from classpath: []
a small progress...
but then an ignore path in the form of .compiled. for sure should exclude files like
~/dev/my-project/ui/dev-resources/public/js/compiled/out/ui/sections/component.cljs
even did repl test and it does match that path...
(clojure.core/re-matches #".*compiled.*" "~/dev/my-project/ui/dev-resources/public/js/compiled/out/ui/sections/component.cljs")
(clojure.core/re-matches #".*compiled.*" "~/dev/my-project/ui/dev-resources/public/js/c/out/ui/sections/component.cljs")we check it https://github.com/clojure-lsp/clojure-lsp/blob/dfd4a0f5855f4ce245c523d6e0461a14f1b70141/lib/src/clojure_lsp/source_paths.clj#L77, with re-matches
thanks, will take a peek there, maybe even run it with local debug to actually see what is going on.
i have in my deps.edn following fragment:
:dev {:extra-paths ["dev" "dev-resources" "test" #_"ui/dev-resources"]
commenting out that extra path resolves the issue....so the problem is indeed clojure-lsp considering that ui/dev-resources source-path, you must exclude the whole source-path
yeah... also, maybe irrelevant but it is clojure project with cljs subproject. that UI folder is having another deps.edn for the clojurescripty parts... if that makes sense
in the end for clojure-lsp is a single one, the used source-path by clojure-lsp is the truth
is there some recursive reading of deps.edn having place in lsp server maybe? because in the ui/deps.edn we do again:
:extra-paths ["dev-resources"]clojure-lsp simplify does clj -A:dev:test -Spath to get the source-paths, run that on the root and you will see the outcome
i see. out of curiosity, why dev and test aliases? we scan the deps to find used aliases? EDIT: i see it it the linked source file so nvmind :)
anyways, thank You very much Eric for your time. Will experiment a bit over the weekend. 🙇
no problem, LMK if you find any bug on that, but almost sure it's a regex issue or something
ok, woke up this morning and i have reasonable take (i think) on what is going on.
So the paths in questions are filtered as-is. I.e. the regex pattern is filtering the ACTUAL path strings returned by clj -A:dev:test -Spath and not their possible path tree expansions on disk. So one can filter based on strings returned from above call, but not on their subpaths that actually happen to exist.
In any case, adding a regex that targets the actual values returned from above clj call helped in my case.
Still have not run the debug of lsp server though to verify that is the case.
But if it is, then i would guess this is not really how a layman thinks about this.... and is a bit confusing.
yeah, i confirmed this on debug session of clojure-lsp. @ericdallo so this is expected behaviour i guess?
so my current understanding is that the "source" variant of setting is loaded once on startup and is excluding the paths returned by clj -path command. It works with relative paths.
The :path-ignore-regex is run basically on every feature all the time, but in it, the path is absolute and not relative, so the regex patterns used better be flexible in the beginning to accommodate for this.
I.e i can not fathom how the default regex from documentation can work. my guess is it does not. ["target.*"]
to be fair, that regex example is at the :source-paths-ignore-regex setting variant listed as default (and example by proxy i guess) so all is good in theory.
sorry I think I got a littlbe bit lost, can you elaborate the cases with examples?
From my POV, :source-paths-ignore-regex should have regex to ignore source-paths dirs, like src/main/foo , and it should be relative to the project root. :path-ignore-regex indeed checks the full filename, maybe it should be relative too.
Even so, why those features aren't enough to fix your problem?
they are. they totally solve my problem. My mistakes were: • not understanding the difference in source-paths and paths • not understanding which parameter what "format" or "style" of path is working on.
makes really sense, I think we can mention that on the docs of those settings WDYT? willing to open a PR?
i think it would save me some time 🙂 Will prep a PR with some clarification around those settings, maybe with examples of what actually is matched by regex we write..
Is it possible to extend protocol function renaming to extend and extend-protocol and extend-type? I can rename a protocol function and get it changed at call-sites, but not in extend-* calls.