mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
fix: resolve all remaining LuaLS diagnostics
This commit is contained in:
committed by
Lewis Russell
parent
83479b95ab
commit
6aa42e8f92
@@ -64,7 +64,7 @@ local state_by_group = setmetatable({}, {
|
||||
---@param client vim.lsp.Client
|
||||
---@return vim.lsp.CTGroup
|
||||
local function get_group(client)
|
||||
local allow_inc_sync = vim.F.if_nil(client.flags.allow_incremental_sync, true) --- @type boolean
|
||||
local allow_inc_sync = vim.F.if_nil(client.flags.allow_incremental_sync, true)
|
||||
local change_capability = vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'change')
|
||||
local sync_kind = change_capability or protocol.TextDocumentSyncKind.None
|
||||
if not allow_inc_sync and change_capability == protocol.TextDocumentSyncKind.Incremental then
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---@meta
|
||||
error('Cannot require a meta file')
|
||||
|
||||
---@alias lsp.Handler fun(err: lsp.ResponseError?, result: any, context: lsp.HandlerContext): ...any
|
||||
---@alias lsp.MultiHandler fun(results: table<integer,{err: lsp.ResponseError?, result: any}>, context: lsp.HandlerContext): ...any
|
||||
---@alias lsp.Handler fun(err: lsp.ResponseError?, result: any, context: lsp.HandlerContext, config?: table): ...any
|
||||
---@alias lsp.MultiHandler fun(results: table<integer,{err: lsp.ResponseError?, result: any}>, context: lsp.HandlerContext, config?: table): ...any
|
||||
|
||||
---@class lsp.HandlerContext
|
||||
---@field method string
|
||||
|
||||
@@ -127,6 +127,7 @@ local function node(type)
|
||||
end
|
||||
|
||||
-- stylua: ignore
|
||||
--- @diagnostic disable-next-line: missing-fields
|
||||
local G = P({
|
||||
'snippet';
|
||||
snippet = Ct(Cg(
|
||||
|
||||
@@ -450,10 +450,10 @@ local function range_from_selection(bufnr, mode)
|
||||
-- A user can start visual selection at the end and move backwards
|
||||
-- Normalize the range to start < end
|
||||
if start_row == end_row and end_col < start_col then
|
||||
end_col, start_col = start_col, end_col
|
||||
end_col, start_col = start_col, end_col --- @type integer, integer
|
||||
elseif end_row < start_row then
|
||||
start_row, end_row = end_row, start_row
|
||||
start_col, end_col = end_col, start_col
|
||||
start_row, end_row = end_row, start_row --- @type integer, integer
|
||||
start_col, end_col = end_col, start_col --- @type integer, integer
|
||||
end
|
||||
if mode == 'V' then
|
||||
start_col = 1
|
||||
@@ -553,25 +553,30 @@ function M.format(opts)
|
||||
|
||||
--- @param client vim.lsp.Client
|
||||
--- @param params lsp.DocumentFormattingParams
|
||||
--- @return lsp.DocumentFormattingParams
|
||||
--- @return lsp.DocumentFormattingParams|lsp.DocumentRangeFormattingParams|lsp.DocumentRangesFormattingParams
|
||||
local function set_range(client, params)
|
||||
local to_lsp_range = function(r) ---@return lsp.DocumentRangeFormattingParams|lsp.DocumentRangesFormattingParams
|
||||
--- @param r {start:[integer,integer],end:[integer, integer]}
|
||||
local function to_lsp_range(r)
|
||||
return util.make_given_range_params(r.start, r['end'], bufnr, client.offset_encoding).range
|
||||
end
|
||||
|
||||
local ret = params --[[@as lsp.DocumentFormattingParams|lsp.DocumentRangeFormattingParams|lsp.DocumentRangesFormattingParams]]
|
||||
if passed_multiple_ranges then
|
||||
params.ranges = vim.tbl_map(to_lsp_range, range)
|
||||
ret = params --[[@as lsp.DocumentRangesFormattingParams]]
|
||||
--- @cast range {start:[integer,integer],end:[integer, integer]}
|
||||
ret.ranges = vim.tbl_map(to_lsp_range, range)
|
||||
elseif range then
|
||||
params.range = to_lsp_range(range)
|
||||
ret = params --[[@as lsp.DocumentRangeFormattingParams]]
|
||||
ret.range = to_lsp_range(range)
|
||||
end
|
||||
return params
|
||||
return ret
|
||||
end
|
||||
|
||||
if opts.async then
|
||||
--- @param idx integer
|
||||
--- @param client vim.lsp.Client
|
||||
--- @param idx? integer
|
||||
--- @param client? vim.lsp.Client
|
||||
local function do_format(idx, client)
|
||||
if not client then
|
||||
if not idx or not client then
|
||||
return
|
||||
end
|
||||
local params = set_range(client, util.make_formatting_params(opts.formatting_options))
|
||||
@@ -650,16 +655,16 @@ function M.rename(new_name, opts)
|
||||
)[1]
|
||||
end
|
||||
|
||||
--- @param idx integer
|
||||
--- @param idx? integer
|
||||
--- @param client? vim.lsp.Client
|
||||
local function try_use_client(idx, client)
|
||||
if not client then
|
||||
if not idx or not client then
|
||||
return
|
||||
end
|
||||
|
||||
--- @param name string
|
||||
local function rename(name)
|
||||
local params = util.make_position_params(win, client.offset_encoding)
|
||||
local params = util.make_position_params(win, client.offset_encoding) --[[@as lsp.RenameParams]]
|
||||
params.newName = name
|
||||
local handler = client.handlers[ms.textDocument_rename]
|
||||
or lsp.handlers[ms.textDocument_rename]
|
||||
@@ -1229,6 +1234,7 @@ function M.code_action(opts)
|
||||
for _, client in ipairs(clients) do
|
||||
---@type lsp.CodeActionParams
|
||||
local params
|
||||
|
||||
if opts.range then
|
||||
assert(type(opts.range) == 'table', 'code_action range must be a table')
|
||||
local start = assert(opts.range.start, 'range must have a `start` property')
|
||||
@@ -1241,6 +1247,9 @@ function M.code_action(opts)
|
||||
else
|
||||
params = util.make_range_params(win, client.offset_encoding)
|
||||
end
|
||||
|
||||
--- @cast params lsp.CodeActionParams
|
||||
|
||||
if context.diagnostics then
|
||||
params.context = context
|
||||
else
|
||||
|
||||
@@ -904,18 +904,20 @@ end
|
||||
function Client:_get_registration(method, bufnr)
|
||||
bufnr = vim._resolve_bufnr(bufnr)
|
||||
for _, reg in ipairs(self.registrations[method] or {}) do
|
||||
if not reg.registerOptions or not reg.registerOptions.documentSelector then
|
||||
local regoptions = reg.registerOptions --[[@as {documentSelector:lsp.TextDocumentFilter[]}]]
|
||||
if not regoptions or not regoptions.documentSelector then
|
||||
return reg
|
||||
end
|
||||
local documentSelector = reg.registerOptions.documentSelector
|
||||
local documentSelector = regoptions.documentSelector
|
||||
local language = self:_get_language_id(bufnr)
|
||||
local uri = vim.uri_from_bufnr(bufnr)
|
||||
local fname = vim.uri_to_fname(uri)
|
||||
for _, filter in ipairs(documentSelector) do
|
||||
local flang, fscheme, fpat = filter.language, filter.scheme, filter.pattern
|
||||
if
|
||||
not (filter.language and language ~= filter.language)
|
||||
and not (filter.scheme and not vim.startswith(uri, filter.scheme .. ':'))
|
||||
and not (filter.pattern and not vim.glob.to_lpeg(filter.pattern):match(fname))
|
||||
not (flang and language ~= flang)
|
||||
and not (fscheme and not vim.startswith(uri, fscheme .. ':'))
|
||||
and not (type(fpat) == 'string' and not vim.glob.to_lpeg(fpat):match(fname))
|
||||
then
|
||||
return reg
|
||||
end
|
||||
|
||||
@@ -470,7 +470,7 @@ local function trigger(bufnr, clients)
|
||||
local server_start_boundary --- @type integer?
|
||||
for client_id, response in pairs(responses) do
|
||||
if response.err then
|
||||
vim.notify_once(response.err.message, vim.log.levels.warn)
|
||||
vim.notify_once(response.err.message, vim.log.levels.WARN)
|
||||
end
|
||||
|
||||
local result = response.result
|
||||
|
||||
@@ -20,7 +20,7 @@ end
|
||||
---@return lsp.DiagnosticSeverity
|
||||
local function severity_vim_to_lsp(severity)
|
||||
if type(severity) == 'string' then
|
||||
severity = vim.diagnostic.severity[severity]
|
||||
severity = vim.diagnostic.severity[severity] --- @type integer
|
||||
end
|
||||
return severity
|
||||
end
|
||||
@@ -89,6 +89,7 @@ local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
|
||||
string.format('Unsupported Markup message from LSP client %d', client_id),
|
||||
vim.lsp.log_levels.ERROR
|
||||
)
|
||||
--- @diagnostic disable-next-line: undefined-field,no-unknown
|
||||
message = diagnostic.message.value
|
||||
end
|
||||
local line = buf_lines and buf_lines[start.line + 1] or ''
|
||||
|
||||
@@ -47,7 +47,7 @@ RSC[ms.dollar_progress] = function(_, params, ctx)
|
||||
local value = params.value
|
||||
|
||||
if type(value) == 'table' then
|
||||
kind = value.kind
|
||||
kind = value.kind --- @type string
|
||||
-- Carry over title of `begin` messages to `report` and `end` messages
|
||||
-- So that consumers always have it available, even if they consume a
|
||||
-- subset of the full sequence
|
||||
|
||||
@@ -15,7 +15,6 @@ local sysname = vim.uv.os_uname().sysname
|
||||
--- @class vim.lsp.protocol.constants
|
||||
--- @nodoc
|
||||
local constants = {
|
||||
--- @enum lsp.DiagnosticSeverity
|
||||
DiagnosticSeverity = {
|
||||
-- Reports an error.
|
||||
Error = 1,
|
||||
@@ -27,7 +26,6 @@ local constants = {
|
||||
Hint = 4,
|
||||
},
|
||||
|
||||
--- @enum lsp.DiagnosticTag
|
||||
DiagnosticTag = {
|
||||
-- Unused or unnecessary code
|
||||
Unnecessary = 1,
|
||||
@@ -35,7 +33,6 @@ local constants = {
|
||||
Deprecated = 2,
|
||||
},
|
||||
|
||||
---@enum lsp.MessageType
|
||||
MessageType = {
|
||||
-- An error message.
|
||||
Error = 1,
|
||||
@@ -50,7 +47,6 @@ local constants = {
|
||||
},
|
||||
|
||||
-- The file event type.
|
||||
---@enum lsp.FileChangeType
|
||||
FileChangeType = {
|
||||
-- The file got created.
|
||||
Created = 1,
|
||||
@@ -149,7 +145,6 @@ local constants = {
|
||||
},
|
||||
|
||||
-- Represents reasons why a text document is saved.
|
||||
---@enum lsp.TextDocumentSaveReason
|
||||
TextDocumentSaveReason = {
|
||||
-- Manually triggered, e.g. by the user pressing save, by starting debugging,
|
||||
-- or by an API call.
|
||||
@@ -246,7 +241,6 @@ local constants = {
|
||||
|
||||
-- Defines whether the insert text in a completion item should be interpreted as
|
||||
-- plain text or a snippet.
|
||||
--- @enum lsp.InsertTextFormat
|
||||
InsertTextFormat = {
|
||||
-- The primary text to be inserted is treated as a plain string.
|
||||
PlainText = 1,
|
||||
@@ -305,7 +299,6 @@ local constants = {
|
||||
SourceOrganizeImports = 'source.organizeImports',
|
||||
},
|
||||
-- The reason why code actions were requested.
|
||||
---@enum lsp.CodeActionTriggerKind
|
||||
CodeActionTriggerKind = {
|
||||
-- Code actions were explicitly requested by the user or by an extension.
|
||||
Invoked = 1,
|
||||
|
||||
@@ -139,7 +139,7 @@ local function tokens_to_ranges(data, bufnr, client, request)
|
||||
|
||||
if token_type then
|
||||
local modifiers = modifiers_from_number(data[i + 4], token_modifiers)
|
||||
local end_char = start_char + data[i + 2]
|
||||
local end_char = start_char + data[i + 2] --- @type integer LuaLS bug
|
||||
local buf_line = lines and lines[line + 1] or ''
|
||||
local start_col = vim.str_byteindex(buf_line, encoding, start_char, false)
|
||||
local end_col = vim.str_byteindex(buf_line, encoding, end_char, false)
|
||||
|
||||
@@ -49,7 +49,8 @@ local function get_border_size(opts)
|
||||
if not border_size[border] then
|
||||
border_error(border)
|
||||
end
|
||||
return unpack(border_size[border])
|
||||
local r = border_size[border]
|
||||
return r[1], r[2]
|
||||
end
|
||||
|
||||
if 8 % #border ~= 0 then
|
||||
@@ -1897,6 +1898,7 @@ function M.make_position_params(window, position_encoding)
|
||||
'position_encoding param is required in vim.lsp.util.make_position_params. Defaulting to position encoding of the first client.',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
--- @diagnostic disable-next-line: deprecated
|
||||
position_encoding = M._get_offset_encoding(buf)
|
||||
end
|
||||
return {
|
||||
@@ -1953,6 +1955,7 @@ function M.make_range_params(window, position_encoding)
|
||||
'position_encoding param is required in vim.lsp.util.make_range_params. Defaulting to position encoding of the first client.',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
--- @diagnostic disable-next-line: deprecated
|
||||
position_encoding = M._get_offset_encoding(buf)
|
||||
end
|
||||
local position = make_position_param(window, position_encoding)
|
||||
@@ -1982,6 +1985,7 @@ function M.make_given_range_params(start_pos, end_pos, bufnr, position_encoding)
|
||||
'position_encoding param is required in vim.lsp.util.make_given_range_params. Defaulting to position encoding of the first client.',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
--- @diagnostic disable-next-line: deprecated
|
||||
position_encoding = M._get_offset_encoding(bufnr)
|
||||
end
|
||||
--- @type [integer, integer]
|
||||
|
||||
Reference in New Issue
Block a user