fix(lsp-java): point jdtls to proper directory locations

Apparently, the per-project directory system I was using isn't supported
by the language server... even though there is absolutely no
documentation specifying that.
This commit is contained in:
Kiana Sheibani 2025-04-03 06:27:42 -04:00
parent 1b56e781c2
commit f9793c25a6
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -4219,15 +4219,26 @@ The =lsp-java= package provides LSP support using the standard Java language ser
(setq lsp-java-jdt-ls-prefer-native-command t))
(add-hook! java-mode
(setq-local lsp-java-server-install-dir
(concat (+lsp-java-server-store-path) "/share/java/jdtls/")))
(f-slash (+lsp-java-server-store-path))))
(defadvice! ~/lsp-java-ls-command ()
"Configure `lsp-java' to work with Nix."
:override #'lsp-java--ls-command
(let ((root (or (doom-project-root) (f-join (getenv "XDG_DATA_HOME") "jdtls"))))
(list lsp-java-jdt-ls-command
"-configuration" (f-join root "config-linux")
"-data" (f-join root "java-workspace"))))
;; The relative locations of the binary and jar file are different
;; on NixOS than on most other Linux distros
(defadvice! ~/lsp-java-locate-server-jar (old-fn)
:around #'lsp-java--locate-server-jar
(let ((lsp-java-server-install-dir
(concat lsp-java-server-install-dir "share/java/jdtls/")))
(funcall old-fn)))
#+end_src
*** Project File Conflict
Doom's standard library allows for an empty =.project= file to mark the root of a project directory. This is a decent idea, but unfortunately Gradle's project structure contains a file of that name that isn't necessarily at the root, and so this must be disabled to prevent Doom from breaking those projects.
#+begin_src emacs-lisp
(after! projectile
(setq projectile-project-root-files-bottom-up
(delete ".project" projectile-project-root-files-bottom-up)))
#+end_src
** Language Servers