aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorAlexis Tacnet <alexistacnet@gmail.com>2025-04-28 14:11:00 +0200
committerGitHub <noreply@github.com>2025-04-28 05:11:00 -0700
commit9c6bbb5d1125491c7c7547e15188ae3e42647143 (patch)
treea1cbe79cc352595db07c188a577802e5aaab3630 /lua
parentci: check legacy configs *last* #3797 (diff)
downloadnvim-lspconfig-9c6bbb5d1125491c7c7547e15188ae3e42647143.tar
nvim-lspconfig-9c6bbb5d1125491c7c7547e15188ae3e42647143.tar.gz
nvim-lspconfig-9c6bbb5d1125491c7c7547e15188ae3e42647143.tar.bz2
nvim-lspconfig-9c6bbb5d1125491c7c7547e15188ae3e42647143.tar.lz
nvim-lspconfig-9c6bbb5d1125491c7c7547e15188ae3e42647143.tar.xz
nvim-lspconfig-9c6bbb5d1125491c7c7547e15188ae3e42647143.tar.zst
nvim-lspconfig-9c6bbb5d1125491c7c7547e15188ae3e42647143.zip
fix: improve typescript server path search for ts-dependent lsp #3795
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/configs/astro.lua7
-rw-r--r--lua/lspconfig/configs/mdx_analyzer.lua7
-rw-r--r--lua/lspconfig/configs/volar.lua7
-rw-r--r--lua/lspconfig/util.lua12
4 files changed, 15 insertions, 18 deletions
diff --git a/lua/lspconfig/configs/astro.lua b/lua/lspconfig/configs/astro.lua
index 106d247f..b979d711 100644
--- a/lua/lspconfig/configs/astro.lua
+++ b/lua/lspconfig/configs/astro.lua
@@ -1,10 +1,5 @@
local util = require 'lspconfig.util'
-local function get_typescript_server_path(root_dir)
- local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1])
- return project_root and (project_root .. '/node_modules/typescript/lib') or ''
-end
-
return {
default_config = {
cmd = { 'astro-ls', '--stdio' },
@@ -15,7 +10,7 @@ return {
},
on_new_config = function(new_config, new_root_dir)
if vim.tbl_get(new_config.init_options, 'typescript') and not new_config.init_options.typescript.tsdk then
- new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
+ new_config.init_options.typescript.tsdk = util.get_typescript_server_path(new_root_dir)
end
end,
},
diff --git a/lua/lspconfig/configs/mdx_analyzer.lua b/lua/lspconfig/configs/mdx_analyzer.lua
index 6ae65a2b..7c68cc81 100644
--- a/lua/lspconfig/configs/mdx_analyzer.lua
+++ b/lua/lspconfig/configs/mdx_analyzer.lua
@@ -1,10 +1,5 @@
local util = require 'lspconfig.util'
-local function get_typescript_server_path(root_dir)
- local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1])
- return project_root and (project_root .. '/node_modules/typescript/lib') or ''
-end
-
return {
default_config = {
cmd = { 'mdx-language-server', '--stdio' },
@@ -17,7 +12,7 @@ return {
},
on_new_config = function(new_config, new_root_dir)
if vim.tbl_get(new_config.init_options, 'typescript') and not new_config.init_options.typescript.tsdk then
- new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
+ new_config.init_options.typescript.tsdk = util.get_typescript_server_path(new_root_dir)
end
end,
},
diff --git a/lua/lspconfig/configs/volar.lua b/lua/lspconfig/configs/volar.lua
index ff52aed5..19070090 100644
--- a/lua/lspconfig/configs/volar.lua
+++ b/lua/lspconfig/configs/volar.lua
@@ -1,10 +1,5 @@
local util = require 'lspconfig.util'
-local function get_typescript_server_path(root_dir)
- local project_root = vim.fs.dirname(vim.fs.find('node_modules', { path = root_dir, upward = true })[1])
- return project_root and (project_root .. '/node_modules/typescript/lib') or ''
-end
-
-- https://github.com/vuejs/language-tools/blob/master/packages/language-server/lib/types.ts
local volar_init_options = {
typescript = {
@@ -24,7 +19,7 @@ return {
and new_config.init_options.typescript
and new_config.init_options.typescript.tsdk == ''
then
- new_config.init_options.typescript.tsdk = get_typescript_server_path(new_root_dir)
+ new_config.init_options.typescript.tsdk = util.get_typescript_server_path(new_root_dir)
end
end,
},
diff --git a/lua/lspconfig/util.lua b/lua/lspconfig/util.lua
index a8cf7439..2807edf3 100644
--- a/lua/lspconfig/util.lua
+++ b/lua/lspconfig/util.lua
@@ -69,6 +69,18 @@ function M.strip_archive_subpath(path)
return path
end
+function M.get_typescript_server_path(root_dir)
+ local project_roots = vim.fs.find('node_modules', { path = root_dir, upward = true, limit = math.huge })
+ for _, project_root in ipairs(project_roots) do
+ local typescript_path = project_root .. '/typescript'
+ local stat = vim.loop.fs_stat(typescript_path)
+ if stat and stat.type == 'directory' then
+ return typescript_path .. '/lib'
+ end
+ end
+ return ''
+end
+
---
---
---