feat(lsp): add vim.lsp.buf.format (#18193)

This commit is contained in:
Michael Lingelbach
2022-04-30 06:36:40 -07:00
committed by GitHub
parent eecc6535eb
commit 5b04e46d23
5 changed files with 220 additions and 21 deletions

View File

@@ -1045,11 +1045,52 @@ execute_command({command_params}) *vim.lsp.buf.execute_command()*
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
format({options}) *vim.lsp.buf.format()*
Formats a buffer using the attached (and optionally filtered)
language server clients.
Parameters: ~
{options} table|nil Optional table which holds the
following optional fields:
• formatting_options (table|nil): Can be used
to specify FormattingOptions. Some
unspecified options will be automatically
derived from the current Neovim options.
See also: ~
https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
• timeout_ms (integer|nil, default 1000): Time in
milliseconds to block for formatting requests.
Formatting requests are current synchronous to prevent
editing of the buffer.
• bufnr (number|nil): Restrict formatting to the clients
attached to the given buffer, defaults to the current
buffer (0).
• filter (function|nil): Predicate to filter clients used
for formatting. Receives the list of clients attached to
bufnr as the argument and must return the list of
clients on which to request formatting. Example: • >
-- Never request typescript-language-server for formatting
vim.lsp.buf.format {
filter = function(clients)
return vim.tbl_filter(
function(client) return client.name ~= "tsserver" end,
clients
)
end
}
<
• id (number|nil): Restrict formatting to the client with
ID (client.id) matching this field.
• name (string|nil): Restrict formatting to the client
with name (client.name) matching this field.
formatting({options}) *vim.lsp.buf.formatting()*
Formats the current buffer.
Parameters: ~
{options} (optional, table) Can be used to specify
{options} (table|nil) Can be used to specify
FormattingOptions. Some unspecified options
will be automatically derived from the current
Neovim options.
@@ -1073,15 +1114,13 @@ formatting_seq_sync({options}, {timeout_ms}, {order})
<
Parameters: ~
{options} (optional, table) `FormattingOptions`
entries
{timeout_ms} (optional, number) Request timeout
{order} (optional, table) List of client names.
Formatting is requested from clients in the
following order: first all clients that are
not in the `order` list, then the remaining
clients in the order as they occur in the
`order` list.
{options} (table|nil) `FormattingOptions` entries
{timeout_ms} (number|nil) Request timeout
{order} (table|nil) List of client names. Formatting
is requested from clients in the following
order: first all clients that are not in the
`order` list, then the remaining clients in
the order as they occur in the `order` list.
*vim.lsp.buf.formatting_sync()*
formatting_sync({options}, {timeout_ms})
@@ -1096,7 +1135,8 @@ formatting_sync({options}, {timeout_ms})
<
Parameters: ~
{options} Table with valid `FormattingOptions` entries
{options} table|nil with valid `FormattingOptions`
entries
{timeout_ms} (number) Request timeout
See also: ~
@@ -1471,8 +1511,7 @@ get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()*
Returns indentation size.
Parameters: ~
{bufnr} (optional, number): Buffer handle, defaults to
current
{bufnr} (number|nil): Buffer handle, defaults to current
Return: ~
(number) indentation size
@@ -1548,7 +1587,8 @@ make_formatting_params({options})
buffer and cursor position.
Parameters: ~
{options} Table with valid `FormattingOptions` entries
{options} table|nil with valid `FormattingOptions`
entries
Return: ~
`DocumentFormattingParams` object