feat: add argument options to LspFormat

This commit is contained in:
Matthew Leong 2023-10-25 15:21:47 -07:00
parent 48ee862b35
commit 65ce07d29c
2 changed files with 9 additions and 3 deletions

View file

@ -20,7 +20,7 @@ function M.on_attach(client, bufnr)
if client.supports_method('textDocument/formatting') then if client.supports_method('textDocument/formatting') then
-- set up :LspFormat for clients that are capable -- set up :LspFormat for clients that are capable
vim.cmd(string.format("command! LspFormat lua require('cosmic.utils.lsp').format(%s)", bufnr)) vim.cmd(string.format("command! -nargs=? LspFormat lua require('cosmic.utils.lsp').format(%s, <q-args>)", bufnr))
-- set up auto format on save -- set up auto format on save
if user_config.lsp.format_on_save then if user_config.lsp.format_on_save then

View file

@ -29,7 +29,13 @@ function M.toggle_format_on_save()
end end
-- format current buffer w/user settings -- format current buffer w/user settings
function M.format(bufnr) function M.format(bufnr, timeout)
if timeout ~= '' then
timeout = timeout * 1000
else
timeout = user_config.lsp.format_timeout
end
timeout = user_config.lsp.format_timeout
local filter = can_client_format local filter = can_client_format
if M.format_disabled_override then if M.format_disabled_override then
filter = function(client) filter = function(client)
@ -37,7 +43,7 @@ function M.format(bufnr)
end end
end end
vim.lsp.buf.format({ vim.lsp.buf.format({
timeout_ms = user_config.lsp.format_timeout, timeout_ms = timeout,
filter = filter, filter = filter,
bufnr = bufnr or 0, bufnr = bufnr or 0,
}) })