Skip to content

Commit c36916f

Browse files
authored
fix(svelte): only attach to existing files #3899
1 parent f6d31b1 commit c36916f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lsp/svelte.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
return {
1313
cmd = { 'svelteserver', '--stdio' },
1414
filetypes = { 'svelte' },
15-
root_markers = { 'package.json', '.git' },
15+
root_dir = function(bufnr, on_dir)
16+
local root_files = { 'package.json', '.git' }
17+
local fname = vim.api.nvim_buf_get_name(bufnr)
18+
-- Svelte LSP only supports file:// schema. https://github.com/sveltejs/language-tools/issues/2777
19+
if vim.uv.fs_stat(fname) ~= nil then
20+
on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1]))
21+
end
22+
end,
1623
on_attach = function(client, bufnr)
1724
vim.api.nvim_buf_create_user_command(bufnr, 'LspMigrateToSvelte5', function()
1825
client:exec_cmd({

0 commit comments

Comments
 (0)