From ead0e33cc8f9a45163e805042c61fcb8c55c632e Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 14 Aug 2024 03:33:54 -0400 Subject: [PATCH] feat: Java support with Nix --- config.org | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/config.org b/config.org index 8ae8496..dc0bfc0 100644 --- a/config.org +++ b/config.org @@ -992,7 +992,7 @@ emacs-lisp ;;hy idris ;;json -;;(java +lsp) +(java +lsp +tree-sitter) ;;javascript ;;julia ;;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)))) #+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 #+call: confpkg("Mode: Yuck")