mirror of
https://github.com/neovim/neovim.git
synced 2026-05-02 03:55:00 +00:00
feat(lsp): support textDocument/onTypeFormatting (#34637)
Implements [on-type formatting](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_onTypeFormatting) using a `vim.on_key()` approach to listen to typed keys. It will listen to keys on the *left hand side* of mappings. The `on_key` callback is cleared when detaching the last on-type formatting client. This feature is disabled by default. Co-authored-by: Maria José Solano <majosolano99@gmail.com>
This commit is contained in:
@@ -2377,6 +2377,33 @@ set_level({level}) *vim.lsp.log.set_level()*
|
||||
• {level} (`string|integer`) One of |vim.log.levels|
|
||||
|
||||
|
||||
==============================================================================
|
||||
Lua module: vim.lsp.on_type_formatting *lsp-on_type_formatting*
|
||||
|
||||
enable({enable}, {filter}) *vim.lsp.on_type_formatting.enable()*
|
||||
Enables/disables on-type formatting globally or for the {filter}ed scope.
|
||||
The following are some practical usage examples: >lua
|
||||
-- Enable for all clients
|
||||
vim.lsp.on_type_formatting.enable()
|
||||
|
||||
-- Enable for a specific client
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
callback = function(args)
|
||||
local client_id = args.data.client_id
|
||||
local client = assert(vim.lsp.get_client_by_id(client_id))
|
||||
if client.name == 'rust-analyzer' then
|
||||
vim.lsp.on_type_formatting.enable(true, { client_id = client_id })
|
||||
end
|
||||
end,
|
||||
})
|
||||
<
|
||||
|
||||
Parameters: ~
|
||||
• {enable} (`boolean?`) true/nil to enable, false to disable.
|
||||
• {filter} (`table?`) Optional filters |kwargs|:
|
||||
• {client_id} (`integer?`) Client ID, or `nil` for all.
|
||||
|
||||
|
||||
==============================================================================
|
||||
Lua module: vim.lsp.rpc *lsp-rpc*
|
||||
|
||||
|
||||
@@ -242,6 +242,8 @@ LSP
|
||||
• |vim.lsp.buf.signature_help()| supports "noActiveParameterSupport".
|
||||
• Support for `textDocument/inlineCompletion` |lsp-inline_completion|
|
||||
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_inlineCompletion
|
||||
• Support for `textDocument/onTypeFormatting`: |lsp-on_type_formatting|
|
||||
https://microsoft.github.io/language-server-protocol/specification/#textDocument_onTypeFormatting
|
||||
|
||||
LUA
|
||||
|
||||
|
||||
Reference in New Issue
Block a user