Skip to content

Commit 46df18d

Browse files
authored
Merge pull request emacs-lsp#57 from mahinshaw/java-9
Java 9+ options
2 parents 102d1ad + 0a29e89 commit 46df18d

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lsp-java.el

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ deduplication with the G1 Garbage collector"
7373
:risky t
7474
:type '(repeat string))
7575

76+
(defcustom lsp-java-9-args '("--add-modules=ALL-SYSTEM" "--add-opens java.base/java.util=ALL-UNNAMED" "--add-opens java.base/java.lang=ALL-UNNAMED")
77+
"Specifies arguments specific to java 9 and later."
78+
:group 'lsp-java
79+
:risky t
80+
:type '(repeat string))
81+
7682
(defcustom lsp-java-incomplete-classpath 'warning
7783
"Specifies the severity of the message when the classpath is incomplete for a Java file."
7884
:group 'lsp-java
@@ -308,11 +314,25 @@ FULL specify whether full or incremental build will be performed."
308314
(unless (file-directory-p path)
309315
(make-directory path)))
310316

317+
(defun lsp-java--get-java-version ()
318+
"Retrieve the java version from shell command."
319+
(let* ((java-version-output (shell-command-to-string (concat lsp-java-java-path " -version")))
320+
(version-string (nth 2 (split-string java-version-output))))
321+
(string-to-number (replace-regexp-in-string "\"" "" version-string))))
322+
323+
(defun lsp-java--java-9-plus-p ()
324+
"Check if java version is greater than or equal to 9."
325+
(let ((java-version (lsp-java--get-java-version)))
326+
(>= java-version 9)))
327+
311328
(defun lsp-java--ls-command ()
312329
"LS startup command."
313330
(let ((server-jar (lsp-java--locate-server-jar))
314331
(server-config (lsp-java--locate-server-config))
315-
(root-dir (lsp-java--get-root)))
332+
(root-dir (lsp-java--get-root))
333+
(java-9-args (if (lsp-java--java-9-plus-p)
334+
lsp-java-9-args
335+
'())))
316336
(lsp-java--ensure-dir lsp-java-workspace-dir)
317337
`(,lsp-java-java-path
318338
"-Declipse.application=org.eclipse.jdt.ls.core.id1"
@@ -326,7 +346,8 @@ FULL specify whether full or incremental build will be performed."
326346
"-configuration"
327347
,server-config
328348
"-data"
329-
,lsp-java-workspace-dir)))
349+
,lsp-java-workspace-dir
350+
,@java-9-args)))
330351

331352
(defun lsp-java--get-root ()
332353
"Retrieves the root directory of the java project root if available.

0 commit comments

Comments
 (0)