@@ -46,6 +46,16 @@ The slash is expected at the end."
4646 :risky t
4747 :type 'directory )
4848
49+ (defcustom lsp-java-jdt-ls-prefer-native-command nil
50+ " Use native jdtls command provided by jdtls installation instead of lsp's java -jar invocation."
51+ :risky t
52+ :type 'boolean )
53+
54+ (defcustom lsp-java-jdt-ls-command " jdtls"
55+ " Native jdtls command provided by jdtls installation."
56+ :risky t
57+ :type 'string )
58+
4959(defcustom lsp-java-jdt-download-url " https://www.eclipse.org/downloads/download.php?file=/jdtls/milestones/1.23.0/jdt-language-server-1.23.0-202304271346.tar.gz"
5060 " JDT JS download url.
5161Use https://download.eclipse.org/jdtls/milestones/1.12.0/jdt-language-server-1.12.0-202206011637.tar.gz if you want to use older java version."
@@ -551,6 +561,13 @@ The entry point of the language server is in `lsp-java-server-install-dir'/plugi
551561 (server-jar-filenames
552562 (error " Unable to find single point of entry %s " server-jar-filenames))))
553563
564+ (defun lsp-java--locate-server-command ()
565+ " Return the jdtls command location of the language server.
566+
567+ The entry point of the language server is in `lsp-java-server-install-dir' /bin/jdtls[.bat]."
568+ (let ((bin-path (expand-file-name " bin" lsp-java-server-install-dir)))
569+ (locate-file lsp-java-jdt-ls-command `(, bin-path ) exec-suffixes 1 )))
570+
554571(defun lsp-java--locate-server-config ()
555572 " Return the server config based on OS."
556573 (let ((config (cond
@@ -652,27 +669,34 @@ FULL specify whether full or incremental build will be performed."
652669
653670(defun lsp-java--ls-command ()
654671 " LS startup command."
655- (let ((server-jar (lsp-file-local-name (lsp-java--locate-server-jar)))
656- (server-config (if lsp-java-server-config-dir
657- lsp-java-server-config-dir
658- (lsp-file-local-name (lsp-java--locate-server-config))))
659- (java-9-args (when (lsp-java--java-9-plus-p)
660- lsp-java-9-args)))
661- (lsp-java--ensure-dir lsp-java-workspace-dir)
662- `(, lsp-java-java-path
663- " -Declipse.application=org.eclipse.jdt.ls.core.id1"
664- " -Dosgi.bundles.defaultStartLevel=4"
665- " -Declipse.product=org.eclipse.jdt.ls.core.product"
666- " -Dlog.protocol=true"
667- " -Dlog.level=ALL"
668- ,@lsp-java-vmargs
669- " -jar"
670- , server-jar
671- " -configuration"
672- , server-config
673- " -data"
674- ,(lsp-file-local-name lsp-java-workspace-dir)
675- ,@java-9-args )))
672+ (let ((server-cmd (lsp-java--locate-server-command)))
673+ (if (and lsp-java-jdt-ls-prefer-native-command
674+ server-cmd)
675+ `(, server-cmd
676+ " --jvm-arg=-Dlog.protocol=true"
677+ " --jvm-arg=-Dlog.level=ALL"
678+ ,@(mapcar (lambda (str ) (concat " --jvm-arg=" str)) lsp-java-vmargs))
679+ (let ((server-jar (lsp-file-local-name (lsp-java--locate-server-jar)))
680+ (server-config (if lsp-java-server-config-dir
681+ lsp-java-server-config-dir
682+ (lsp-file-local-name (lsp-java--locate-server-config))))
683+ (java-9-args (when (lsp-java--java-9-plus-p)
684+ lsp-java-9-args)))
685+ (lsp-java--ensure-dir lsp-java-workspace-dir)
686+ `(, lsp-java-java-path
687+ " -Declipse.application=org.eclipse.jdt.ls.core.id1"
688+ " -Dosgi.bundles.defaultStartLevel=4"
689+ " -Declipse.product=org.eclipse.jdt.ls.core.product"
690+ " -Dlog.protocol=true"
691+ " -Dlog.level=ALL"
692+ ,@lsp-java-vmargs
693+ " -jar"
694+ , server-jar
695+ " -configuration"
696+ , server-config
697+ " -data"
698+ ,(lsp-file-local-name lsp-java-workspace-dir)
699+ ,@java-9-args )))))
676700
677701(eval-and-compile
678702 (lsp-interface
0 commit comments