feat: improve vim formatting

This commit is contained in:
2026-07-22 12:35:12 +02:00
parent a06b592031
commit 4f8af808b1
2 changed files with 24 additions and 9 deletions
@@ -1,3 +1,16 @@
local function format_options(bufnr)
local oxfmt = vim.lsp.get_clients({
bufnr = bufnr,
name = "oxfmt",
method = "textDocument/formatting",
})[1]
return {
lsp_format = "fallback",
name = oxfmt and "oxfmt" or nil,
}
end
require("lz.n").load({
{
"conform.nvim",
@@ -7,17 +20,15 @@ require("lz.n").load({
{
"<leader>f",
function()
require("conform").format({ async = true, lsp_format = "fallback" })
local options = format_options(vim.api.nvim_get_current_buf())
options.async = true
require("conform").format(options)
end,
mode = "",
desc = "[F]ormat buffer",
},
},
after = function()
-- Conform's built-in oxfmt formatter searches upwards for
-- node_modules/.bin/oxfmt before falling back to the wrapped binary.
local oxfmt = { "oxfmt" }
require("conform").setup({
notify_on_error = true,
format_on_save = function(bufnr)
@@ -25,10 +36,9 @@ require("lz.n").load({
if disable_filetypes[vim.bo[bufnr].filetype] then
return nil
else
return {
timeout_ms = 500,
lsp_format = "fallback",
}
local options = format_options(bufnr)
options.timeout_ms = 500
return options
end
end,
formatters_by_ft = {