Add Java runtimes for eglot and a maven build command

This commit is contained in:
Jeremy Dormitzer 2023-04-17 12:49:33 -04:00
parent fb7f98e4fd
commit 8c2ae4093c

View File

@ -42,9 +42,15 @@
'(("vscode-html-language-server" "--stdio")
("html-languageserver" "--stdio")))))
;; Support jdtls' ability to jump into class files
(add-to-list 'eglot-server-programs '(java-mode . ("jdtls" :initializationOptions
(:extendedClientCapabilities
(:classFileContentsSupport t)))))
(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)]))))
(defun jdt-class-file-name-handler (operation &rest args)
"File name handler for jdtls' `jdt://' URIs."
(cond
@ -102,6 +108,20 @@
(setq eglot-extend-to-xref t)
(add-to-list 'file-name-handler-alist '("\\`jdt://" . jdt-class-file-name-handler))
(add-to-list 'auto-mode-alist '("\\`jdt://" . java-mode))
;; Java build command
(defun eglot-java-maven-build ()
(interactive)
(if-let ((pom-path (locate-dominating-file default-directory "pom.xml")))
(let ((pom-uri (eglot--path-to-uri pom-path)))
(jsonrpc-notify
(eglot--current-server-or-lose)
:java/projectConfigurationUpdate
(list :uri pom-uri))
(jsonrpc-notify
(eglot--current-server-or-lose)
:java/buildWorkspace
'((:json-false))))
(user-error "This doesn't appear to be a Maven project, could not find pom.xml.")))
:init
(defvar eglot-prefix-map (make-sparse-keymap)
"Prefix keymap for eglot commands.")