diff --git a/core/utils.py b/core/utils.py index 21e3774009..2186f7b0c7 100755 --- a/core/utils.py +++ b/core/utils.py @@ -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 diff --git a/langserver/astro-ls.json b/langserver/astro-ls.json index 6012e40c1b..29447d5f43 100644 --- a/langserver/astro-ls.json +++ b/langserver/astro-ls.json @@ -5,5 +5,10 @@ "astro-ls", "--stdio" ], - "settings": {} + "settings": {}, + "initializationOptions": { + "typescript": { + "tsdk": "%TSDK_PATH%" + } + } } diff --git a/langserver/volar.json b/langserver/volar.json index 2f212d5061..e703b603e6 100644 --- a/langserver/volar.json +++ b/langserver/volar.json @@ -9,7 +9,7 @@ "settings": {}, "initializationOptions": { "typescript": { - "tsdk": "/usr/lib/node_modules/typescript/lib" + "tsdk": "%TSDK_PATH%" }, "vue": { "hybridMode": false diff --git a/langserver/volar_darwin.json b/langserver/volar_darwin.json index 337f7b36a9..0c6db3d025 100644 --- a/langserver/volar_darwin.json +++ b/langserver/volar_darwin.json @@ -8,7 +8,7 @@ "settings": {}, "initializationOptions": { "typescript": { - "tsdk": "/usr/local/lib/node_modules/typescript/lib" + "tsdk": "%TSDK_PATH%" }, "vue": { "hybridMode": false diff --git a/lsp-bridge.el b/lsp-bridge.el index 9da4b8aea0..68742180ff 100644 --- a/lsp-bridge.el +++ b/lsp-bridge.el @@ -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) @@ -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.") @@ -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)))