Fork me on GitHub
#lsp
<
2023-10-08
>
Matt LeVeck23:10:13

I could use some guidance on debugging why goto def in Neovim is not working for Java classes. I'll post in thread my minimal case, and what I've checked so far.

Matt LeVeck23:10:09

The code:

(ns mytest.mytest
 ( :import (java.io File)))

(File. "src/mytest/mytest.cl")
(str "foo" "bar")
deps.edn empty:
{}
What I expect based on my reading of the lsp docs: goto definition should work for both File. and str What happens instead: goto def works for str but not for File. What I've looked at: 1. I 'm running the latest version of the Clojure lsp : 2023.08.06-00.28.06 2. Should it find this based on my setup? I think so. File is a standard Java library. Java is on the shell path. So based on the https://clojure-lsp.io/settings/#java-support I think the lsp should be able to find the source. 3. I ran :LspLog and didn't see anything 4. But, I also ran :LspInfo and verified it's attached, and like I said above gotodef works for str

Matt LeVeck00:10:00

I also tried explicitly setting JAVA_HOME on the off chance that was the issue. But it did not change anything

Matt LeVeck00:10:41

And I verified the Java installation comes with src.zip

-rw-r--r--@ 1 matthewleveck  admin  53105940 Jun 14 01:03 /opt/homebrew/Cellar/openjdk/20.0.2/libexec/openjdk.jdk/Contents/Home/lib/src.zip

Matt LeVeck00:10:10

Ok... I have solved my issue. Will put the steps here in case this is useful to anyone in the future. 1. I noticed clojure-lsp docs say that upon finding src.zip under the directory specified by JAVA_HOME, it'll copy the sources into ~/.config/clojure-lsp. But that directory did not exist on my system. 2. I made the directory ~/.config/clojure-lsp. Deleted .lsp, .clj-kondo and .cp-cache under my project directory (this might not be necessary). Now goto def works for the java class File.

ericdallo00:10:24

Isnt't the source copied to ~/.cache/clojure-lsp? Also, you don't need to create that manually :thinking_face:

Matt LeVeck00:10:58

I'm not sure what you mean by "You don't need to create that manually". Do you mean /.cache/clojure-lsp, /.config/clojure-lsp?

Matt LeVeck00:10:13

Anyways, to answer your question if I check, it looks like there are are source files under ~/.cache/clojure-lsp/jdk/ . They're all very recent (after the steps above) so I have no way to know if some version of the files existed before I did the steps I described.

Matt LeVeck00:10:05

But, before creating ~/.config/clojure-lsp goto def was broken. After I created it, goto-def worked.

Matt LeVeck00:10:27

Interestingly, there is actually nothing under ~/.config/clojure-lsp

src/clj-lsp-test % ls -ltra ~/.config/clojure-lsp
total 0
drwxr-xr-x@  2 matthewleveck  staff   64 Oct  8 17:14 .
drwxr-xr-x@ 15 matthewleveck  staff  480 Oct  8 17:14 ..

Matt LeVeck00:10:47

If I:

rm -rf ~/.config/clojure-lsp
rm -rf ~/.cache/clojure-lsp/jdk
rm -rf .lsp
rm -rf .clj-condo
rm -rf .cp-cache
And then open the source file. What would you expect the behavior to be?

Matt LeVeck01:10:03

Btw, if you're confused about why I was messing around with /.config and not /.cache it's because the https://clojure-lsp.io/settings/#java-support say:

Most JRE installations contains the java source code in a src.zip, clojure-lsp tries to find it via :java :home-path setting if provided, JAVA_HOME env var or java command on PATH, if found clojure-lsp extracts to its global cache config (XDG_CONFIG or ~/.config/clojure-lsp) to be used in other projects.
and env var XDG_CONFIG isn't set in my shell.

ericdallo12:10:48

Docs fixed

thanks3 1