feat: proper Format command

This commit is contained in:
əlemi 2023-04-16 12:07:03 +02:00
parent 84855753c7
commit 1cac97e9a9
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -94,7 +94,20 @@ function KEYBINDS:set_lsp_keys(opts)
vim.keymap.set('n', '<C-Del>', vim.diagnostic.open_float, opts) vim.keymap.set('n', '<C-Del>', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '<M-x>', vim.diagnostic.open_float, opts) -- fallback for windows vim.keymap.set('n', '<M-x>', vim.diagnostic.open_float, opts) -- fallback for windows
-- It's not really a keybind but whatever -- It's not really a keybind but whatever
vim.api.nvim_create_user_command('Format', ':lua vim.lsp.buf.formatting()<CR>', {}) -- TODO if function is passed directly, it doesn't work! vim.api.nvim_create_user_command(
'Format',
function(args)
if args.range == 0 then
vim.lsp.buf.format({ async = args.bang })
else
local range = {}
range['start'] = { args.line1, 0 }
range['end'] = { args.line2, 0 }
vim.lsp.buf.format({async=not args.bang, range=range})
end
end,
{bang=true, range=2}
)
vim.keymap.set('n', '<M-p>', ':ClangdSwitchSourceHeader<CR>', {}) vim.keymap.set('n', '<M-p>', ':ClangdSwitchSourceHeader<CR>', {})
end end