66; ; Author: Shen, Jen-Chieh <[email protected] >77; ; URL: https://github.com/emacs-languagetool/lsp-ltex
88; ; Version: 0.2.1
9- ; ; Package-Requires: ((emacs "26 .1") (lsp-mode "6.1"))
9+ ; ; Package-Requires: ((emacs "27 .1") (lsp-mode "6.1"))
1010; ; Keywords: convenience lsp languagetool checker
1111
1212; ; This file is NOT part of GNU Emacs.
@@ -264,13 +264,19 @@ This is use to unzip the language server files."
264264This is use to active language server and check if language server's existence."
265265 (expand-file-name " latest" lsp-ltex-server-store-path))
266266
267+ (defun lsp-ltex--store-locally-p ()
268+ " Return non-nil if language server is installed locally."
269+ (and (string-prefix-p lsp-server-install-dir lsp-ltex-server-store-path)
270+ (file-directory-p lsp-ltex-server-store-path)))
271+
267272(defun lsp-ltex--current-version ()
268273 " Return the current version of LTEX."
269- (when (file-directory-p lsp-ltex-server-store-path)
270- (when-let* ((gz-files (directory-files-recursively lsp-ltex-server-store-path " \\ .gz" ))
271- (tar (car gz-files))
272- (fn (file-name-nondirectory (lsp-ltex--s-replace " .tar.gz" " " tar))))
273- (lsp-ltex--s-replace " ltex-ls-" " " fn))))
274+ (if (lsp-ltex--store-locally-p)
275+ (when-let* ((gz-files (directory-files-recursively lsp-ltex-server-store-path " \\ .gz" ))
276+ (tar (car gz-files))
277+ (fn (file-name-nondirectory (lsp-ltex--s-replace " .tar.gz" " " tar))))
278+ (lsp-ltex--s-replace " ltex-ls-" " " fn))
279+ (ignore-errors (gethash " ltex-ls" (json-parse-string (shell-command-to-string " ltex-ls -V" ))))))
274280
275281(defun lsp-ltex--latest-version ()
276282 " Return the latest version from remote repository."
@@ -290,7 +296,7 @@ This is use to active language server and check if language server's existence."
290296 'ltex-ls
291297 '(:system " ltex-ls" )
292298 `(:download :url , lsp-ltex--server-download-url
293- :store-path ,(lsp-ltex--downloaded-extension-path))))
299+ :store-path ,(lsp-ltex--downloaded-extension-path))))
294300
295301(defcustom lsp-ltex-version (or (lsp-ltex--current-version)
296302 (lsp-ltex--latest-version)
@@ -346,11 +352,13 @@ If current server not found, install it then."
346352 " Return the server entry file.
347353
348354This file is use to activate the language server."
349- (concat (file-name-as-directory (lsp-ltex--extension-root))
350- (file-name-as-directory " bin" )
351- (if (eq system-type 'windows-nt )
352- " ltex-ls.bat"
353- " ltex-ls" )))
355+ (if (lsp-ltex--store-locally-p)
356+ (concat (file-name-as-directory (lsp-ltex--extension-root))
357+ (file-name-as-directory " bin" )
358+ (if (eq system-type 'windows-nt )
359+ " ltex-ls.bat"
360+ " ltex-ls" ))
361+ (executable-find " ltex-ls" )))
354362
355363(defun lsp-ltex--server-command ()
356364 " Startup command for LTEX language server."
@@ -390,7 +398,7 @@ This file is use to activate the language server."
390398 (make-lsp-client
391399 :new-connection (lsp-stdio-connection
392400 #'lsp-ltex--server-command
393- (lambda () (file-exists-p (lsp-ltex--extension-root ))))
401+ (lambda () (and ( file-executable-p (lsp-ltex--server-entry)) ( file- exists-p (lsp-ltex--server-entry) ))))
394402 :activation-fn (lambda (&rest _ ) (apply #'derived-mode-p lsp-ltex-active-modes))
395403 :priority -2
396404 :add-on? t
0 commit comments