Skip to content

Commit

Permalink
Merge pull request #1108 from liuyinz/feat/add-tsdk-path-var
Browse files Browse the repository at this point in the history
add option lsp-bridge-tsdk-path to setup tsserver lib
  • Loading branch information
manateelazycat authored Nov 13, 2024
2 parents f110a0d + fec4301 commit d9647c1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ def replace_template(arg, project_path=None):
return arg.replace("%FILEHASH%", os.urandom(21).hex())
elif "%USERPROFILE%" in arg:
return arg.replace("%USERPROFILE%", windows_get_env_value("USERPROFILE"))
elif "%TSDK_PATH%" in arg:
return arg.replace("%TSDK_PATH%", get_emacs_func_result("get-user-tsdk-path"))
else:
return arg

Expand Down
7 changes: 6 additions & 1 deletion langserver/astro-ls.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"astro-ls",
"--stdio"
],
"settings": {}
"settings": {},
"initializationOptions": {
"typescript": {
"tsdk": "%TSDK_PATH%"
}
}
}
2 changes: 1 addition & 1 deletion langserver/volar.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"settings": {},
"initializationOptions": {
"typescript": {
"tsdk": "/usr/lib/node_modules/typescript/lib"
"tsdk": "%TSDK_PATH%"
},
"vue": {
"hybridMode": false
Expand Down
2 changes: 1 addition & 1 deletion langserver/volar_darwin.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"settings": {},
"initializationOptions": {
"typescript": {
"tsdk": "/usr/local/lib/node_modules/typescript/lib"
"tsdk": "%TSDK_PATH%"
},
"vue": {
"hybridMode": false
Expand Down
16 changes: 16 additions & 0 deletions lsp-bridge.el
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ LSP-Bridge will enable completion inside string literals."
(lsp-bridge-epc-define-method mngr 'get-multi-lang-server 'lsp-bridge--get-multi-lang-server-func)
(lsp-bridge-epc-define-method mngr 'get-single-lang-server 'lsp-bridge--get-single-lang-server-func)
(lsp-bridge-epc-define-method mngr 'get-user-emacs-directory 'lsp-bridge--user-emacs-directory-func)
(lsp-bridge-epc-define-method mngr 'get-user-tsdk-path 'lsp-bridge--user-tsdk-path-func)
(lsp-bridge-epc-define-method mngr 'get-buffer-content 'lsp-bridge--get-buffer-content-func)
(lsp-bridge-epc-define-method mngr 'get-current-line 'lsp-bridge--get-current-line-func)
(lsp-bridge-epc-define-method mngr 'get-ssh-password 'lsp-bridge--get-ssh-password-func)
Expand Down Expand Up @@ -514,6 +515,12 @@ Possible choices are basedpyright_ruff, pyright_ruff, pyright-background-analysi
"Default LSP server for XML, you can choose `lemminx', `camells'"
:type 'string)

(defcustom lsp-bridge-tsdk-path nil
"Tsserver lib*.d.ts directory path in current system needed by some lsp servers.
If nil, lsp-bridge would try to detect by default."
:type '(choice (const nil)
(string)))

(defcustom lsp-bridge-use-wenls-in-org-mode nil
"Use `wen' lsp server in org-mode, default is disable.")

Expand Down Expand Up @@ -1021,6 +1028,15 @@ So we build this macro to restore postion after code format."
"Get lang server with project path, file path or file extension."
(expand-file-name user-emacs-directory))

(defun lsp-bridge--user-tsdk-path-func ()
"Get tsserver lib*.d.ts directory path."
(when-let* (((null lsp-bridge-tsdk-path))
(bin (executable-find "tsc"))
(tsdk (expand-file-name "../../lib" (file-truename bin)))
((file-exists-p tsdk)))
(setq lsp-bridge-tsdk-path tsdk))
(or lsp-bridge-tsdk-path ""))

(defun lsp-bridge--get-buffer-content-func (buffer-name &optional no-org-babel)
"Get buffer content for lsp. BUFFER-NAME is name eval from (buffer-name)."
(when-let* ((buf (get-buffer buffer-name)))
Expand Down

0 comments on commit d9647c1

Please sign in to comment.