mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
refactor(lsp): add type annotations
This commit is contained in:
@@ -1415,8 +1415,9 @@ on_publish_diagnostics({_}, {result}, {ctx}, {config})
|
|||||||
<
|
<
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
|
• {result} (`lsp.PublishDiagnosticsParams`)
|
||||||
• {ctx} (`lsp.HandlerContext`)
|
• {ctx} (`lsp.HandlerContext`)
|
||||||
• {config} (`table`) Configuration table (see
|
• {config} (`vim.diagnostic.Opts?`) Configuration table (see
|
||||||
|vim.diagnostic.config()|).
|
|vim.diagnostic.config()|).
|
||||||
|
|
||||||
|
|
||||||
|
@@ -64,7 +64,7 @@ local state_by_group = setmetatable({}, {
|
|||||||
---@param client lsp.Client
|
---@param client lsp.Client
|
||||||
---@return vim.lsp.CTGroup
|
---@return vim.lsp.CTGroup
|
||||||
local function get_group(client)
|
local function get_group(client)
|
||||||
local allow_inc_sync = vim.F.if_nil(client.config.flags.allow_incremental_sync, true)
|
local allow_inc_sync = vim.F.if_nil(client.config.flags.allow_incremental_sync, true) --- @type boolean
|
||||||
local change_capability = vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'change')
|
local change_capability = vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'change')
|
||||||
local sync_kind = change_capability or protocol.TextDocumentSyncKind.None
|
local sync_kind = change_capability or protocol.TextDocumentSyncKind.None
|
||||||
if not allow_inc_sync and change_capability == protocol.TextDocumentSyncKind.Incremental then
|
if not allow_inc_sync and change_capability == protocol.TextDocumentSyncKind.Incremental then
|
||||||
|
@@ -24,7 +24,7 @@ function M:supports_registration(method)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- @param registrations lsp.Registration[]
|
--- @param registrations lsp.Registration[]
|
||||||
--- @private
|
--- @package
|
||||||
function M:register(registrations)
|
function M:register(registrations)
|
||||||
-- remove duplicates
|
-- remove duplicates
|
||||||
self:unregister(registrations)
|
self:unregister(registrations)
|
||||||
|
@@ -630,8 +630,9 @@ end
|
|||||||
--- @param code integer Error code
|
--- @param code integer Error code
|
||||||
--- @param err any Error arguments
|
--- @param err any Error arguments
|
||||||
function Client:write_error(code, err)
|
function Client:write_error(code, err)
|
||||||
log.error(self._log_prefix, 'on_error', { code = lsp.client_errors[code], err = err })
|
local client_error = lsp.client_errors[code] --- @type string|integer
|
||||||
err_message(self._log_prefix, ': Error ', lsp.client_errors[code], ': ', vim.inspect(err))
|
log.error(self._log_prefix, 'on_error', { code = client_error, err = err })
|
||||||
|
err_message(self._log_prefix, ': Error ', client_error, ': ', vim.inspect(err))
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param method string
|
--- @param method string
|
||||||
|
@@ -22,7 +22,7 @@ end
|
|||||||
---@param severity lsp.DiagnosticSeverity
|
---@param severity lsp.DiagnosticSeverity
|
||||||
local function severity_lsp_to_vim(severity)
|
local function severity_lsp_to_vim(severity)
|
||||||
if type(severity) == 'string' then
|
if type(severity) == 'string' then
|
||||||
severity = protocol.DiagnosticSeverity[severity]
|
severity = protocol.DiagnosticSeverity[severity] --- @type integer
|
||||||
end
|
end
|
||||||
return severity
|
return severity
|
||||||
end
|
end
|
||||||
@@ -48,7 +48,7 @@ local function line_byte_from_position(lines, lnum, col, offset_encoding)
|
|||||||
local line = lines[lnum + 1]
|
local line = lines[lnum + 1]
|
||||||
local ok, result = pcall(vim.str_byteindex, line, col, offset_encoding == 'utf-16')
|
local ok, result = pcall(vim.str_byteindex, line, col, offset_encoding == 'utf-16')
|
||||||
if ok then
|
if ok then
|
||||||
return result
|
return result --- @type integer
|
||||||
end
|
end
|
||||||
|
|
||||||
return col
|
return col
|
||||||
@@ -362,7 +362,7 @@ end
|
|||||||
--- implementation so it's simply marked @private rather than @deprecated.
|
--- implementation so it's simply marked @private rather than @deprecated.
|
||||||
---
|
---
|
||||||
---@param client_id integer
|
---@param client_id integer
|
||||||
---@param buffer_client_map table map of buffers to active clients
|
---@param buffer_client_map table<integer, table<integer, table>> map of buffers to active clients
|
||||||
---@private
|
---@private
|
||||||
function M.reset(client_id, buffer_client_map)
|
function M.reset(client_id, buffer_client_map)
|
||||||
buffer_client_map = vim.deepcopy(buffer_client_map)
|
buffer_client_map = vim.deepcopy(buffer_client_map)
|
||||||
@@ -462,7 +462,8 @@ function M._enable(bufnr)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
if bufstates[bufnr] and bufstates[bufnr].enabled then
|
||||||
_refresh(bufnr, { only_visible = true, client_id = opts.data.client_id })
|
local client_id = opts.data.client_id --- @type integer?
|
||||||
|
_refresh(bufnr, { only_visible = true, client_id = client_id })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
group = augroup,
|
group = augroup,
|
||||||
|
@@ -7,7 +7,7 @@ function M.check()
|
|||||||
|
|
||||||
local log = vim.lsp.log
|
local log = vim.lsp.log
|
||||||
local current_log_level = log.get_level()
|
local current_log_level = log.get_level()
|
||||||
local log_level_string = log.levels[current_log_level]
|
local log_level_string = log.levels[current_log_level] ---@type string
|
||||||
report_info(string.format('LSP log level : %s', log_level_string))
|
report_info(string.format('LSP log level : %s', log_level_string))
|
||||||
|
|
||||||
if current_log_level < log.levels.WARN then
|
if current_log_level < log.levels.WARN then
|
||||||
|
@@ -498,7 +498,7 @@ function Client:handle_body(body)
|
|||||||
if decoded.error then
|
if decoded.error then
|
||||||
decoded.error = setmetatable(decoded.error, {
|
decoded.error = setmetatable(decoded.error, {
|
||||||
__tostring = M.format_rpc_error,
|
__tostring = M.format_rpc_error,
|
||||||
})
|
}) --- @type table
|
||||||
end
|
end
|
||||||
self:try_call(
|
self:try_call(
|
||||||
M.client_errors.SERVER_RESULT_CALLBACK_ERROR,
|
M.client_errors.SERVER_RESULT_CALLBACK_ERROR,
|
||||||
|
@@ -58,8 +58,7 @@ local function byte_to_utf(line, byte, offset_encoding)
|
|||||||
-- convert to 0 based indexing for str_utfindex
|
-- convert to 0 based indexing for str_utfindex
|
||||||
byte = byte - 1
|
byte = byte - 1
|
||||||
|
|
||||||
local utf_idx --- @type integer
|
local utf_idx, _ --- @type integer, integer
|
||||||
local _
|
|
||||||
-- Convert the byte range to utf-{8,16,32} and convert 1-based (lua) indexing to 0-based
|
-- Convert the byte range to utf-{8,16,32} and convert 1-based (lua) indexing to 0-based
|
||||||
if offset_encoding == 'utf-16' then
|
if offset_encoding == 'utf-16' then
|
||||||
_, utf_idx = str_utfindex(line, byte)
|
_, utf_idx = str_utfindex(line, byte)
|
||||||
@@ -77,8 +76,7 @@ end
|
|||||||
---@param offset_encoding string
|
---@param offset_encoding string
|
||||||
---@return integer
|
---@return integer
|
||||||
local function compute_line_length(line, offset_encoding)
|
local function compute_line_length(line, offset_encoding)
|
||||||
local length --- @type integer
|
local length, _ --- @type integer, integer
|
||||||
local _
|
|
||||||
if offset_encoding == 'utf-16' then
|
if offset_encoding == 'utf-16' then
|
||||||
_, length = str_utfindex(line)
|
_, length = str_utfindex(line)
|
||||||
elseif offset_encoding == 'utf-32' then
|
elseif offset_encoding == 'utf-32' then
|
||||||
@@ -202,9 +200,10 @@ end
|
|||||||
--- prev_end_range is the text range sent to the server representing the changed region.
|
--- prev_end_range is the text range sent to the server representing the changed region.
|
||||||
--- curr_end_range is the text that should be collected and sent to the server.
|
--- curr_end_range is the text that should be collected and sent to the server.
|
||||||
--
|
--
|
||||||
---@param prev_lines table list of lines
|
|
||||||
---@param curr_lines table list of lines
|
|
||||||
---@param start_range table
|
---@param start_range table
|
||||||
|
---@param prev_lines string[] list of lines
|
||||||
|
---@param curr_lines string[] list of lines
|
||||||
|
---@param firstline integer
|
||||||
---@param lastline integer
|
---@param lastline integer
|
||||||
---@param new_lastline integer
|
---@param new_lastline integer
|
||||||
---@param offset_encoding string
|
---@param offset_encoding string
|
||||||
@@ -253,7 +252,7 @@ local function compute_end_range(
|
|||||||
-- Editing the same line
|
-- Editing the same line
|
||||||
-- If the byte offset is zero, that means there is a difference on the last byte (not newline)
|
-- If the byte offset is zero, that means there is a difference on the last byte (not newline)
|
||||||
if prev_line_idx == curr_line_idx then
|
if prev_line_idx == curr_line_idx then
|
||||||
local max_length
|
local max_length --- @type integer
|
||||||
if start_line_idx == prev_line_idx then
|
if start_line_idx == prev_line_idx then
|
||||||
-- Search until beginning of difference
|
-- Search until beginning of difference
|
||||||
max_length = min(
|
max_length = min(
|
||||||
|
Reference in New Issue
Block a user