feat: Java support with Nix

This commit is contained in:
Kiana Sheibani 2024-08-14 03:33:54 -04:00
parent b57142a575
commit ead0e33cc8
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -992,7 +992,7 @@ emacs-lisp
;;hy ;;hy
idris idris
;;json ;;json
;;(java +lsp) (java +lsp +tree-sitter)
;;javascript ;;javascript
;;julia ;;julia
;;kotlin ;;kotlin
@ -3928,6 +3928,34 @@ Operators being in italics looks ugly in this mode too, but unfortunately due to
`(idris-semantic-postulate-face :foreground ,(doom-color 'yellow)))) `(idris-semantic-postulate-face :foreground ,(doom-color 'yellow))))
#+end_src #+end_src
** Java
The =lsp-java= package provides LSP support using the standard language server, the Eclipse-based ~jdtls~. Unfortunately, this package isn't designed for Nix, so it fails to find the server script in our Nix store. We need to do a bit of legwork to patch in this support, as well as some extra considerations, such as per-project config directories.
#+begin_src emacs-lisp
(defun +lsp-java-server-store-path ()
"Return the Nix store derivation path to the Java language server."
(string-remove-suffix
(concat "/bin/" lsp-java-jdt-ls-command)
(or
(executable-find lsp-java-jdt-ls-command)
(user-error "Could not find Java language server"))))
(after! java-mode
(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/")))
(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"))))
#+end_src
** Yuck ** Yuck
#+call: confpkg("Mode: Yuck") #+call: confpkg("Mode: Yuck")