aboutsummaryrefslogtreecommitdiffstats
path: root/lsp/svelte.lua
diff options
context:
space:
mode:
authorAlexis Tacnet <alexis@mistral.ai>2025-09-11 05:31:23 +0200
committerGitHub <noreply@github.com>2025-09-10 20:31:23 -0700
commitec54d14e0ad816e4099738a2b8f8e61ed3c9430e (patch)
tree32fc90c3593795e812ac54472756b59e8111ea9e /lsp/svelte.lua
parentdocs: update configs.md (diff)
downloadnvim-lspconfig-ec54d14e0ad816e4099738a2b8f8e61ed3c9430e.tar
nvim-lspconfig-ec54d14e0ad816e4099738a2b8f8e61ed3c9430e.tar.gz
nvim-lspconfig-ec54d14e0ad816e4099738a2b8f8e61ed3c9430e.tar.bz2
nvim-lspconfig-ec54d14e0ad816e4099738a2b8f8e61ed3c9430e.tar.lz
nvim-lspconfig-ec54d14e0ad816e4099738a2b8f8e61ed3c9430e.tar.xz
nvim-lspconfig-ec54d14e0ad816e4099738a2b8f8e61ed3c9430e.tar.zst
nvim-lspconfig-ec54d14e0ad816e4099738a2b8f8e61ed3c9430e.zip
fix: ts/js LSPs require lockfile #4062
Problem: Some projects don't have a lockfile. Solution: - Fallback to ".git" as a lower-priority root-marker (Nvim 0.11.3+). - Fallback to CWD.
Diffstat (limited to 'lsp/svelte.lua')
-rw-r--r--lsp/svelte.lua8
1 files changed, 6 insertions, 2 deletions
diff --git a/lsp/svelte.lua b/lsp/svelte.lua
index e7177991..53f3e73e 100644
--- a/lsp/svelte.lua
+++ b/lsp/svelte.lua
@@ -14,11 +14,15 @@ return {
cmd = { 'svelteserver', '--stdio' },
filetypes = { 'svelte' },
root_dir = function(bufnr, on_dir)
- local root_files = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
local fname = vim.api.nvim_buf_get_name(bufnr)
-- Svelte LSP only supports file:// schema. https://github.com/sveltejs/language-tools/issues/2777
if vim.uv.fs_stat(fname) ~= nil then
- on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1]))
+ local root_markers = { 'package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'bun.lockb', 'bun.lock', 'deno.lock' }
+ root_markers = vim.fn.has('nvim-0.11.3') == 1 and { root_markers, { '.git' } }
+ or vim.list_extend(root_markers, { '.git' })
+ -- We fallback to the current working directory if no project root is found
+ local project_root = vim.fs.root(bufnr, root_markers) or vim.fn.getcwd()
+ on_dir(project_root)
end
end,
on_attach = function(client, bufnr)