Updated config

Added conform to replace null-ls
This commit is contained in:
2024-09-07 00:19:24 +02:00
parent c3ced61294
commit b25c9186b9
6 changed files with 62 additions and 25 deletions

View File

@@ -0,0 +1,38 @@
return {
"stevearc/conform.nvim",
event = { "BufReadPre", "BufNewFile" },
config = function()
require("conform").setup({
formatters_by_ft = {
lua = { "stylua" },
javascript = { "dprint" },
typescript = { "dprint" },
json = { "dprint" },
markdown = { "dprint" },
},
format_on_save = {
timeout_ms = 500,
lsp_format = "fallback",
},
})
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 })
vim.api.nvim_set_keymap(
"n",
"<leader>bf",
"<cmd>Format<CR>",
{ noremap = true, silent = true, desc = "Format buffer" }
)
end,
}