Skip to content

Commit c00c164

Browse files
authored
Merge pull request #23 from emacs-languagetool/fix/install
fix(src): Allow globally installed language server
2 parents 7b94196 + 200776a commit c00c164

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
matrix:
1919
os: [ubuntu-latest, macos-latest, windows-latest]
2020
emacs-version:
21-
- 26.3
2221
- 27.2
2322
- 28.1
2423
- snapshot

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
1111
* Allow latest version return `nil` value if fails.
1212
* Fix server installation on Unix system (#20)
13+
* Allow globally installed language server (#23)
1314

1415
## 0.2.0
1516
> Released Aug 26, 2021

lsp-ltex.el

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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."
264264
This 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
348354
This 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

Comments
 (0)