feat: add range formatting to formatter
This commit is contained in:
parent
6ba2408cdf
commit
e2fca30499
26
init.lua
26
init.lua
|
@ -740,16 +740,6 @@ require('lazy').setup({
|
||||||
'stevearc/conform.nvim',
|
'stevearc/conform.nvim',
|
||||||
event = { 'BufWritePre' },
|
event = { 'BufWritePre' },
|
||||||
cmd = { 'ConformInfo' },
|
cmd = { 'ConformInfo' },
|
||||||
keys = {
|
|
||||||
{
|
|
||||||
'<leader>f',
|
|
||||||
function()
|
|
||||||
require('conform').format { async = true, lsp_format = 'fallback' }
|
|
||||||
end,
|
|
||||||
mode = '',
|
|
||||||
desc = '[F]ormat buffer',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
opts = {
|
opts = {
|
||||||
notify_on_error = false,
|
notify_on_error = false,
|
||||||
format_on_save = function(bufnr)
|
format_on_save = function(bufnr)
|
||||||
|
@ -774,6 +764,22 @@ require('lazy').setup({
|
||||||
-- You can use 'stop_after_first' to run the first available formatter from the list
|
-- You can use 'stop_after_first' to run the first available formatter from the list
|
||||||
-- javascript = { "prettierd", "prettier", stop_after_first = true },
|
-- javascript = { "prettierd", "prettier", stop_after_first = true },
|
||||||
},
|
},
|
||||||
|
vim.api.nvim_create_user_command('Format', function(args)
|
||||||
|
local range = nil
|
||||||
|
if args.count ~= -1 then
|
||||||
|
local end_line = vim.api.nvim_buf_gt_lines(0, args.line2 - 1, args.line2, true)[1]
|
||||||
|
range = {
|
||||||
|
start = { args.line1, 0 },
|
||||||
|
['end'] = { args.line2, end_line:len() },
|
||||||
|
}
|
||||||
|
end
|
||||||
|
require('conform').format {
|
||||||
|
async = true,
|
||||||
|
lsp_format = 'fallback',
|
||||||
|
range = range,
|
||||||
|
}
|
||||||
|
end, { range = true }),
|
||||||
|
vim.keymap.set({ 'n', 'v' }, '<leader>f', '<Cmd>Format<CR>'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue