use conform.nvim as universal formatting handler
This commit is contained in:
parent
d8ccea5412
commit
d3cc1e4ec3
2 changed files with 10 additions and 33 deletions
|
@ -1,31 +0,0 @@
|
|||
local autocmd = vim.api.nvim_create_autocmd
|
||||
|
||||
autocmd('LspAttach', {
|
||||
callback = function(args)
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
if client.supports_method('textDocument/formatting') then
|
||||
-- Format the current buffer on save
|
||||
vim.api.nvim_create_autocmd('BufWritePre', {
|
||||
buffer = args.buf,
|
||||
callback = function()
|
||||
vim.lsp.buf.format({bufnr = args.buf, id = client.id})
|
||||
end,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
autocmd('LspDetach', {
|
||||
callback = function(args)
|
||||
-- Get the detaching client
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
-- Remove the autocommand to format the buffer on save, if it exists
|
||||
if client.supports_method('textDocument/formatting') then
|
||||
vim.api.nvim_clear_autocmds({
|
||||
event = 'BufWritePre',
|
||||
buffer = args.buf,
|
||||
})
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
|
@ -3,14 +3,22 @@ local options = {
|
|||
lua = { "stylua" },
|
||||
css = { "prettier" },
|
||||
html = { "prettier" },
|
||||
python = { "ruff", "pyright" }
|
||||
python = { "ruff_format" },
|
||||
go = { "goimports", "gofmt" },
|
||||
json = { "jq" },
|
||||
},
|
||||
|
||||
format_on_save = {
|
||||
-- These options will be passed to conform.format()
|
||||
timeout_ms = 500,
|
||||
lsp_fallback = true,
|
||||
lsp_format = "fallback",
|
||||
},
|
||||
-- Set the log level. Use `:ConformInfo` to see the location of the log file.
|
||||
log_level = vim.log.levels.ERROR,
|
||||
-- Conform will notify you when a formatter errors
|
||||
notify_on_error = true,
|
||||
-- Conform will notify you when no formatters are available for the buffer
|
||||
notify_no_formatters = true,
|
||||
}
|
||||
|
||||
return options
|
||||
|
|
Loading…
Add table
Reference in a new issue