Skip to content

Commit 09f548c

Browse files
authored
lsp-xml: add supports for native binary language server (#4396)
* lsp-xml: add supports for native binary language server * lsp-xml: convert lsp-xml-has-java? to function * lsp-xml-server-command: add type
1 parent 83cd9b8 commit 09f548c

File tree

1 file changed

+50
-6
lines changed

1 file changed

+50
-6
lines changed

clients/lsp-xml.el

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,18 @@ The value for `enabled' can be always, never or onValidSchema."
287287
("xml.catalogs" lsp-xml-catalogs)
288288
("xml.trace.server" lsp-xml-trace-server)))
289289

290+
(defcustom lsp-xml-prefer-jar t
291+
"Prefer using the jar file instead of the native binary."
292+
:type 'boolean
293+
:group 'lsp-xml
294+
:package-version '(lsp-mode . "8.0.2"))
295+
290296
(defconst lsp-xml-jar-version "0.27.0")
291297

292298
(defconst lsp-xml-jar-name "org.eclipse.lemminx-uber.jar")
293299

294300
(defcustom lsp-xml-jar-file (f-join lsp-server-install-dir "xmlls" lsp-xml-jar-name)
295301
"Xml server jar command."
296-
:type 'string
297302
:group 'lsp-xml
298303
:type 'file
299304
:package-version '(lsp-mode . "6.1"))
@@ -314,16 +319,53 @@ The value for `enabled' can be always, never or onValidSchema."
314319
`(:download :url lsp-xml-jar-download-url
315320
:store-path lsp-xml-jar-file))
316321

317-
(defcustom lsp-xml-server-command `("java" "-jar" ,lsp-xml-jar-file)
322+
(defconst lsp-xml-bin-base-name
323+
(format "lemminx-%s" (let ((arch (if (string-prefix-p "x86_64" system-configuration) "x86_64" "aarch_64")))
324+
(pcase system-type
325+
('darwin (format "osx-%s" arch))
326+
('gnu/linux "linux")
327+
('windows-nt "win32")))))
328+
329+
(defconst lsp-xml-bin-name (format "%s%s" lsp-xml-bin-base-name (if (eq system-type 'windows-nt) ".exe" "")))
330+
331+
(defcustom lsp-xml-bin-file (f-join lsp-server-install-dir "xmlls" lsp-xml-bin-name)
332+
"Xml server binary."
333+
:group 'lsp-xml
334+
:type 'file
335+
:package-version '(lsp-mode . "8.0.2"))
336+
337+
(defcustom lsp-xml-bin-download-url
338+
;; This is the version with `latest` tag
339+
(format "https://github.com/redhat-developer/vscode-xml/releases/download/latest/%s.zip"
340+
lsp-xml-bin-base-name)
341+
"Automatic download url for lsp-xml's native binary."
342+
:type 'string
343+
:group 'lsp-xml
344+
:package-version '(lsp-mode . "8.0.2"))
345+
346+
(lsp-dependency
347+
'xmlls-bin
348+
'(:system ,(file-name-nondirectory lsp-xml-bin-file))
349+
`(:download :url lsp-xml-bin-download-url
350+
:decompress :zip
351+
:store-path lsp-xml-bin-file))
352+
353+
(defsubst lsp-xml-has-java? () (executable-find "java"))
354+
355+
(defcustom lsp-xml-server-command
356+
(lambda () (or (and (lsp-xml-has-java?) lsp-xml-prefer-jar `("java" "-jar" ,lsp-xml-jar-file))
357+
`(,lsp-xml-bin-file)))
318358
"Xml server command."
319-
:type '(repeat string)
359+
:type '(choice (repeat string) (function))
320360
:group 'lsp-xml
321361
:package-version '(lsp-mode . "6.1"))
322362

323363
(defun lsp-xml--create-connection ()
364+
"Create a connection for the XML language server."
324365
(lsp-stdio-connection
325-
(lambda () lsp-xml-server-command)
326-
(lambda () (f-exists? lsp-xml-jar-file))))
366+
(lambda () (lsp-resolve-value lsp-xml-server-command))
367+
(lambda () (or (and (lsp-xml-has-java?) lsp-xml-prefer-jar (f-exists? lsp-xml-jar-file))
368+
(f-exists? lsp-xml-bin-file)))))
327369

328370
(lsp-register-client
329371
(make-lsp-client :new-connection (lsp-xml--create-connection)
@@ -335,7 +377,9 @@ The value for `enabled' can be always, never or onValidSchema."
335377
(with-lsp-workspace workspace
336378
(lsp--set-configuration (lsp-configuration-section "xml"))))
337379
:download-server-fn (lambda (_client callback error-callback _update?)
338-
(lsp-package-ensure 'xmlls callback error-callback))))
380+
(lsp-package-ensure (or (and (lsp-xml-has-java?) lsp-xml-prefer-jar 'xmlls)
381+
'xmlls-bin)
382+
callback error-callback))))
339383

340384
(lsp-consistency-check lsp-xml)
341385

0 commit comments

Comments
 (0)