Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option lsp-bridge-tsdk-path to setup tsserver lib #1108

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading