47 lines
1.2 KiB
Lua
47 lines
1.2 KiB
Lua
---@module "utils.plugins"
|
|
---@type Plugin
|
|
return {
|
|
after = "mason-bridge",
|
|
configure = function(load)
|
|
load("stevearc/conform.nvim")
|
|
|
|
require("conform").setup({
|
|
formatters_by_ft = require("mason-bridge").get_formatters(),
|
|
|
|
format_on_save = function(bufnr)
|
|
require("conform").formatters_by_ft = require("mason-bridge").get_formatters()
|
|
|
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
|
return
|
|
else
|
|
return { timeout_ms = 500, lsp_format = "fallback" }
|
|
end
|
|
end,
|
|
})
|
|
|
|
vim.api.nvim_create_user_command("FormatDisable", function(args)
|
|
if args.bang then
|
|
-- FormatDisable! will disable formatting globally
|
|
vim.g.disable_autoformat = true
|
|
else
|
|
vim.b.disable_autoformat = true
|
|
end
|
|
end, {
|
|
desc = "Disable autoformat-on-save",
|
|
bang = true,
|
|
})
|
|
vim.api.nvim_create_user_command("FormatEnable", function(args)
|
|
if args.bang then
|
|
-- FormatDisable! will disable formatting globally
|
|
vim.g.disable_autoformat = false
|
|
else
|
|
vim.b.disable_autoformat = false
|
|
end
|
|
end, {
|
|
desc = "Enable autoformat-on-save",
|
|
bang = true,
|
|
})
|
|
|
|
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
|
end,
|
|
}
|