From ad28b2d2d188c5e73aa1fb9720e81b0f9586f907 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Tue, 18 Apr 2023 09:35:30 -0400 Subject: [PATCH] Fix eglot JDTLS workspaceEdit handling --- emacs/.emacs.d/config/init-ide.el | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/emacs/.emacs.d/config/init-ide.el b/emacs/.emacs.d/config/init-ide.el index f374d89..8dd12e2 100644 --- a/emacs/.emacs.d/config/init-ide.el +++ b/emacs/.emacs.d/config/init-ide.el @@ -41,16 +41,26 @@ `(html-web-mode . ,(eglot-alternatives '(("vscode-html-language-server" "--stdio") ("html-languageserver" "--stdio"))))) - ;; Support jdtls' ability to jump into class files + ;; Custom eglot java server for deeper customization + (defclass eglot-java-server (eglot-lsp-server) () + :documentation "Eglot integration with JDTLS.") (add-to-list 'eglot-server-programs - '(java-mode . ("jdtls" :initializationOptions - (:extendedClientCapabilities - (:classFileContentsSupport t) - :runtimes [(:name "JavaSE-11" - :path "/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk") - (:name "JavaSE-17" - :path "/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk" - :default t)])))) + '(java-mode . + (eglot-java-server . + ("jdtls" :initializationOptions + (:extendedClientCapabilities + (:classFileContentsSupport t) + :runtimes [(:name "JavaSE-11" + :path "/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk") + (:name "JavaSE-17" + :path "/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk" + :default t)]))))) + ;; Fix JDTLS's weird handling of workspaceEdit + (cl-defmethod eglot-execute-command + ((_server eglot-java-server) (_cmd (eql java.apply.workspaceEdit)) arguments) + "Eclipse JDT breaks spec and replies with edits as arguments." + (mapc #'eglot--apply-workspace-edit arguments)) + ;; Support jdtls' ability to jump into class files (defun jdt-class-file-name-handler (operation &rest args) "File name handler for jdtls' `jdt://' URIs." (cond