From 970f77614f92952ef7b050a2a4bf89926a024f6d Mon Sep 17 00:00:00 2001 From: Igor Date: Tue, 10 Jun 2025 20:07:23 -0300 Subject: [PATCH] fix(svelte): only attach to existing files --- lsp/svelte.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lsp/svelte.lua b/lsp/svelte.lua index 98fde15f04..170c1d6416 100644 --- a/lsp/svelte.lua +++ b/lsp/svelte.lua @@ -12,7 +12,14 @@ return { cmd = { 'svelteserver', '--stdio' }, filetypes = { 'svelte' }, - root_markers = { 'package.json', '.git' }, + root_dir = function(bufnr, on_dir) + local root_files = { 'package.json', '.git' } + 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])) + end + end, on_attach = function(client, bufnr) vim.api.nvim_buf_create_user_command(bufnr, 'LspMigrateToSvelte5', function() client:exec_cmd({