@@ -287,13 +287,18 @@ The value for `enabled' can be always, never or onValidSchema."
287
287
(" xml.catalogs" lsp-xml-catalogs)
288
288
(" xml.trace.server" lsp-xml-trace-server)))
289
289
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
+
290
296
(defconst lsp-xml-jar-version " 0.27.0" )
291
297
292
298
(defconst lsp-xml-jar-name " org.eclipse.lemminx-uber.jar" )
293
299
294
300
(defcustom lsp-xml-jar-file (f-join lsp-server-install-dir " xmlls" lsp-xml-jar-name)
295
301
" Xml server jar command."
296
- :type 'string
297
302
:group 'lsp-xml
298
303
:type 'file
299
304
:package-version '(lsp-mode . " 6.1" ))
@@ -314,16 +319,53 @@ The value for `enabled' can be always, never or onValidSchema."
314
319
`(:download :url lsp-xml-jar-download-url
315
320
:store-path lsp-xml-jar-file))
316
321
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 )))
318
358
" Xml server command."
319
- :type '(repeat string)
359
+ :type '(choice ( repeat string) ( function ) )
320
360
:group 'lsp-xml
321
361
:package-version '(lsp-mode . " 6.1" ))
322
362
323
363
(defun lsp-xml--create-connection ()
364
+ " Create a connection for the XML language server."
324
365
(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)))))
327
369
328
370
(lsp-register-client
329
371
(make-lsp-client :new-connection (lsp-xml--create-connection)
@@ -335,7 +377,9 @@ The value for `enabled' can be always, never or onValidSchema."
335
377
(with-lsp-workspace workspace
336
378
(lsp--set-configuration (lsp-configuration-section " xml" ))))
337
379
: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))))
339
383
340
384
(lsp-consistency-check lsp-xml)
341
385
0 commit comments