mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 12:28:18 +00:00
fix(lsp): correct some type annotations (#21365)
This commit is contained in:

committed by
GitHub

parent
3cf0131c5c
commit
49df92da94
@@ -564,9 +564,9 @@ buf_notify({bufnr}, {method}, {params}) *vim.lsp.buf_notify()*
|
|||||||
Send a notification to a server
|
Send a notification to a server
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {bufnr} [number] (optional): The number of the buffer
|
• {bufnr} (number|nil) The number of the buffer
|
||||||
• {method} [string]: Name of the request method
|
• {method} (string) Name of the request method
|
||||||
• {params} [string]: Arguments to send to the server
|
• {params} (string) Arguments to send to the server
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
true if any client returns true; false otherwise
|
true if any client returns true; false otherwise
|
||||||
@@ -580,7 +580,7 @@ buf_request_all({bufnr}, {method}, {params}, {callback})
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {bufnr} (number) Buffer handle, or 0 for current.
|
• {bufnr} (number) Buffer handle, or 0 for current.
|
||||||
• {method} (string) LSP method name
|
• {method} (string) LSP method name
|
||||||
• {params} (optional, table) Parameters to send to the server
|
• {params} (table|nil) Parameters to send to the server
|
||||||
• {callback} (function) The callback to call when all requests are
|
• {callback} (function) The callback to call when all requests are
|
||||||
finished.
|
finished.
|
||||||
|
|
||||||
@@ -599,9 +599,9 @@ buf_request_sync({bufnr}, {method}, {params}, {timeout_ms})
|
|||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {bufnr} (number) Buffer handle, or 0 for current.
|
• {bufnr} (number) Buffer handle, or 0 for current.
|
||||||
• {method} (string) LSP method name
|
• {method} (string) LSP method name
|
||||||
• {params} (optional, table) Parameters to send to the server
|
• {params} (table|nil) Parameters to send to the server
|
||||||
• {timeout_ms} (optional, number, default=1000) Maximum time in
|
• {timeout_ms} (number|nil) Maximum time in milliseconds to wait for a
|
||||||
milliseconds to wait for a result.
|
result. Defaults to 1000
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
Map of client_id:request_result. On timeout, cancel or error, returns
|
Map of client_id:request_result. On timeout, cancel or error, returns
|
||||||
@@ -668,7 +668,7 @@ client_is_stopped({client_id}) *vim.lsp.client_is_stopped()*
|
|||||||
Checks whether a client is stopped.
|
Checks whether a client is stopped.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {client_id} (Number)
|
• {client_id} (number)
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
true if client is stopped, false otherwise.
|
true if client is stopped, false otherwise.
|
||||||
@@ -747,8 +747,8 @@ omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
|
|||||||
Implements 'omnifunc' compatible LSP completion.
|
Implements 'omnifunc' compatible LSP completion.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {findstart} 0 or 1, decides behavior
|
• {findstart} (number) 0 or 1, decides behavior
|
||||||
• {base} If findstart=0, text to match against
|
• {base} (number) findstart=0, text to match against
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
(number) Decided by {findstart}:
|
(number) Decided by {findstart}:
|
||||||
@@ -770,7 +770,7 @@ set_log_level({level}) *vim.lsp.set_log_level()*
|
|||||||
Use `lsp.log_levels` for reverse lookup.
|
Use `lsp.log_levels` for reverse lookup.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {level} [number|string] the case insensitive level name or number
|
• {level} (number|string) the case insensitive level name or number
|
||||||
|
|
||||||
See also: ~
|
See also: ~
|
||||||
|vim.lsp.log_levels|
|
|vim.lsp.log_levels|
|
||||||
@@ -972,7 +972,8 @@ stop_client({client_id}, {force}) *vim.lsp.stop_client()*
|
|||||||
for this client, then force-shutdown is attempted.
|
for this client, then force-shutdown is attempted.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {client_id} client id or |vim.lsp.client| object, or list thereof
|
• {client_id} number|table id or |vim.lsp.client| object, or list
|
||||||
|
thereof
|
||||||
• {force} (boolean) (optional) shutdown forcefully
|
• {force} (boolean) (optional) shutdown forcefully
|
||||||
|
|
||||||
tagfunc({...}) *vim.lsp.tagfunc()*
|
tagfunc({...}) *vim.lsp.tagfunc()*
|
||||||
@@ -984,8 +985,8 @@ tagfunc({...}) *vim.lsp.tagfunc()*
|
|||||||
LSP servers, falls back to using built-in tags.
|
LSP servers, falls back to using built-in tags.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {pattern} Pattern used to find a workspace symbol
|
• {pattern} (string) Pattern used to find a workspace symbol
|
||||||
• {flags} See |tag-function|
|
• {flags} (string) See |tag-function|
|
||||||
|
|
||||||
Return: ~
|
Return: ~
|
||||||
A list of matching tags
|
A list of matching tags
|
||||||
@@ -1877,7 +1878,7 @@ set_level({level}) *vim.lsp.log.set_level()*
|
|||||||
Sets the current log level.
|
Sets the current log level.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
• {level} (string or number) One of `vim.lsp.log.levels`
|
• {level} (string|number) One of `vim.lsp.log.levels`
|
||||||
|
|
||||||
should_log({level}) *vim.lsp.log.should_log()*
|
should_log({level}) *vim.lsp.log.should_log()*
|
||||||
Checks whether the level is sufficient for logging.
|
Checks whether the level is sufficient for logging.
|
||||||
|
@@ -67,7 +67,7 @@ lsp._request_name_to_capability = {
|
|||||||
---@private
|
---@private
|
||||||
--- Concatenates and writes a list of strings to the Vim error buffer.
|
--- Concatenates and writes a list of strings to the Vim error buffer.
|
||||||
---
|
---
|
||||||
---@param {...} (List of strings) List to write to the buffer
|
---@param {...} table[] List to write to the buffer
|
||||||
local function err_message(...)
|
local function err_message(...)
|
||||||
nvim_err_writeln(table.concat(vim.tbl_flatten({ ... })))
|
nvim_err_writeln(table.concat(vim.tbl_flatten({ ... })))
|
||||||
nvim_command('redraw')
|
nvim_command('redraw')
|
||||||
@@ -76,7 +76,7 @@ end
|
|||||||
---@private
|
---@private
|
||||||
--- Returns the buffer number for the given {bufnr}.
|
--- Returns the buffer number for the given {bufnr}.
|
||||||
---
|
---
|
||||||
---@param bufnr (number) Buffer number to resolve. Defaults to the current
|
---@param bufnr (number|nil) Buffer number to resolve. Defaults to the current
|
||||||
---buffer if not given.
|
---buffer if not given.
|
||||||
---@returns bufnr (number) Number of requested buffer
|
---@returns bufnr (number) Number of requested buffer
|
||||||
local function resolve_bufnr(bufnr)
|
local function resolve_bufnr(bufnr)
|
||||||
@@ -244,9 +244,9 @@ end
|
|||||||
---@private
|
---@private
|
||||||
--- Augments a validator function with support for optional (nil) values.
|
--- Augments a validator function with support for optional (nil) values.
|
||||||
---
|
---
|
||||||
---@param fn (function(v)) The original validator function; should return a
|
---@param fn (fun(v)) The original validator function; should return a
|
||||||
---bool.
|
---bool.
|
||||||
---@returns (function(v)) The augmented function. Also returns true if {v} is
|
---@returns (fun(v)) The augmented function. Also returns true if {v} is
|
||||||
---`nil`.
|
---`nil`.
|
||||||
local function optional_validator(fn)
|
local function optional_validator(fn)
|
||||||
return function(v)
|
return function(v)
|
||||||
@@ -1366,7 +1366,7 @@ function lsp.start_client(config)
|
|||||||
---
|
---
|
||||||
---@param method (string) LSP method name.
|
---@param method (string) LSP method name.
|
||||||
---@param params (table) LSP request params.
|
---@param params (table) LSP request params.
|
||||||
---@param handler (function, optional) Response |lsp-handler| for this method.
|
---@param handler (function|nil) Response |lsp-handler| for this method.
|
||||||
---@param bufnr (number) Buffer handle (0 for current).
|
---@param bufnr (number) Buffer handle (0 for current).
|
||||||
---@returns ({status}, [request_id]): {status} is a bool indicating
|
---@returns ({status}, [request_id]): {status} is a bool indicating
|
||||||
---whether the request was successful. If it is `false`, then it will
|
---whether the request was successful. If it is `false`, then it will
|
||||||
@@ -1377,8 +1377,10 @@ function lsp.start_client(config)
|
|||||||
---@see |vim.lsp.buf_request()|
|
---@see |vim.lsp.buf_request()|
|
||||||
function client.request(method, params, handler, bufnr)
|
function client.request(method, params, handler, bufnr)
|
||||||
if not handler then
|
if not handler then
|
||||||
handler = resolve_handler(method)
|
handler = assert(
|
||||||
or error(string.format('not found: %q request handler for client %q.', method, client.name))
|
resolve_handler(method),
|
||||||
|
string.format('not found: %q request handler for client %q.', method, client.name)
|
||||||
|
)
|
||||||
end
|
end
|
||||||
-- Ensure pending didChange notifications are sent so that the server doesn't operate on a stale state
|
-- Ensure pending didChange notifications are sent so that the server doesn't operate on a stale state
|
||||||
changetracking.flush(client, bufnr)
|
changetracking.flush(client, bufnr)
|
||||||
@@ -1396,7 +1398,7 @@ function lsp.start_client(config)
|
|||||||
nvim_exec_autocmds('User', { pattern = 'LspRequest', modeline = false })
|
nvim_exec_autocmds('User', { pattern = 'LspRequest', modeline = false })
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if success then
|
if success and request_id then
|
||||||
client.requests[request_id] = { type = 'pending', bufnr = bufnr, method = method }
|
client.requests[request_id] = { type = 'pending', bufnr = bufnr, method = method }
|
||||||
nvim_exec_autocmds('User', { pattern = 'LspRequest', modeline = false })
|
nvim_exec_autocmds('User', { pattern = 'LspRequest', modeline = false })
|
||||||
end
|
end
|
||||||
@@ -1411,8 +1413,8 @@ function lsp.start_client(config)
|
|||||||
---
|
---
|
||||||
---@param method (string) LSP method name.
|
---@param method (string) LSP method name.
|
||||||
---@param params (table) LSP request params.
|
---@param params (table) LSP request params.
|
||||||
---@param timeout_ms (number, optional, default=1000) Maximum time in
|
---@param timeout_ms (number|nil) Maximum time in milliseconds to wait for
|
||||||
---milliseconds to wait for a result.
|
--- a result. Defaults to 1000
|
||||||
---@param bufnr (number) Buffer handle (0 for current).
|
---@param bufnr (number) Buffer handle (0 for current).
|
||||||
---@returns { err=err, result=result }, a dictionary, where `err` and `result` come from the |lsp-handler|.
|
---@returns { err=err, result=result }, a dictionary, where `err` and `result` come from the |lsp-handler|.
|
||||||
---On timeout, cancel or error, returns `(nil, err)` where `err` is a
|
---On timeout, cancel or error, returns `(nil, err)` where `err` is a
|
||||||
@@ -1435,7 +1437,9 @@ function lsp.start_client(config)
|
|||||||
end, 10)
|
end, 10)
|
||||||
|
|
||||||
if not wait_result then
|
if not wait_result then
|
||||||
client.cancel_request(request_id)
|
if request_id then
|
||||||
|
client.cancel_request(request_id)
|
||||||
|
end
|
||||||
return nil, wait_result_reason[reason]
|
return nil, wait_result_reason[reason]
|
||||||
end
|
end
|
||||||
return request_result
|
return request_result
|
||||||
@@ -1800,7 +1804,7 @@ end
|
|||||||
--- By default asks the server to shutdown, unless stop was requested
|
--- By default asks the server to shutdown, unless stop was requested
|
||||||
--- already for this client, then force-shutdown is attempted.
|
--- already for this client, then force-shutdown is attempted.
|
||||||
---
|
---
|
||||||
---@param client_id client id or |vim.lsp.client| object, or list thereof
|
---@param client_id number|table id or |vim.lsp.client| object, or list thereof
|
||||||
---@param force boolean (optional) shutdown forcefully
|
---@param force boolean (optional) shutdown forcefully
|
||||||
function lsp.stop_client(client_id, force)
|
function lsp.stop_client(client_id, force)
|
||||||
local ids = type(client_id) == 'table' and client_id or { client_id }
|
local ids = type(client_id) == 'table' and client_id or { client_id }
|
||||||
@@ -1815,10 +1819,16 @@ function lsp.stop_client(client_id, force)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class vim.lsp.get_active_clients.filter
|
||||||
|
---@field id number|nil Match clients by id
|
||||||
|
---@field bufnr number|nil match clients attached to the given buffer
|
||||||
|
---@field name number|nil match clients by name
|
||||||
|
|
||||||
--- Get active clients.
|
--- Get active clients.
|
||||||
---
|
---
|
||||||
---@param filter (table|nil) A table with key-value pairs used to filter the
|
---@param filter vim.lsp.get_active_clients.filter|nil (table|nil) A table with
|
||||||
--- returned clients. The available keys are:
|
--- key-value pairs used to filter the returned clients.
|
||||||
|
--- The available keys are:
|
||||||
--- - id (number): Only return clients with the given id
|
--- - id (number): Only return clients with the given id
|
||||||
--- - bufnr (number): Only return clients attached to this buffer
|
--- - bufnr (number): Only return clients attached to this buffer
|
||||||
--- - name (string): Only return clients with the given name
|
--- - name (string): Only return clients with the given name
|
||||||
@@ -1966,7 +1976,7 @@ end
|
|||||||
---
|
---
|
||||||
---@param bufnr (number) Buffer handle, or 0 for current.
|
---@param bufnr (number) Buffer handle, or 0 for current.
|
||||||
---@param method (string) LSP method name
|
---@param method (string) LSP method name
|
||||||
---@param params (optional, table) Parameters to send to the server
|
---@param params (table|nil) Parameters to send to the server
|
||||||
---@param callback (function) The callback to call when all requests are finished.
|
---@param callback (function) The callback to call when all requests are finished.
|
||||||
-- Unlike `buf_request`, this will collect all the responses from each server instead of handling them.
|
-- Unlike `buf_request`, this will collect all the responses from each server instead of handling them.
|
||||||
-- A map of client_id:request_result will be provided to the callback
|
-- A map of client_id:request_result will be provided to the callback
|
||||||
@@ -2008,9 +2018,9 @@ end
|
|||||||
---
|
---
|
||||||
---@param bufnr (number) Buffer handle, or 0 for current.
|
---@param bufnr (number) Buffer handle, or 0 for current.
|
||||||
---@param method (string) LSP method name
|
---@param method (string) LSP method name
|
||||||
---@param params (optional, table) Parameters to send to the server
|
---@param params (table|nil) Parameters to send to the server
|
||||||
---@param timeout_ms (optional, number, default=1000) Maximum time in
|
---@param timeout_ms (number|nil) Maximum time in milliseconds to wait for a
|
||||||
--- milliseconds to wait for a result.
|
--- result. Defaults to 1000
|
||||||
---
|
---
|
||||||
---@returns Map of client_id:request_result. On timeout, cancel or error,
|
---@returns Map of client_id:request_result. On timeout, cancel or error,
|
||||||
--- returns `(nil, err)` where `err` is a string describing the failure
|
--- returns `(nil, err)` where `err` is a string describing the failure
|
||||||
@@ -2035,9 +2045,9 @@ function lsp.buf_request_sync(bufnr, method, params, timeout_ms)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Send a notification to a server
|
--- Send a notification to a server
|
||||||
---@param bufnr [number] (optional): The number of the buffer
|
---@param bufnr (number|nil) The number of the buffer
|
||||||
---@param method [string]: Name of the request method
|
---@param method (string) Name of the request method
|
||||||
---@param params [string]: Arguments to send to the server
|
---@param params (string) Arguments to send to the server
|
||||||
---
|
---
|
||||||
---@returns true if any client returns true; false otherwise
|
---@returns true if any client returns true; false otherwise
|
||||||
function lsp.buf_notify(bufnr, method, params)
|
function lsp.buf_notify(bufnr, method, params)
|
||||||
@@ -2078,8 +2088,8 @@ end
|
|||||||
---@see |complete-items|
|
---@see |complete-items|
|
||||||
---@see |CompleteDone|
|
---@see |CompleteDone|
|
||||||
---
|
---
|
||||||
---@param findstart 0 or 1, decides behavior
|
---@param findstart number 0 or 1, decides behavior
|
||||||
---@param base If findstart=0, text to match against
|
---@param base number findstart=0, text to match against
|
||||||
---
|
---
|
||||||
---@returns (number) Decided by {findstart}:
|
---@returns (number) Decided by {findstart}:
|
||||||
--- - findstart=0: column where the completion starts, or -2 or -3
|
--- - findstart=0: column where the completion starts, or -2 or -3
|
||||||
@@ -2208,8 +2218,8 @@ end
|
|||||||
--- Otherwise, uses "workspace/symbol". If no results are returned from
|
--- Otherwise, uses "workspace/symbol". If no results are returned from
|
||||||
--- any LSP servers, falls back to using built-in tags.
|
--- any LSP servers, falls back to using built-in tags.
|
||||||
---
|
---
|
||||||
---@param pattern Pattern used to find a workspace symbol
|
---@param pattern string Pattern used to find a workspace symbol
|
||||||
---@param flags See |tag-function|
|
---@param flags string See |tag-function|
|
||||||
---
|
---
|
||||||
---@returns A list of matching tags
|
---@returns A list of matching tags
|
||||||
function lsp.tagfunc(...)
|
function lsp.tagfunc(...)
|
||||||
@@ -2218,7 +2228,7 @@ end
|
|||||||
|
|
||||||
---Checks whether a client is stopped.
|
---Checks whether a client is stopped.
|
||||||
---
|
---
|
||||||
---@param client_id (Number)
|
---@param client_id (number)
|
||||||
---@returns true if client is stopped, false otherwise.
|
---@returns true if client is stopped, false otherwise.
|
||||||
function lsp.client_is_stopped(client_id)
|
function lsp.client_is_stopped(client_id)
|
||||||
return active_clients[client_id] == nil
|
return active_clients[client_id] == nil
|
||||||
@@ -2227,7 +2237,7 @@ end
|
|||||||
--- Gets a map of client_id:client pairs for the given buffer, where each value
|
--- Gets a map of client_id:client pairs for the given buffer, where each value
|
||||||
--- is a |vim.lsp.client| object.
|
--- is a |vim.lsp.client| object.
|
||||||
---
|
---
|
||||||
---@param bufnr (optional, number): Buffer handle, or 0 for current
|
---@param bufnr (number|nil): Buffer handle, or 0 for current
|
||||||
---@returns (table) Table of (client_id, client) pairs
|
---@returns (table) Table of (client_id, client) pairs
|
||||||
---@deprecated Use |vim.lsp.get_active_clients()| instead.
|
---@deprecated Use |vim.lsp.get_active_clients()| instead.
|
||||||
function lsp.buf_get_clients(bufnr)
|
function lsp.buf_get_clients(bufnr)
|
||||||
@@ -2256,7 +2266,7 @@ lsp.log_levels = log.levels
|
|||||||
---
|
---
|
||||||
---@see |vim.lsp.log_levels|
|
---@see |vim.lsp.log_levels|
|
||||||
---
|
---
|
||||||
---@param level [number|string] the case insensitive level name or number
|
---@param level (number|string) the case insensitive level name or number
|
||||||
function lsp.set_log_level(level)
|
function lsp.set_log_level(level)
|
||||||
if type(level) == 'string' or type(level) == 'number' then
|
if type(level) == 'string' or type(level) == 'number' then
|
||||||
log.set_level(level)
|
log.set_level(level)
|
||||||
|
@@ -141,7 +141,7 @@ end
|
|||||||
vim.tbl_add_reverse_lookup(log.levels)
|
vim.tbl_add_reverse_lookup(log.levels)
|
||||||
|
|
||||||
--- Sets the current log level.
|
--- Sets the current log level.
|
||||||
---@param level (string or number) One of `vim.lsp.log.levels`
|
---@param level (string|number) One of `vim.lsp.log.levels`
|
||||||
function log.set_level(level)
|
function log.set_level(level)
|
||||||
if type(level) == 'string' then
|
if type(level) == 'string' then
|
||||||
current_log_level =
|
current_log_level =
|
||||||
|
Reference in New Issue
Block a user