You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to set up format-on-save handler, which currently looks like this:
localformat_autocmd=function(bufnr, filter)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer=bufnr,
group="LspFormat",
callback=function()
vim.lsp.buf.format {
bufnr=bufnr,
filter=iffilterthen-- prolly not valid lua, not the pointfunction(c) returnc.name=="null-ls" endelsenilend
}
end,
})
endvim.api.nvim_create_augroup("LspFormat", {})
vim.api.nvim_create_autocmd("LspAttach", {
callback=function(args)
localbufnr=args.buf-- format on saveformat_autocmd(bufnr, false)
localclients=vim.lsp.get_clients {
bufnr=bufnr,
}
for_, clientinipairs(clients) doifclient.name=="null-ls" thenvim.api.nvim_clear_autocmds {
buffer=bufnr,
group="LspFormat",
}
format_autocmd(bufnr, true)
breakendendend,
})
This has one issue tho: if I use NoneLS in a specific ft not for formatting (like extra code actions, unsupported by the main LS), this'll set the formatting to NoneLS anyway, which is not always desired.
How can I detect if NoneLS uses a formatter locally?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to set up format-on-save handler, which currently looks like this:
This has one issue tho: if I use NoneLS in a specific ft not for formatting (like extra code actions, unsupported by the main LS), this'll set the formatting to NoneLS anyway, which is not always desired.
How can I detect if NoneLS uses a formatter locally?
Beta Was this translation helpful? Give feedback.
All reactions