*vim.lsp.buf_request_sync()*
buf_request_sync({bufnr}, {method}, {params}, {timeout_ms})
Sends a request to all server and waits for the response of all of them.
Calls |vim.lsp.buf_request_all()| but blocks Nvim while awaiting the
result. Parameters are the same as |vim.lsp.buf_request_all()| but the
result is different. Waits a maximum of {timeout_ms}.
Attributes: ~
Since: 0.5.0
Parameters: ~
• {bufnr} (`integer`) Buffer handle, or 0 for current.
• {method} (`string`) LSP method name
• {params} (`table|(fun(client: vim.lsp.Client, bufnr: integer): table?)?`)
Parameters to send to the server. Can also be passed as
a function that returns the params table for cases where
parameters are specific to the client.
• {timeout_ms} (`integer?`, default: `1000`) Maximum time in
milliseconds to wait for a result.
Return (multiple): ~
(`table<integer, {error: lsp.ResponseError?, result: any}>?`) result
Map of client_id:request_result.
(`string?`) err On timeout, cancel, or error, `err` is a string
describing the failure reason, and `result` is nil.
commands *vim.lsp.commands*
Registry (a table) for client-side handlers, for custom server-commands
that are not in the LSP specification.
If an LSP response contains a command which is not found in
`vim.lsp.commands`, the command will be executed via the LSP server using
`workspace/executeCommand`.
Each key in the table is a unique command name, and each value is a
function which is called when an LSP action (code action, code lenses,
…) triggers the command.
• Argument 1 is the `Command`: >
Command
title: String
command: String
arguments?: any[]
<
• Argument 2 is the |lsp-handler| `ctx`.
Example: >lua
vim.lsp.commands['java.action.generateToStringPrompt'] = function(_, ctx)
require("jdtls.async").run(function()
local _, result = request(ctx.bufnr, 'java/checkToStringStatus', ctx.params)
local fields = ui.pick_many(result.fields, 'Include item in toString?', function(x)
return string.format('%s: %s', x.name, x.type)
end)
local _, edit = request(ctx.bufnr, 'java/generateToString', { context = ctx.params; fields = fields; })
vim.lsp.util.apply_workspace_edit(edit, offset_encoding)
end)
end
<
config({name}, {cfg}) *vim.lsp.config()*
Sets the default configuration for an LSP client (or all clients if the
special name "*" is used).
Can also be accessed by table-indexing (`vim.lsp.config[…]`) to get the
resolved config, or redefine the config (instead of "merging" with the
config chain).
Examples:
• Add root markers for ALL clients: >lua
vim.lsp.config('*', {
root_markers = { '.git', '.hg' },
})
<
• Add capabilities to ALL clients: >lua
vim.lsp.config('*', {
capabilities = {
textDocument = {
semanticTokens = {
multilineTokenSupport = true,
}
}
}
})
<
• Add root markers and capabilities for "clangd": >lua
vim.lsp.config('clangd', {
root_markers = { '.clang-format', 'compile_commands.json' },
capabilities = {
textDocument = {
completion = {
completionItem = {
snippetSupport = true,
}
}
}
}
})
<
• (Re-)define the "clangd" configuration (overrides the resolved chain): >lua
vim.lsp.config.clangd = {
cmd = {
'clangd',
'--clang-tidy',
'--background-index',
'--offset-encoding=utf-8',
},
root_markers = { '.clangd', 'compile_commands.json'