This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-28
Channels
- # announcements (5)
- # babashka (7)
- # beginners (101)
- # biff (9)
- # calva (46)
- # cider (6)
- # clj-yaml (2)
- # cljsrn (13)
- # clojure (11)
- # clojure-europe (43)
- # clojure-nl (13)
- # clojure-norway (22)
- # clojurescript (20)
- # conjure (1)
- # cursive (7)
- # data-science (2)
- # datomic (26)
- # emacs (38)
- # graphql (27)
- # gratitude (5)
- # hoplon (8)
- # hugsql (22)
- # humbleui (2)
- # hyperfiddle (6)
- # introduce-yourself (8)
- # joyride (3)
- # lsp (79)
- # malli (6)
- # nbb (67)
- # portal (16)
- # rdf (27)
- # reagent (42)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (36)
- # test-check (17)
- # tools-deps (1)
- # xtdb (15)
Hi, how can i use clojure-lsp to show docs? Locally i got only cider fns related to java or clojuredocs. Thx https://clojure-lsp.io/features/#documentation-and-clojuredocs-integration
Are you talking about Documentation and clojuredocs integration? I see no conflicts there...
Clojuredocs it's a plus that clojure-lsp adds to the docs, didn't you say you were having issues showing docs for functions?
I mean.. When running cider I can do something like C-c c-d d to display docs and I am looking for the same in lsp so I can display docs without running repl.
Yes, on doom, pressing K will get the docs and present in a buffer but not sure what is the exact emacs command for that
You may find it here: https://emacs-lsp.github.io/lsp-mode/page/keybindings/
SOLVED! Nothing to do with LSP -- somehow my .cpcache
folder got out of sync after a recent CLI update.
Have there been any changes to the clojure-lsp
API stuff that might prevent it from finding/sorting nses in :require
clauses? 🧵
First off, this setup has worked for me for quite a while but no longer works (after some LSP updates).
Second, I used this wrapper because I need to specify the project root:
(defn clean-ns!
"Run LSP's `clean-ns!` refactoring, controlled by
`:exec-args` settings in the main `deps.edn` file
under the `:sort-ns` alias."
[opts]
((requiring-resolve 'clojure-lsp.api/clean-ns!)
(assoc opts :project-root (io/file ".."))))
Here's the alias we use:
:sort-ns
{:replace-paths ["development/src"]
:replace-deps {com.github.clojure-lsp/clojure-lsp {:mvn/version "RELEASE"}}
:exec-fn ws.lsp/clean-ns!
:exec-args {:dry? false
:settings
{:clean
{:ns-inner-blocks-indentation :same-line
:ns-import-classes-indentation :same-line
:sort {:refer {:max-line-length 1}}}}}}
Our project root is wsmain
with it's .lsp
folder. Our Clojure code is in wsmain/clojure
We run the above with (cd clojure && clojure -T:sort-ns)
Here's what I see now:
(/Developer/workspace/wsmain)-(!2054)-> (cd clojure/ && clojure -T:sort-ns)
Reflection warning, clojure_lsp/handlers.clj:171:3 - call to static method sleep on java.lang.Thread can't be resolved (argument types: unknown).
... quite a few of those -- we're on JDK 19 which has introduced a new overload for `Thread/sleep` so type hints are needed now...
[100%] Project analyzed
Checking namespaces...
Nothing to clear!
Could the JDK 19 vs 18 be a cause? (I can test that I think)
Nope, not that. Ran it with JDK 18 and got the same result.
Tried it with a couple of older versions of clojure-lsp
back to 2022.07.24-18.25.43
and I'm getting the same result.
:verbose true
showed me the problem -- the custom classpath.sh
script I'm using to generate the classpath is no longer working... argh!
And that turned out to be due to something about my clojure/.cpcache
stuff being borked somehow and/or the recent update I made to my CLI scripts.
Blew away wsmain/clojure/.cpcache
and now everything is working 😕
The problem is back and it's happening "almost all the time". I have to blow away .lsp/.cache
and my .cpcache
folder and then it works for a while, but a short while later -- after making various file changes (and maybe me running some other process that may add to/update the .cpcache
folder?) -- it just stops being able to find files and detect changes it needs to make.
Maybe it's a bug on cpcache, maybe check the classpath with clj -Spath
which is what clojure-lsp does when starting the server
Well, as noted previously, because the :project-root
is my repo root -- because VS Code -- and my Clojure code is in <root>/clojure
I have this config for LSP:
{:project-specs [{:project-path "clojure/deps.edn"
:classpath-cmd ["build/bin/classpath.sh"]}]
:source-aliases #{:build :dev :everything :runner :test}}
and classpath.sh
is
#!/bin/sh
cd /Developer/workspace/wsmain/clojure
../build/clojure/bin/clojure -A:build:dev:everything:runner:test -Spath
So I could add -Sforce
to that, I guess if you think it would help?If you think would build a classpath consistent, sounds good, my guess is that something is building that wrong classpath, debugging that script may makes sense
Minor detail and probably not the issue here, but according to the docs, -Spath
should go before -A...
Actually, I think clojure-lsp's default adds -A before the -S path, but never received a issue about that
I'll move -Spath
up but if that were actually "wrong", I'd never get a classpath printed 🙂
Newer versions of the clojure CLI are better about caching, especially the newest one, but you're probably already using that...
I think it's only recently started happening so I wonder if it's at all related to some of the recent CLI/t.d.a changes?
Anyways, I'll keep an eye on it, but any suggestions about debugging it are welcome...
Just a sanity check: it doesn't clean test nses by default does it? When I add the verbose option, I see all the source paths have both src
and test
folders but if I have out-of-order requires in a test ns, it doesn't fix those, just the src
code...
Verbose output:
[INFO] [Startup] Using source-paths from classpath: ["/Developer/workspace/wsmain/clojure/wsbilling-test/test" "/Developer/workspace/wsmain/components/application-system/test" "/Developer/workspace/wsmain/bases/photo-queue-cli/test" "/Developer/workspace/wsmain/components/oauth-client/test" "/Developer/workspace/wsmain/clojure/bases/batch-jobs/src" ... very long list ...
It does fix just like other source-paths, probably the test is not in the source-path or classpath
What happens if you go to the test ns in calva or emacs and calls clean-ns there? Does it clean as expected?
Yes. And the classpath absolutely includes the test
folders: clojure -A:build:dev:everything:runner:test -Spath
-- :runner:test
bring in all test
folders explicitly.
From where? What command? Remember I'm using this as a dependency and running it via -X
...
What information are you after? I'm always using the latest clojure-lsp
with Calva, and the latest Calva.
(and what does that have to do with running clean-ns via the CLI and the clojure-lsp API?)
I no longer at work but I can try to pull it up on my laptop -- are you looking for the classpath output stuff or just the versions?
1,000 lines of it...
FWIW, my .cpcache
was messed up on my laptop too -- so I had to rm -rf .lsp/.cache && rm -rf clojure/.cpcache
to get this up and running.
None of the test nses are being cleaned.
I mean, it would take me a while to dig through and find a specific test ns that needs cleaning but I know there are plenty of them...
OK, I just reordered ws.error-reporter.test
so it needs cleaning and then ran (cd clojure && clojure -T:sort-ns)
and it did not see that ns needing cleaning.
If I run the calva/lsp clean NS command directly in that ns, it fixes the ordering.
Pretty weird, a test source-path is just like any other source-path, no reason to clojure-lsp ignore only tests
Could you try to create a simple repro for that? It may be a bug somewhere, but without a repro I can't debug and understand it better
I'll try to find some time tomorrow. I'm watching DWTS (live) right now and work is over for the day 🙂
So there's no setting that would hide/skip -test$
nses?
Up until this discussion, I thought it was a "feature" that test nses were ignored by default for cleaning 😂
OK, I discovered why test nses are not being cleaned... the classpath has relative paths to the test folders -- but they're relative to <root>/clojure
not <root>
so there's a mismatch between what LSP sees and what Clojure sees. The sources are found because they use :local/root
dependencies and those seem to resolve to absolute paths. I've futzed with my classpath.sh
shell script to turn all relative paths into absolute paths in the output (and, as it happens, de-duped some folders that showed up as both relative and absolute paths) and got
Cleared 198 namespaces
Wowza!
Unfortunately, this breaks a bunch of tests, because they use "interesting" macros that clj-kondo doesn't understand so it thinks a bunch of requires are unused and they get removed... so now I either need to adjust the classpath.sh to not make the /test
folders absolute (and leave the test nses "messy") or find and fix all of the macros that cause clj-kondo to "do the wrong thing" by adding hooks etc.
The latter will take time so I'll probably just fiddle with my classpath.sh script some more for now...3 hours later... all our test nses are nice and "clean" too -- and I only needed to add one hook for a macro (and change how another one was analyzed).
My custom classpath script now does this:
echo `../build/clojure/bin/clojure -Sforce -Spath -A:build:dev:everything:runner:test |
sed 's;:\([a-z]\);:/Developer/workspace/wsmain/clojure/\1;g' |
sed 's;^\([a-z]\);/Developer/workspace/wsmain/clojure/\1;' |
tr ':' '\n' | sort -u` | sed 's; ;:;g'
🤯The problem is back and it's happening "almost all the time". I have to blow away .lsp/.cache
and my .cpcache
folder and then it works for a while, but a short while later -- after making various file changes (and maybe me running some other process that may add to/update the .cpcache
folder?) -- it just stops being able to find files and detect changes it needs to make.