Closed diegoulloao closed 9 months ago
Svelte Files are not registered automatically by formatting.prettier
(as you can read here: https://github.com/nvimtools/none-ls.nvim/blob/main/doc/BUILTINS.md#notes-39)
So you would have to enable it like this:
null_ls.setup({
sources = {
formatting.prettier.with({ extra_filetypes = { "svelte" } }),
formatting.stylua,
diagnostics.eslint_d,
},
-- configure format on save
on_attach = function(current_client, bufnr)
if current_client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({
filter = function(client)
-- only use null-ls for formatting instead of lsp server
return client.name == "null-ls"
end,
bufnr = bufnr,
})
end,
})
end
end,
})
FAQ
Issues
Neovim Version
0.9.4
Dev Version?
Operating System
macOs sonoma
Minimal Config
Steps to Reproduce
Create a
.svelte
file and try saving for auto formatting.Reproducibility Check
minimal_init.lua
template and that my issue is reproducible by runningnvim --clean -u minimal_init.lua
and following the steps above.Expected Behavior
Files should get formatted automatically before write changes.
Actual Behavior
Auto formatting doesn't work.
Debug Log
none.
Help
Yes
Implementation Help
No response
Requirements