Fork me on GitHub
#lsp
<
2022-10-28
>
Akiz08:10:22

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

ericdallo10:10:56

On doom-emacs usually this is just press K which shows eldoc buffer

ericdallo10:10:18

Remember to resolve the conflict of cider as well

Akiz10:10:37

I'll take a look what it does 👍

ericdallo10:10:15

Check conflict with cider

Akiz11:10:55

Are you talking about Documentation and clojuredocs integration? I see no conflicts there...

ericdallo11:10:59

Clojuredocs it's a plus that clojure-lsp adds to the docs, didn't you say you were having issues showing docs for functions?

Akiz11:10:51

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.

Akiz11:10:48

The cider X lsp integration is more about minibuffer, right?

ericdallo11:10:00

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

ericdallo11:10:20

Not there, maybe is a eldoc command

seancorfield23:10:19

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? 🧵

seancorfield23:10:02

First off, this setup has worked for me for quite a while but no longer works (after some LSP updates).

seancorfield23:10:24

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 ".."))))

seancorfield23:10:57

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}}}}}}

seancorfield23:10:25

Our project root is wsmain with it's .lsp folder. Our Clojure code is in wsmain/clojure

seancorfield23:10:50

We run the above with (cd clojure && clojure -T:sort-ns)

seancorfield23:10:20

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!

seancorfield23:10:14

Could the JDK 19 vs 18 be a cause? (I can test that I think)

seancorfield23:10:47

Nope, not that. Ran it with JDK 18 and got the same result.

seancorfield23:10:55

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.

seancorfield00:10:11

:verbose true showed me the problem -- the custom classpath.sh script I'm using to generate the classpath is no longer working... argh!

seancorfield00:10:45

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.

seancorfield00:10:57

Blew away wsmain/clojure/.cpcache and now everything is working 😕

ericdallo01:10:58

It's not the first time I see some caching issues with .cpcache

1
seancorfield22:10:34

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.

ericdallo22:10:20

Maybe it's a bug on cpcache, maybe check the classpath with clj -Spath which is what clojure-lsp does when starting the server

seancorfield22:10:29

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?

ericdallo22:10:49

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

borkdude22:10:18

Minor detail and probably not the issue here, but according to the docs, -Spath should go before -A...

ericdallo22:10:52

Interesting, I didn't know about it

ericdallo22:10:24

Actually, I think clojure-lsp's default adds -A before the -S path, but never received a issue about that

seancorfield22:10:16

I'll move -Spath up but if that were actually "wrong", I'd never get a classpath printed 🙂

ericdallo22:10:57

My guess would be a clj cache bug, I already had the same issue, but pretty rare

borkdude22:10:46

Newer versions of the clojure CLI are better about caching, especially the newest one, but you're probably already using that...

seancorfield22:10:08

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?

seancorfield22:10:41

Anyways, I'll keep an eye on it, but any suggestions about debugging it are welcome...

seancorfield22:10:55

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...

seancorfield22:10:12

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 ...

ericdallo23:10:25

It does fix just like other source-paths, probably the test is not in the source-path or classpath

ericdallo23:10:02

What happens if you go to the test ns in calva or emacs and calls clean-ns there? Does it clean as expected?

seancorfield23:10:16

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.

ericdallo00:11:11

Hum, weird, could you paste clojure-lsp server info?

seancorfield00:11:03

From where? What command? Remember I'm using this as a dependency and running it via -X...

ericdallo00:11:59

Not sure how to get on Calva, on emacs it's lsp-clojure-server-info

seancorfield00:11:46

What information are you after? I'm always using the latest clojure-lsp with Calva, and the latest Calva.

seancorfield00:11:15

(and what does that have to do with running clean-ns via the CLI and the clojure-lsp API?)

ericdallo00:11:41

That brings info about your project which should help understand the issue

ericdallo00:11:49

Try click on LSP icon on vscode

ericdallo00:11:57

It should have a command like server info

seancorfield00:11:10

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?

ericdallo00:11:31

Classpath, source-paths, source-aliases, settings

seancorfield00:11:57

1,000 lines of it...

seancorfield00:11:48

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.

ericdallo00:11:13

Looks fine, what test ns was not being cleaned?

seancorfield00:11:01

None of the test nses are being cleaned.

seancorfield00:11:33

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...

ericdallo00:11:32

Your wrapper looks good too

seancorfield00:11:54

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.

seancorfield00:11:25

If I run the calva/lsp clean NS command directly in that ns, it fixes the ordering.

ericdallo00:11:35

Pretty weird, a test source-path is just like any other source-path, no reason to clojure-lsp ignore only tests

ericdallo00:11:18

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

ericdallo00:11:36

Maybe just using a similar project arch with one test file

ericdallo00:11:42

And a src one

seancorfield00:11:50

I'll try to find some time tomorrow. I'm watching DWTS (live) right now and work is over for the day 🙂

seancorfield00:11:46

So there's no setting that would hide/skip -test$ nses?

ericdallo00:11:15

Nope, only for code lenses, nothing related with that

seancorfield00:11:20

Up until this discussion, I thought it was a "feature" that test nses were ignored by default for cleaning 😂

😹 3
1
seancorfield17:11:17

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...

ericdallo17:11:40

Great! makes sense, glad you found it

seancorfield21:11:11

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).

ericdallo21:11:15

In the end I think was worth replacing the custom script with clojure-lsp 😄

seancorfield21:11:21

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'
🤯

😨 1
seancorfield22:10:34

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.