feat: add argument options to LspFormat
This commit is contained in:
parent
48ee862b35
commit
65ce07d29c
2 changed files with 9 additions and 3 deletions
|
@ -20,7 +20,7 @@ function M.on_attach(client, bufnr)
|
|||
|
||||
if client.supports_method('textDocument/formatting') then
|
||||
-- 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
|
||||
if user_config.lsp.format_on_save then
|
||||
|
|
|
@ -29,7 +29,13 @@ function M.toggle_format_on_save()
|
|||
end
|
||||
|
||||
-- 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
|
||||
if M.format_disabled_override then
|
||||
filter = function(client)
|
||||
|
@ -37,7 +43,7 @@ function M.format(bufnr)
|
|||
end
|
||||
end
|
||||
vim.lsp.buf.format({
|
||||
timeout_ms = user_config.lsp.format_timeout,
|
||||
timeout_ms = timeout,
|
||||
filter = filter,
|
||||
bufnr = bufnr or 0,
|
||||
})
|
||||
|
|
Loading…
Add table
Reference in a new issue