Add conform.nvim

This commit is contained in:
Antoine Vaure 2024-08-12 16:51:19 +02:00
parent 1a0c48ae00
commit e462372892
2 changed files with 29 additions and 3 deletions

View file

@ -75,9 +75,7 @@ vim.api.nvim_create_autocmd('LspAttach', {
vim.keymap.set('n', '<leader>ra', vim.lsp.buf.rename, opts) vim.keymap.set('n', '<leader>ra', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts) vim.keymap.set({ 'n', 'v' }, '<leader>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', telescope.lsp_references, opts) vim.keymap.set('n', 'gr', telescope.lsp_references, opts)
vim.keymap.set('n', '<leader>fm', function() vim.keymap.set({ 'n', 'v' }, '<leader>fm', ":Format<cr>", opts)
vim.lsp.buf.format { async = true }
end, opts)
end, end,
}) })

View file

@ -530,6 +530,34 @@ local plugins = {
}, },
{ {
'nvimtools/hydra.nvim', 'nvimtools/hydra.nvim',
},
{
'stevearc/conform.nvim',
config = function()
require("conform").setup({
formatters = {
uncrustify = {
prepend_args = { "-c", "./scripts/uncrustify.cfg" },
},
},
formatters_by_ft = {
cpp = { "uncrustify" },
typst = { "typstyle" }
}
})
vim.api.nvim_create_user_command("Format", function(args)
local range = nil
if args.count ~= -1 then
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
range = {
start = { args.line1, 0 },
["end"] = { args.line2, end_line:len() },
}
end
require("conform").format({ async = true, lsp_format = "fallback", range = range })
end, { range = true })
end
} }
} }