From c82bf5510298bcc6694fc2fa0154d375d1df66fa Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Mon, 1 May 2023 10:13:43 -0400 Subject: [PATCH] Fix eglot-java contact settings, and add ability to set java agent --- emacs/.emacs.d/config/init-ide.el | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/emacs/.emacs.d/config/init-ide.el b/emacs/.emacs.d/config/init-ide.el index 968c419..6bee9d1 100644 --- a/emacs/.emacs.d/config/init-ide.el +++ b/emacs/.emacs.d/config/init-ide.el @@ -52,20 +52,28 @@ `(html-web-mode . ,(eglot-alternatives '(("vscode-html-language-server" "--stdio") ("html-languageserver" "--stdio"))))) + (defvar eglot-java-java-agent nil + "Java agent JVM arg for eglot JDTLS.") ;; 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 . - (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)]))))) + (defun eglot-java-contact (&optional interactive) + `(eglot-java-server . + ("jdtls" ,(if (s-blank? eglot-java-java-agent) + "" + (format "--jvm-arg=-javaagent:%s" eglot-java-java-agent)) + :initializationOptions + (:extendedClientCapabilities (:classFileContentsSupport t) + :settings + (:java + (:home "/Library/Java/JavaVirtualMachines/amazon-corretto-17.jdk/Contents/Home" + :configuration + (: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)]))))))) + (add-to-list 'eglot-server-programs '(java-mode . eglot-java-contact)) ;; Fix JDTLS's weird handling of workspaceEdit (cl-defmethod eglot-execute-command ((_server eglot-java-server) (_cmd (eql java.apply.workspaceEdit)) arguments)