nvim/lua/custom/plugins/formatting.lua
Jeremie Fraeys 02e26b00b7
Some checks are pending
Check Lua Formatting in MyRepo / Stylua Check (push) Waiting to run
chore(nvim): reinitialize with working config
2026-02-07 21:06:45 -05:00

88 lines
2.1 KiB
Lua
Executable file

return {
'stevearc/conform.nvim',
dependencies = {
'nvim-lua/plenary.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim',
},
event = { 'BufReadPre', 'BufNewFile' },
opts = {
formatters = {
juliaformatter = {
command = 'julia',
args = {
'--project=' .. vim.fn.expand('~/.julia/environments/nvim-format'),
'--startup-file=no',
'--history-file=no',
'-e',
[[
using JuliaFormatter
print(format_text(read(stdin, String)))
]],
},
stdin = true,
},
},
formatters_by_ft = {
python = {
'ruff_fix',
'ruff_format',
'ruff_organize_imports',
},
yaml = { 'yamlfmt' },
sh = { 'shfmt' },
sql = { 'sqlfluff' },
lua = { 'stylua' },
json = { 'jq' },
julia = { 'juliaformatter' }, -- keep JuliaFormatter here
markdown = { 'prettierd', 'prettier' },
html = { 'prettierd' },
css = { 'prettierd' },
javascript = { 'prettierd' },
typescript = { 'prettierd' },
},
-- Fallback setup
format_on_save = function(bufnr)
if vim.bo[bufnr].filetype == 'julia' then
return
end
return {
timeout_ms = 2000,
lsp_fallback = true,
}
end,
notify_on_error = true,
async = true,
},
config = function(_, opts)
-- Setup Conform
require('conform').setup(opts)
-- Auto-install formatters via Mason
local all_formatters = {}
for _, formatters in pairs(opts.formatters_by_ft) do
for _, f in ipairs(formatters) do
all_formatters[f] = true
end
end
local exclude = {
ruff_fix = true,
ruff_format = true,
ruff_organize_imports = true,
juliaformatter = true, -- exclude JuliaFormatter from Mason (install via Julia)
}
local tools = vim.tbl_filter(function(tool)
return not exclude[tool]
end, vim.tbl_keys(all_formatters))
require('mason-tool-installer').setup({
ensure_installed = tools,
auto_update = false,
run_on_start = true,
})
end,
}