Skip to content

Commit b7fa0b7

Browse files
lsp-volar: improve typescript plugin configuration (#4914)
- allow to specify a manual location of vue package - improve automatic detection by adding a second method that works if vue-language-server is installed by npm and made available in PATH by a symlink
1 parent 9e5d8d1 commit b7fa0b7

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

clients/lsp-volar.el

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ Reference: https://github.com/vuejs/language-tools/discussions/5455"
5757
:package-version '(lsp-mode . "9.0.1")
5858
:type 'boolean)
5959

60+
(defcustom lsp-volar-location-for-typescript-plugin :auto
61+
"Location of vue package used by typescript plugin.
62+
Specify a manual value if automatic detection does not work."
63+
:group 'lsp-volar
64+
:package-version '(lsp-mode . "9.0.1")
65+
:type '(choice (const :tag "Automatic detection" :auto)
66+
(directory :tag "Manual value")))
67+
6068
(defun lsp-volar--activate-p (filename &optional _)
6169
"Check if the volar-language-server should be enabled base on FILENAME."
6270
(and filename (string-suffix-p ".vue" filename)))
@@ -67,16 +75,19 @@ Reference: https://github.com/vuejs/language-tools/discussions/5455"
6775
:version (lambda () (when lsp-volar-support-vue2 "~3.0"))))
6876

6977
;; Set lsp-clients-typescript-plugins
70-
(condition-case nil
71-
(when-let* ((vue-language-server-path (lsp-package-path 'volar-language-server)))
72-
(let ((vue-plugin (list :name "@vue/typescript-plugin"
73-
:location (f-join vue-language-server-path "../.." "lib/node_modules/@vue/language-server/")
74-
:languages (vector "vue")
75-
:configNamespace "typescript"
76-
:enableForWorkspaceTypeScriptVersions t)))
77-
(setq lsp-clients-typescript-plugins
78-
(vconcat lsp-clients-typescript-plugins (vector vue-plugin)))))
79-
(error nil))
78+
(when-let* ((package-path (ignore-errors (lsp-package-path 'volar-language-server)))
79+
(location (if (eq lsp-volar-location-for-typescript-plugin :auto)
80+
(cl-find-if #'file-directory-p
81+
`(,(f-join package-path "../.." "lib/node_modules/@vue/language-server/")
82+
,(f-join (file-chase-links package-path) "../../")))
83+
lsp-volar-location-for-typescript-plugin))
84+
(vue-plugin (list :name "@vue/typescript-plugin"
85+
:location location
86+
:languages (vector "vue")
87+
:configNamespace "typescript"
88+
:enableForWorkspaceTypeScriptVersions t)))
89+
(setq lsp-clients-typescript-plugins
90+
(vconcat lsp-clients-typescript-plugins (vector vue-plugin))))
8091

8192
(defun lsp-volar--send-notify (workspace method params)
8293
"Send notification to WORKSPACE with METHOD PARAMS."

0 commit comments

Comments
 (0)