68 lines
2.3 KiB
Lua
68 lines
2.3 KiB
Lua
return { -- Autoformat
|
|
'stevearc/conform.nvim',
|
|
event = { 'BufWritePre' },
|
|
cmd = { 'ConformInfo' },
|
|
keys = {
|
|
{
|
|
'<leader>=',
|
|
function()
|
|
require('conform').format { async = true, lsp_format = 'fallback' }
|
|
end,
|
|
mode = '',
|
|
desc = '[F]ormat buffer',
|
|
},
|
|
},
|
|
opts = {
|
|
notify_on_error = false,
|
|
format_on_save = function(bufnr)
|
|
-- Disable "format_on_save lsp_fallback" for languages that don't
|
|
-- have a well standardized coding style. You can add additional
|
|
-- languages here or re-enable it for the disabled ones.
|
|
local disable_filetypes = { c = true, cpp = true }
|
|
local slow_filetypes = { kotlin = true }
|
|
if disable_filetypes[vim.bo[bufnr].filetype] then
|
|
return nil
|
|
elseif slow_filetypes[vim.bo[bufnr].filetype] then
|
|
return {
|
|
timeout_ms = 2500,
|
|
lsp_format = 'fallback',
|
|
}
|
|
else
|
|
return {
|
|
timeout_ms = 500,
|
|
lsp_format = 'fallback',
|
|
}
|
|
end
|
|
end,
|
|
formatters_by_ft = {
|
|
lua = { 'stylua' },
|
|
svelte = { 'prettierd', 'prettier', stop_after_first = true },
|
|
astro = { 'prettierd', 'prettier', stop_after_first = true },
|
|
javascript = { 'prettierd', 'prettier', stop_after_first = true },
|
|
typescript = { 'prettierd', 'prettier', stop_after_first = true },
|
|
javascriptreact = { 'prettierd', 'prettier', stop_after_first = true },
|
|
typescriptreact = { 'prettierd', 'prettier', stop_after_first = true },
|
|
json = { 'prettierd', 'prettier', stop_after_first = true },
|
|
graphql = { 'prettierd', 'prettier', stop_after_first = true },
|
|
java = { 'google-java-format' },
|
|
kotlin = { 'ktlint' },
|
|
ruby = { 'standardrb' },
|
|
markdown = { 'prettierd', 'prettier', stop_after_first = true },
|
|
erb = { 'htmlbeautifier' },
|
|
html = { 'htmlbeautifier' },
|
|
bash = { 'beautysh' },
|
|
proto = { 'buf' },
|
|
rust = { 'rustfmt' },
|
|
yaml = { 'yamlfix' },
|
|
toml = { 'taplo' },
|
|
css = { 'prettierd', 'prettier', stop_after_first = true },
|
|
scss = { 'prettierd', 'prettier', stop_after_first = true },
|
|
sh = { 'shellcheck' },
|
|
go = { 'gofmt', 'goimports', 'goimports_reviser' },
|
|
xml = { 'xmllint' },
|
|
c = { 'clang-format' },
|
|
python = { 'black' },
|
|
},
|
|
},
|
|
}
|