aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/lsp')
-rw-r--r--runtime/lua/vim/lsp/buf.lua16
-rw-r--r--runtime/lua/vim/lsp/client.lua14
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua2
-rw-r--r--runtime/lua/vim/lsp/inlay_hint.lua9
-rw-r--r--runtime/lua/vim/lsp/rpc.lua24
-rw-r--r--runtime/lua/vim/lsp/semantic_tokens.lua16
6 files changed, 29 insertions, 52 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index ccef314d86..f6837a627f 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -21,10 +21,8 @@ local M = {}
---
---@see |vim.lsp.buf_request()|
local function request(method, params, handler)
- validate({
- method = { method, 's' },
- handler = { handler, 'f', true },
- })
+ validate('method', method, 'string')
+ validate('handler', handler, 'function', true)
return vim.lsp.buf_request(0, method, params, handler)
end
@@ -439,7 +437,7 @@ end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
---@param opts? vim.lsp.ListOpts
function M.references(context, opts)
- validate({ context = { context, 't', true } })
+ validate('context', context, 'table', true)
local params = util.make_position_params()
params.context = context or {
includeDeclaration = true,
@@ -857,7 +855,7 @@ end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
---@see vim.lsp.protocol.CodeActionTriggerKind
function M.code_action(opts)
- validate({ options = { opts, 't', true } })
+ validate('options', opts, 'table', true)
opts = opts or {}
-- Detect old API call code_action(context) which should now be
-- code_action({ context = context} )
@@ -935,10 +933,8 @@ end
--- @param command_params lsp.ExecuteCommandParams
--- @see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
function M.execute_command(command_params)
- validate({
- command = { command_params.command, 's' },
- arguments = { command_params.arguments, 't', true },
- })
+ validate('command', command_params.command, 'string')
+ validate('arguments', command_params.arguments, 'table', true)
command_params = {
command = command_params.command,
arguments = command_params.arguments,
diff --git a/runtime/lua/vim/lsp/client.lua b/runtime/lua/vim/lsp/client.lua
index e3c82f4169..d5fc5b8908 100644
--- a/runtime/lua/vim/lsp/client.lua
+++ b/runtime/lua/vim/lsp/client.lua
@@ -291,7 +291,7 @@ local client_index = 0
--- @param filename (string) path to check
--- @return boolean # true if {filename} exists and is a directory, false otherwise
local function is_dir(filename)
- validate({ filename = { filename, 's' } })
+ validate('filename', filename, 'string')
local stat = uv.fs_stat(filename)
return stat and stat.type == 'directory' or false
end
@@ -312,9 +312,7 @@ local valid_encodings = {
--- @param encoding string? Encoding to normalize
--- @return string # normalized encoding name
local function validate_encoding(encoding)
- validate({
- encoding = { encoding, 's', true },
- })
+ validate('encoding', encoding, 'string', true)
if not encoding then
return valid_encodings.UTF16
end
@@ -350,9 +348,7 @@ end
--- Validates a client configuration as given to |vim.lsp.start_client()|.
--- @param config vim.lsp.ClientConfig
local function validate_config(config)
- validate({
- config = { config, 't' },
- })
+ validate('config', config, 'table')
validate({
handlers = { config.handlers, 't', true },
capabilities = { config.capabilities, 't', true },
@@ -640,7 +636,7 @@ end
--- @param bufnr (integer|nil) Buffer number to resolve. Defaults to current buffer
--- @return integer bufnr
local function resolve_bufnr(bufnr)
- validate({ bufnr = { bufnr, 'n', true } })
+ validate('bufnr', bufnr, 'number', true)
if bufnr == nil or bufnr == 0 then
return api.nvim_get_current_buf()
end
@@ -806,7 +802,7 @@ end
--- @return boolean status true if notification was successful. false otherwise
--- @see |vim.lsp.client.notify()|
function Client:_cancel_request(id)
- validate({ id = { id, 'n' } })
+ validate('id', id, 'number')
local request = self.requests[id]
if request and request.type == 'pending' then
request.type = 'cancel'
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index c10312484b..bf72222536 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -195,7 +195,7 @@ local _client_pull_namespaces = {}
---@param client_id integer The id of the LSP client
---@param is_pull boolean? Whether the namespace is for a pull or push client. Defaults to push
function M.get_namespace(client_id, is_pull)
- vim.validate({ client_id = { client_id, 'n' } })
+ vim.validate('client_id', client_id, 'number')
local client = vim.lsp.get_client_by_id(client_id)
if is_pull then
diff --git a/runtime/lua/vim/lsp/inlay_hint.lua b/runtime/lua/vim/lsp/inlay_hint.lua
index 61059180fe..61d119e653 100644
--- a/runtime/lua/vim/lsp/inlay_hint.lua
+++ b/runtime/lua/vim/lsp/inlay_hint.lua
@@ -145,7 +145,7 @@ end
--- @return vim.lsp.inlay_hint.get.ret[]
--- @since 12
function M.get(filter)
- vim.validate({ filter = { filter, 'table', true } })
+ vim.validate('filter', filter, 'table', true)
filter = filter or {}
local bufnr = filter.bufnr
@@ -375,11 +375,11 @@ api.nvim_set_decoration_provider(namespace, {
--- @return boolean
--- @since 12
function M.is_enabled(filter)
- vim.validate({ filter = { filter, 'table', true } })
+ vim.validate('filter', filter, 'table', true)
filter = filter or {}
local bufnr = filter.bufnr
- vim.validate({ bufnr = { bufnr, 'number', true } })
+ vim.validate('bufnr', bufnr, 'number', true)
if bufnr == nil then
return globalstate.enabled
elseif bufnr == 0 then
@@ -406,7 +406,8 @@ end
--- @param filter vim.lsp.inlay_hint.enable.Filter?
--- @since 12
function M.enable(enable, filter)
- vim.validate({ enable = { enable, 'boolean', true }, filter = { filter, 'table', true } })
+ vim.validate('enable', enable, 'boolean', true)
+ vim.validate('filter', filter, 'table', true)
enable = enable == nil or enable
filter = filter or {}
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index e79dbd2db3..ac43801c1c 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -152,9 +152,7 @@ end
---@param err table The error object
---@return string error_message The formatted error message
function M.format_rpc_error(err)
- validate({
- err = { err, 't' },
- })
+ validate('err', err, 'table')
-- There is ErrorCodes in the LSP specification,
-- but in ResponseError.code it is not used and the actual type is number.
@@ -329,10 +327,8 @@ end
---@return boolean success `true` if request could be sent, `false` if not
---@return integer? message_id if request could be sent, `nil` if not
function Client:request(method, params, callback, notify_reply_callback)
- validate({
- callback = { callback, 'f' },
- notify_reply_callback = { notify_reply_callback, 'f', true },
- })
+ validate('callback', callback, 'function')
+ validate('notify_reply_callback', notify_reply_callback, 'function', true)
self.message_index = self.message_index + 1
local message_id = self.message_index
local result = self:encode_and_send({
@@ -465,9 +461,7 @@ function Client:handle_body(body)
local notify_reply_callbacks = self.notify_reply_callbacks
local notify_reply_callback = notify_reply_callbacks and notify_reply_callbacks[result_id]
if notify_reply_callback then
- validate({
- notify_reply_callback = { notify_reply_callback, 'f' },
- })
+ validate('notify_reply_callback', notify_reply_callback, 'function')
notify_reply_callback(result_id)
notify_reply_callbacks[result_id] = nil
end
@@ -498,9 +492,7 @@ function Client:handle_body(body)
local callback = message_callbacks and message_callbacks[result_id]
if callback then
message_callbacks[result_id] = nil
- validate({
- callback = { callback, 'f' },
- })
+ validate('callback', callback, 'function')
if decoded.error then
decoded.error = setmetatable(decoded.error, {
__tostring = M.format_rpc_error,
@@ -734,10 +726,8 @@ end
function M.start(cmd, dispatchers, extra_spawn_params)
log.info('Starting RPC client', { cmd = cmd, extra = extra_spawn_params })
- validate({
- cmd = { cmd, 't' },
- dispatchers = { dispatchers, 't', true },
- })
+ validate('cmd', cmd, 'table')
+ validate('dispatchers', dispatchers, 'table', true)
extra_spawn_params = extra_spawn_params or {}
diff --git a/runtime/lua/vim/lsp/semantic_tokens.lua b/runtime/lua/vim/lsp/semantic_tokens.lua
index 8182457dd0..2c7958b0d5 100644
--- a/runtime/lua/vim/lsp/semantic_tokens.lua
+++ b/runtime/lua/vim/lsp/semantic_tokens.lua
@@ -565,10 +565,8 @@ local M = {}
--- - debounce (integer, default: 200): Debounce token requests
--- to the server by the given number in milliseconds
function M.start(bufnr, client_id, opts)
- vim.validate({
- bufnr = { bufnr, 'n', false },
- client_id = { client_id, 'n', false },
- })
+ vim.validate('bufnr', bufnr, 'number')
+ vim.validate('client_id', client_id, 'number')
if bufnr == 0 then
bufnr = api.nvim_get_current_buf()
@@ -622,10 +620,8 @@ end
---@param bufnr (integer) Buffer number, or `0` for current buffer
---@param client_id (integer) The ID of the |vim.lsp.Client|
function M.stop(bufnr, client_id)
- vim.validate({
- bufnr = { bufnr, 'n', false },
- client_id = { client_id, 'n', false },
- })
+ vim.validate('bufnr', bufnr, 'number')
+ vim.validate('client_id', client_id, 'number')
if bufnr == 0 then
bufnr = api.nvim_get_current_buf()
@@ -708,9 +704,7 @@ end
---@param bufnr (integer|nil) filter by buffer. All buffers if nil, current
--- buffer if 0
function M.force_refresh(bufnr)
- vim.validate({
- bufnr = { bufnr, 'n', true },
- })
+ vim.validate('bufnr', bufnr, 'number', true)
local buffers = bufnr == nil and vim.tbl_keys(STHighlighter.active)
or bufnr == 0 and { api.nvim_get_current_buf() }