-
With recent master, I was able to configure eglot to use jdtls, since this newest incarnation (version 1.6?) sports a nice startup script - which is still a bit weird to use btw. Until now, I've always used lsp-mode and lsp-java for it because that worked somehow with lots of features. But I want to get rid of this and find eglot less intrusive. Now, while some parts work - rudimentary formatting via eglot-format-buffer, I couldn't figure out how to make it use my custom code-format.xml. Here is my config:
However, it seems the server doesn't respect the code-format.xml and uses some default settings. I cannot see any error messages about the code-format.xml in any logs. Now I wonder, can I tell the server my settings using some other way? E.g. by using eglot-workspace-configuration? How would I do this? Has anyone here done this or can see what I did wrong in my configuration? I've thought about something like the following, though probably this is not correct:
The goal is to set the line split to 40 just to see if it works when executing eglot-format-buffer. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 4 replies
-
check for example: (defvar +eglot/initialization-options-map (make-hash-table :size 5))
(cl-defmethod eglot-initialization-options ((server eglot-lsp-server))
(if-let ((init-options (gethash (eglot--major-mode server) +eglot/initialization-options-map)))
init-options
eglot--{}))
(add-to-list 'eglot-server-programs
`(java-mode "jdtls"
"-configuration" ,(expand-file-name "cache/language-server/java/jdtls/config_linux" user-emacs-directory)
"-data" ,(expand-file-name "cache/java-workspace" user-emacs-directory)
,(concat "--jvm-arg=-javaagent:" (expand-file-name "~/.m2/repository/org/projectlombok/lombok/1.18.20/lombok-1.18.20.jar"))))
(puthash 'java-mode
`(:settings
(:java
(:configuration
(:runtime [(:name "JavaSE-1.8" :path "/usr/local/jdk-8")
(:name "JavaSE-11" :path "/usr/local/graalvm-ce-java11-22.0.0.2")
(:name "JavaSE-17" :path "/usr/local/graalvm-ce-java17-22.0.0.2" :default t)])
:format (:settings (:url ,(expand-file-name (locate-user-emacs-file "cache/eclipse-java-google-style.xml"))
:profile "GoogleStyle"))
;; NOTE: https://github.com/redhat-developer/vscode-java/issues/406#issuecomment-356303715
;; > We enabled it by default so that workspace-wide errors can be reported (eg. removing a public method in one class would cause compilation errors in other files consuming that method).
;; for large workspaces, it may make sense to be able to disable autobuild if it negatively impacts performance.
:autobuild (:enabled t)
;; https://github.com/dgileadi/vscode-java-decompiler
:contentProvider (:preferred "fernflower")))
;; WIP: support non standard LSP `java/classFileContents', `Location' items that have a `jdt://...' uri
;; https://github.com/eclipse/eclipse.jdt.ls/issues/1384
;; nvim impl demo: https://github.com/mfussenegger/dotfiles/commit/3cddf73cd43120da2655e2df6d79bdfd06697f0e
;; lsp-java impl demo: https://github.com/emacs-lsp/lsp-java/blob/master/lsp-java.el
:extendedClientCapabilities (:classFileContentsSupport t)
;; bundles: decompilers, etc.
;; https://github.com/dgileadi/dg.jdt.ls.decompiler
:bundles ,(let ((bundles-dir (expand-file-name (locate-user-emacs-file "cache/language-server/java/bundles" user-emacs-directory)))
jdtls-bundles)
(->> (when (file-directory-p bundles-dir)
(directory-files bundles-dir t "\\.jar$"))
(append jdtls-bundles)
(apply #'vector))))
+eglot/initialization-options-map) PS: I am also switching from lsp-mode to elgot and eglot gives me a feeling that it is much faster than lsp-mode (only tested in java). |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot! This helped me getting my setup working. What still does not work, however, is organizing imports. I get
But I guess this is a language server bug/incompatibility (perhaps eclipse-jdtls/eclipse.jdt.ls#376)? Or does the "organize imports" code action work for you? |
Beta Was this translation helpful? Give feedback.
-
It makes a difference, but instead of organizing the imports, it now seems to remove them. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hm. Maybe. I've downloaded the latest version of the jdtls. |
Beta Was this translation helpful? Give feedback.
-
On the other hand, these imports just don't seem to be necessary, so you might be correct. I'd thought one had to use action remove imports for removing unneeded imports, but apparently not. |
Beta Was this translation helpful? Give feedback.
-
I'll try with a better example. |
Beta Was this translation helpful? Give feedback.
-
Yes, it seems to remove (only) the unused imports. So it actually works correctly. Thanks. |
Beta Was this translation helpful? Give feedback.
check
eglot-initialization-options
.for example: