Formatting

This commit is contained in:
Chris
2026-07-03 13:48:02 +01:00
parent 12b0d3d8b8
commit fbcdd3af0c
7 changed files with 114 additions and 65 deletions
+49
View File
@@ -104,5 +104,54 @@ helpers.open_file_modal = function(path, title)
})
end
local function get_formatter_bin(formatter)
return vim.fn.stdpath 'data' .. '/mason/bin/' .. formatter
end
local formatter_args = {
pint = function(file)
return {
get_formatter_bin 'pint',
'--stdin-filename',
file,
}
end,
eslint_d = function(file)
return {
get_formatter_bin 'eslint_d',
'--stdin',
'--stdin-filename',
file,
'--fix-to-stdout',
}
end,
stylua = function(file)
return {
get_formatter_bin 'stylua',
'--stdin-filepath',
file,
'-',
}
end,
}
helpers.format_buffer = function(formatter, buf, cwd)
local file = vim.api.nvim_buf_get_name(buf)
local input = table.concat(vim.api.nvim_buf_get_lines(buf, 0, -1, false), '\n')
local result = vim.system(formatter_args[formatter](file), {
text = true,
stdin = input,
cwd = cwd,
}):wait()
if result.code ~= 0 then
vim.notify(result.stderr, vim.log.levels.ERROR)
return
end
vim.api.nvim_buf_set_lines(buf, 0, -1, false, vim.split(result.stdout, '\n', { plain = true }))
end
return helpers
-- nnoremap <Leader>ev :tabedit $MYVIMRC<CR>