mirror of
https://github.com/neovim/neovim.git
synced 2026-04-30 19:24:09 +00:00
fix: type fixes
Type fixes caught by emmylua
This commit is contained in:
committed by
Lewis Russell
parent
4c333fdbb7
commit
3b6084ddf4
@@ -6,7 +6,7 @@ local ms = lsp.protocol.Methods
|
||||
---@param name string
|
||||
---@param range lsp.Range
|
||||
---@param uri string
|
||||
---@param position_encoding string
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@return {name: string, filename: string, cmd: string, kind?: string}
|
||||
local function mk_tag_item(name, range, uri, position_encoding)
|
||||
local bufnr = vim.uri_to_bufnr(uri)
|
||||
@@ -32,7 +32,7 @@ local function query_definition(pattern)
|
||||
|
||||
--- @param range lsp.Range
|
||||
--- @param uri string
|
||||
--- @param position_encoding string
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
local add = function(range, uri, position_encoding)
|
||||
table.insert(results, mk_tag_item(pattern, range, uri, position_encoding))
|
||||
end
|
||||
|
||||
@@ -545,7 +545,7 @@ function M.format(opts)
|
||||
end
|
||||
|
||||
local passed_multiple_ranges = (range and #range ~= 0 and type(range[1]) == 'table')
|
||||
local method ---@type string
|
||||
local method ---@type vim.lsp.protocol.Method.ClientToServer
|
||||
if passed_multiple_ranges then
|
||||
method = ms.textDocument_rangesFormatting
|
||||
elseif range then
|
||||
@@ -579,10 +579,11 @@ function M.format(opts)
|
||||
|
||||
local ret = params --[[@as lsp.DocumentFormattingParams|lsp.DocumentRangeFormattingParams|lsp.DocumentRangesFormattingParams]]
|
||||
if passed_multiple_ranges then
|
||||
--- @cast range {start:[integer,integer],end:[integer, integer]}[]
|
||||
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
|
||||
--- @cast range {start:[integer,integer],end:[integer, integer]}
|
||||
ret = params --[[@as lsp.DocumentRangeFormattingParams]]
|
||||
ret.range = to_lsp_range(range)
|
||||
end
|
||||
@@ -660,7 +661,7 @@ function M.rename(new_name, opts)
|
||||
local cword = vim.fn.expand('<cword>')
|
||||
|
||||
--- @param range lsp.Range
|
||||
--- @param position_encoding string
|
||||
--- @param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
local function get_text_at_range(range, position_encoding)
|
||||
return api.nvim_buf_get_text(
|
||||
bufnr,
|
||||
@@ -1199,7 +1200,7 @@ local function on_code_action_results(results, opts)
|
||||
return title
|
||||
end
|
||||
|
||||
local source = lsp.get_client_by_id(item.ctx.client_id).name
|
||||
local source = assert(lsp.get_client_by_id(item.ctx.client_id)).name
|
||||
return ('%s [%s]'):format(title, source)
|
||||
end
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ local validate = vim.validate
|
||||
--- @field name string
|
||||
---
|
||||
--- See [vim.lsp.ClientConfig].
|
||||
--- @field offset_encoding string
|
||||
--- @field offset_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---
|
||||
--- A ring buffer (|vim.ringbuf()|) containing progress messages
|
||||
--- sent by the server.
|
||||
@@ -440,16 +440,16 @@ function Client.create(config)
|
||||
--- @type vim.lsp.rpc.Dispatchers
|
||||
local dispatchers = {
|
||||
notification = function(...)
|
||||
return self:_notification(...)
|
||||
self:_notification(...)
|
||||
end,
|
||||
server_request = function(...)
|
||||
return self:_server_request(...)
|
||||
end,
|
||||
on_error = function(...)
|
||||
return self:_on_error(...)
|
||||
self:_on_error(...)
|
||||
end,
|
||||
on_exit = function(...)
|
||||
return self:_on_exit(...)
|
||||
self:_on_exit(...)
|
||||
end,
|
||||
}
|
||||
|
||||
@@ -597,7 +597,7 @@ end
|
||||
|
||||
--- @private
|
||||
--- @param id integer
|
||||
--- @param req_type 'pending'|'complete'|'cancel'|
|
||||
--- @param req_type 'pending'|'complete'|'cancel'
|
||||
--- @param bufnr? integer (only required for req_type='pending')
|
||||
--- @param method? string (only required for req_type='pending')
|
||||
function Client:_process_request(id, req_type, bufnr, method)
|
||||
|
||||
@@ -258,20 +258,22 @@ end
|
||||
---@param result lsp.CodeLens[]
|
||||
---@param ctx lsp.HandlerContext
|
||||
function M.on_codelens(err, result, ctx)
|
||||
local bufnr = assert(ctx.bufnr)
|
||||
|
||||
if err then
|
||||
active_refreshes[assert(ctx.bufnr)] = nil
|
||||
active_refreshes[bufnr] = nil
|
||||
log.error('codelens', err)
|
||||
return
|
||||
end
|
||||
|
||||
M.save(result, ctx.bufnr, ctx.client_id)
|
||||
M.save(result, bufnr, ctx.client_id)
|
||||
|
||||
-- Eager display for any resolved (and unresolved) lenses and refresh them
|
||||
-- once resolved.
|
||||
M.display(result, ctx.bufnr, ctx.client_id)
|
||||
resolve_lenses(result, ctx.bufnr, ctx.client_id, function()
|
||||
active_refreshes[assert(ctx.bufnr)] = nil
|
||||
M.display(result, ctx.bufnr, ctx.client_id)
|
||||
M.display(result, bufnr, ctx.client_id)
|
||||
resolve_lenses(result, bufnr, ctx.client_id, function()
|
||||
active_refreshes[bufnr] = nil
|
||||
M.display(result, bufnr, ctx.client_id)
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ local lsp = vim.lsp
|
||||
local protocol = lsp.protocol
|
||||
local ms = protocol.Methods
|
||||
|
||||
local rtt_ms = 50
|
||||
local rtt_ms = 50.0
|
||||
local ns_to_ms = 0.000001
|
||||
|
||||
--- @alias vim.lsp.CompletionResult lsp.CompletionList | lsp.CompletionItem[]
|
||||
@@ -92,7 +92,7 @@ local completion_timer = nil
|
||||
|
||||
--- @return uv.uv_timer_t
|
||||
local function new_timer()
|
||||
return assert(vim.uv.new_timer())
|
||||
return (assert(vim.uv.new_timer()))
|
||||
end
|
||||
|
||||
local function reset_timer()
|
||||
@@ -110,7 +110,7 @@ end
|
||||
local function exp_avg(window, warmup)
|
||||
local count = 0
|
||||
local sum = 0
|
||||
local value = 0
|
||||
local value = 0.0
|
||||
|
||||
return function(sample)
|
||||
if count < warmup then
|
||||
@@ -278,7 +278,6 @@ end
|
||||
--- Turns the result of a `textDocument/completion` request into vim-compatible
|
||||
--- |complete-items|.
|
||||
---
|
||||
--- @private
|
||||
--- @param result vim.lsp.CompletionResult Result of `textDocument/completion`
|
||||
--- @param prefix string prefix to filter the completion items
|
||||
--- @param client_id integer? Client ID
|
||||
@@ -365,7 +364,7 @@ end
|
||||
--- @param lnum integer 0-indexed
|
||||
--- @param line string
|
||||
--- @param items lsp.CompletionItem[]
|
||||
--- @param encoding string
|
||||
--- @param encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
--- @return integer?
|
||||
local function adjust_start_col(lnum, line, items, encoding)
|
||||
local min_start_char = nil
|
||||
@@ -384,7 +383,6 @@ local function adjust_start_col(lnum, line, items, encoding)
|
||||
end
|
||||
end
|
||||
|
||||
--- @private
|
||||
--- @param line string line content
|
||||
--- @param lnum integer 0-indexed line number
|
||||
--- @param cursor_col integer
|
||||
@@ -392,7 +390,7 @@ end
|
||||
--- @param client_start_boundary integer 0-indexed word boundary
|
||||
--- @param server_start_boundary? integer 0-indexed word boundary, based on textEdit.range.start.character
|
||||
--- @param result vim.lsp.CompletionResult
|
||||
--- @param encoding string
|
||||
--- @param encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
--- @return table[] matches
|
||||
--- @return integer? server_start_boundary
|
||||
function M._convert_results(
|
||||
@@ -487,7 +485,7 @@ local function trigger(bufnr, clients, ctx)
|
||||
local line = api.nvim_get_current_line()
|
||||
local line_to_cursor = line:sub(1, cursor_col)
|
||||
local word_boundary = vim.fn.match(line_to_cursor, '\\k*$')
|
||||
local start_time = vim.uv.hrtime()
|
||||
local start_time = vim.uv.hrtime() --[[@as integer]]
|
||||
Context.last_request_time = start_time
|
||||
|
||||
local cancel_request = request(clients, bufnr, win, ctx, function(responses)
|
||||
@@ -557,7 +555,7 @@ local function on_insert_char_pre(handle)
|
||||
else
|
||||
completion_timer = new_timer()
|
||||
completion_timer:start(
|
||||
debounce_ms,
|
||||
math.floor(debounce_ms),
|
||||
0,
|
||||
vim.schedule_wrap(function()
|
||||
M.get({ ctx = ctx })
|
||||
|
||||
@@ -11,25 +11,28 @@ local augroup = api.nvim_create_augroup('nvim.lsp.diagnostic', {})
|
||||
---@class (private) vim.lsp.diagnostic.BufState
|
||||
---@field enabled boolean Whether diagnostics are enabled for this buffer
|
||||
---@field client_result_id table<integer, string?> Latest responded `resultId`
|
||||
---@type table<integer, vim.lsp.diagnostic.BufState?>
|
||||
|
||||
---@type table<integer,vim.lsp.diagnostic.BufState>
|
||||
local bufstates = {}
|
||||
|
||||
local DEFAULT_CLIENT_ID = -1
|
||||
|
||||
---@param severity lsp.DiagnosticSeverity
|
||||
---@return vim.diagnostic.Severity
|
||||
local function severity_lsp_to_vim(severity)
|
||||
if type(severity) == 'string' then
|
||||
severity = protocol.DiagnosticSeverity[severity] --- @type integer
|
||||
return protocol.DiagnosticSeverity[severity] --[[@as vim.diagnostic.Severity]]
|
||||
end
|
||||
return severity
|
||||
end
|
||||
|
||||
---@param severity vim.diagnostic.Severity|vim.diagnostic.SeverityName
|
||||
---@return lsp.DiagnosticSeverity
|
||||
local function severity_vim_to_lsp(severity)
|
||||
if type(severity) == 'string' then
|
||||
severity = vim.diagnostic.severity[severity] --- @type integer
|
||||
return vim.diagnostic.severity[severity]
|
||||
end
|
||||
return severity
|
||||
return severity --[[@as lsp.DiagnosticSeverity]]
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
@@ -186,10 +189,9 @@ function M.get_namespace(client_id, is_pull)
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
if is_pull then
|
||||
local server_id =
|
||||
vim.tbl_get((client or {}).server_capabilities, 'diagnosticProvider', 'identifier')
|
||||
local key = string.format('%d:%s', client_id, server_id or 'nil')
|
||||
local name = string.format(
|
||||
'nvim.lsp.%s.%d.%s',
|
||||
vim.tbl_get((client or {}).server_capabilities or {}, 'diagnosticProvider', 'identifier')
|
||||
local key = ('%d:%s'):format(client_id, server_id or 'nil')
|
||||
local name = ('nvim.lsp.%s.%d.%s'):format(
|
||||
client and client.name or 'unknown',
|
||||
client_id,
|
||||
server_id or 'nil'
|
||||
@@ -200,15 +202,15 @@ function M.get_namespace(client_id, is_pull)
|
||||
_client_pull_namespaces[key] = ns
|
||||
end
|
||||
return ns
|
||||
else
|
||||
local name = string.format('nvim.lsp.%s.%d', client and client.name or 'unknown', client_id)
|
||||
local ns = _client_push_namespaces[client_id]
|
||||
if not ns then
|
||||
ns = api.nvim_create_namespace(name)
|
||||
_client_push_namespaces[client_id] = ns
|
||||
end
|
||||
return ns
|
||||
end
|
||||
|
||||
local ns = _client_push_namespaces[client_id]
|
||||
if not ns then
|
||||
local name = ('nvim.lsp.%s.%d'):format(client and client.name or 'unknown', client_id)
|
||||
ns = api.nvim_create_namespace(name)
|
||||
_client_push_namespaces[client_id] = ns
|
||||
end
|
||||
return ns
|
||||
end
|
||||
|
||||
--- @param uri string
|
||||
@@ -227,9 +229,7 @@ local function handle_diagnostics(uri, client_id, diagnostics, is_pull)
|
||||
return
|
||||
end
|
||||
|
||||
if client_id == nil then
|
||||
client_id = DEFAULT_CLIENT_ID
|
||||
end
|
||||
client_id = client_id or DEFAULT_CLIENT_ID
|
||||
|
||||
local namespace = M.get_namespace(client_id, is_pull)
|
||||
|
||||
@@ -380,7 +380,6 @@ end
|
||||
|
||||
--- Enable pull diagnostics for a buffer
|
||||
---@param bufnr (integer) Buffer handle, or 0 for current
|
||||
---@private
|
||||
function M._enable(bufnr)
|
||||
bufnr = vim._resolve_bufnr(bufnr)
|
||||
|
||||
|
||||
@@ -40,7 +40,13 @@ local document_color_opts = { style = 'background' }
|
||||
--- @param color string
|
||||
local function get_contrast_color(color)
|
||||
local r_s, g_s, b_s = color:match('^#(%x%x)(%x%x)(%x%x)$')
|
||||
if not (r_s and g_s and b_s) then
|
||||
error('Invalid color format: ' .. color)
|
||||
end
|
||||
local r, g, b = tonumber(r_s, 16), tonumber(g_s, 16), tonumber(b_s, 16)
|
||||
if not (r and g and b) then
|
||||
error('Invalid color format: ' .. color)
|
||||
end
|
||||
|
||||
-- Source: https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
|
||||
-- Using power 2.2 is a close approximation to full piecewise transform
|
||||
@@ -185,7 +191,7 @@ local function buf_enable(bufnr)
|
||||
api.nvim_buf_attach(bufnr, false, {
|
||||
on_reload = function(_, buf)
|
||||
buf_clear(buf)
|
||||
if bufstates[buf].enabled then
|
||||
if assert(bufstates[buf]).enabled then
|
||||
M._buf_refresh(buf)
|
||||
end
|
||||
end,
|
||||
@@ -203,7 +209,7 @@ local function buf_enable(bufnr)
|
||||
|
||||
if
|
||||
(method == ms.textDocument_didChange or method == ms.textDocument_didOpen)
|
||||
and bufstates[args.buf].enabled
|
||||
and assert(bufstates[args.buf]).enabled
|
||||
then
|
||||
M._buf_refresh(args.buf, args.data.client_id)
|
||||
end
|
||||
@@ -254,7 +260,7 @@ function M.is_enabled(bufnr)
|
||||
reset_bufstate(bufnr, false)
|
||||
end
|
||||
|
||||
return bufstates[bufnr].enabled
|
||||
return assert(bufstates[bufnr]).enabled
|
||||
end
|
||||
|
||||
--- Enables document highlighting from the given language client in the given buffer.
|
||||
|
||||
@@ -241,7 +241,7 @@ end
|
||||
---
|
||||
--- The returned function has an optional {config} parameter that accepts |vim.lsp.ListOpts|
|
||||
---
|
||||
---@param map_result fun(resp, bufnr: integer, position_encoding: 'utf-8'|'utf-16'|'utf-32'): table to convert the response
|
||||
---@param map_result fun(resp: any, bufnr: integer, position_encoding: 'utf-8'|'utf-16'|'utf-32'): table to convert the response
|
||||
---@param entity string name of the resource used in a `not found` error message
|
||||
---@param title_fn fun(ctx: lsp.HandlerContext): string Function to call to generate list title
|
||||
---@return lsp.Handler
|
||||
|
||||
@@ -15,6 +15,7 @@ local globalstate = {
|
||||
---@field version? integer
|
||||
---@field client_hints? table<integer, table<integer, lsp.InlayHint[]>> client_id -> (lnum -> hints)
|
||||
---@field applied table<integer, integer> Last version of hints applied to this line
|
||||
|
||||
---@type table<integer, vim.lsp.inlay_hint.bufstate>
|
||||
local bufstates = vim.defaulttable(function(_)
|
||||
return setmetatable({ applied = {} }, {
|
||||
|
||||
@@ -36,6 +36,7 @@ end
|
||||
local M = {}
|
||||
|
||||
--- Mapping of error codes used by the client
|
||||
--- @enum vim.lsp.rpc.ClientErrors
|
||||
local client_errors = {
|
||||
INVALID_SERVER_MESSAGE = 1,
|
||||
INVALID_SERVER_JSON = 2,
|
||||
@@ -150,6 +151,7 @@ local default_dispatchers = {
|
||||
|
||||
local strbuffer = require('vim._stringbuffer')
|
||||
|
||||
--- @async
|
||||
local function request_parser_loop()
|
||||
local buf = strbuffer.new()
|
||||
while true do
|
||||
@@ -279,7 +281,7 @@ function Client:request(method, params, callback, notify_reply_callback)
|
||||
end
|
||||
|
||||
---@package
|
||||
---@param errkind integer
|
||||
---@param errkind vim.lsp.rpc.ClientErrors
|
||||
---@param ... any
|
||||
function Client:on_error(errkind, ...)
|
||||
assert(M.client_errors[errkind])
|
||||
@@ -375,7 +377,7 @@ function Client:handle_body(body)
|
||||
-- This works because we are expecting vim.NIL here
|
||||
elseif decoded.id and (decoded.result ~= vim.NIL or decoded.error ~= vim.NIL) then
|
||||
-- We sent a number, so we expect a number.
|
||||
local result_id = assert(tonumber(decoded.id), 'response id must be a number')
|
||||
local result_id = assert(tonumber(decoded.id), 'response id must be a number') --[[@as integer]]
|
||||
|
||||
-- Notify the user that a response was received for the request
|
||||
local notify_reply_callback = self.notify_reply_callbacks[result_id]
|
||||
|
||||
@@ -90,6 +90,7 @@ end
|
||||
|
||||
--- Converts a raw token list to a list of highlight ranges used by the on_win callback
|
||||
---
|
||||
---@async
|
||||
---@param data integer[]
|
||||
---@param bufnr integer
|
||||
---@param client vim.lsp.Client
|
||||
@@ -326,6 +327,7 @@ end
|
||||
--- Finally, a redraw command is issued to force nvim to redraw the screen to
|
||||
--- pick up changed highlight tokens.
|
||||
---
|
||||
---@async
|
||||
---@param response lsp.SemanticTokens|lsp.SemanticTokensDelta
|
||||
---@private
|
||||
function STHighlighter:process_response(response, client, version)
|
||||
@@ -491,7 +493,7 @@ function STHighlighter:on_win(topline, botline)
|
||||
local is_folded, foldend
|
||||
|
||||
for i = first, last do
|
||||
local token = highlights[i]
|
||||
local token = assert(highlights[i])
|
||||
|
||||
is_folded, foldend = check_fold(token.line + 1, foldend)
|
||||
|
||||
|
||||
@@ -52,10 +52,11 @@ local str_utf_end = vim.str_utf_end
|
||||
-- utf-8 index and either the utf-16, or utf-32 index.
|
||||
---@param line string the line to index into
|
||||
---@param byte integer the byte idx
|
||||
---@param position_encoding string utf-8|utf-16|utf-32|nil (default: utf-8)
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'? (default: utf-8)
|
||||
---@return integer byte_idx of first change position
|
||||
---@return integer char_idx of first change position
|
||||
local function align_end_position(line, byte, position_encoding)
|
||||
position_encoding = position_encoding or 'utf-8'
|
||||
local char --- @type integer
|
||||
-- If on the first byte, or an empty string: the trivial case
|
||||
if byte == 1 or #line == 0 then
|
||||
@@ -93,7 +94,7 @@ end
|
||||
---@param firstline integer firstline from on_lines, adjusted to 1-index
|
||||
---@param lastline integer lastline from on_lines, adjusted to 1-index
|
||||
---@param new_lastline integer new_lastline from on_lines, adjusted to 1-index
|
||||
---@param position_encoding string utf-8|utf-16|utf-32|nil (fallback to utf-8)
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'? (default: utf-8)
|
||||
---@return vim.lsp.sync.Range result table include line_idx, byte_idx, and char_idx of first change position
|
||||
local function compute_start_range(
|
||||
prev_lines,
|
||||
@@ -103,6 +104,8 @@ local function compute_start_range(
|
||||
new_lastline,
|
||||
position_encoding
|
||||
)
|
||||
position_encoding = position_encoding or 'utf-8'
|
||||
|
||||
local char_idx --- @type integer?
|
||||
local byte_idx --- @type integer?
|
||||
-- If firstline == lastline, no existing text is changed. All edit operations
|
||||
@@ -130,8 +133,8 @@ local function compute_start_range(
|
||||
return { line_idx = firstline, byte_idx = 1, char_idx = 1 }
|
||||
end
|
||||
|
||||
local prev_line = prev_lines[firstline]
|
||||
local curr_line = curr_lines[firstline]
|
||||
local prev_line = assert(prev_lines[firstline])
|
||||
local curr_line = assert(curr_lines[firstline])
|
||||
|
||||
-- Iterate across previous and current line containing first change
|
||||
-- to find the first different byte.
|
||||
@@ -174,7 +177,7 @@ end
|
||||
---@param firstline integer
|
||||
---@param lastline integer
|
||||
---@param new_lastline integer
|
||||
---@param position_encoding string
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@return vim.lsp.sync.Range prev_end_range
|
||||
---@return vim.lsp.sync.Range curr_end_range
|
||||
local function compute_end_range(
|
||||
@@ -189,7 +192,7 @@ local function compute_end_range(
|
||||
-- A special case for the following `firstline == new_lastline` case where lines are deleted.
|
||||
-- Even if the buffer has become empty, nvim behaves as if it has an empty line with eol.
|
||||
if #curr_lines == 1 and curr_lines[1] == '' then
|
||||
local prev_line = prev_lines[lastline - 1]
|
||||
local prev_line = assert(prev_lines[lastline - 1])
|
||||
return {
|
||||
line_idx = lastline - 1,
|
||||
byte_idx = #prev_line + 1,
|
||||
@@ -219,8 +222,8 @@ local function compute_end_range(
|
||||
local prev_line_idx = lastline - 1
|
||||
local curr_line_idx = new_lastline - 1
|
||||
|
||||
local prev_line = prev_lines[lastline - 1]
|
||||
local curr_line = curr_lines[new_lastline - 1]
|
||||
local prev_line = assert(prev_lines[lastline - 1])
|
||||
local curr_line = assert(curr_lines[new_lastline - 1])
|
||||
|
||||
local prev_line_length = #prev_line
|
||||
local curr_line_length = #curr_line
|
||||
@@ -284,8 +287,8 @@ end
|
||||
|
||||
--- Get the text of the range defined by start and end line/column
|
||||
---@param lines table list of lines
|
||||
---@param start_range table table returned by first_difference
|
||||
---@param end_range table new_end_range returned by last_difference
|
||||
---@param start_range vim.lsp.sync.Range table returned by first_difference
|
||||
---@param end_range vim.lsp.sync.Range new_end_range returned by last_difference
|
||||
---@return string text extracted from defined region
|
||||
local function extract_text(lines, start_range, end_range, line_ending)
|
||||
if not lines[start_range.line_idx] then
|
||||
@@ -326,7 +329,7 @@ end
|
||||
---@param lines string[]
|
||||
---@param start_range vim.lsp.sync.Range
|
||||
---@param end_range vim.lsp.sync.Range
|
||||
---@param position_encoding string
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@param line_ending string
|
||||
---@return integer
|
||||
local function compute_range_length(lines, start_range, end_range, position_encoding, line_ending)
|
||||
@@ -352,7 +355,9 @@ local function compute_range_length(lines, start_range, end_range, position_enco
|
||||
for idx = start_range.line_idx + 1, end_range.line_idx - 1 do
|
||||
-- Length full line plus newline character
|
||||
if #lines[idx] > 0 then
|
||||
range_length = range_length + str_utfindex(lines[idx], position_encoding) + #line_ending
|
||||
range_length = range_length
|
||||
+ str_utfindex(assert(lines[idx]), position_encoding)
|
||||
+ #line_ending
|
||||
else
|
||||
range_length = range_length + line_ending_length
|
||||
end
|
||||
@@ -372,7 +377,7 @@ end
|
||||
---@param firstline integer line to begin search for first difference
|
||||
---@param lastline integer line to begin search in old_lines for last difference
|
||||
---@param new_lastline integer line to begin search in new_lines for last difference
|
||||
---@param position_encoding string encoding requested by language server
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32' encoding requested by language server
|
||||
---@param line_ending string
|
||||
---@return lsp.TextDocumentContentChangeEvent : see https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
|
||||
function M.compute_diff(
|
||||
|
||||
@@ -68,6 +68,7 @@ local function get_border_size(opts)
|
||||
end
|
||||
|
||||
--- @param e string
|
||||
--- @return integer
|
||||
local function border_height(e)
|
||||
return #e > 0 and 1 or 0
|
||||
end
|
||||
@@ -133,9 +134,9 @@ function M.set_lines(lines, A, B, new_lines)
|
||||
error('Invalid range: ' .. vim.inspect({ A = A, B = B, #lines, new_lines }))
|
||||
end
|
||||
local prefix = ''
|
||||
local suffix = lines[i_n]:sub(B[2] + 1)
|
||||
local suffix = assert(lines[i_n]):sub(B[2] + 1)
|
||||
if A[2] > 0 then
|
||||
prefix = lines[i_0]:sub(1, A[2])
|
||||
prefix = assert(lines[i_0]):sub(1, A[2])
|
||||
end
|
||||
local n = i_n - i_0 + 1
|
||||
if n ~= #new_lines then
|
||||
@@ -181,7 +182,7 @@ end
|
||||
---
|
||||
---@param bufnr integer bufnr to get the lines from
|
||||
---@param rows integer[] zero-indexed line numbers
|
||||
---@return table<integer, string>|string a table mapping rows to lines
|
||||
---@return table<integer, string> # a table mapping rows to lines
|
||||
local function get_lines(bufnr, rows)
|
||||
--- @type integer[]
|
||||
rows = type(rows) == 'table' and rows or { rows }
|
||||
@@ -219,7 +220,7 @@ local function get_lines(bufnr, rows)
|
||||
-- get the data from the file
|
||||
local fd = uv.fs_open(filename, 'r', 438)
|
||||
if not fd then
|
||||
return ''
|
||||
return {}
|
||||
end
|
||||
local stat = assert(uv.fs_fstat(fd))
|
||||
local data = assert(uv.fs_read(fd, stat.size, 0))
|
||||
@@ -322,6 +323,8 @@ function M.apply_text_edits(text_edits, bufnr, position_encoding)
|
||||
end
|
||||
end
|
||||
|
||||
--- @cast text_edits (lsp.TextEdit|{_index: integer})[]
|
||||
|
||||
-- Sort text_edits
|
||||
---@param a lsp.TextEdit | { _index: integer }
|
||||
---@param b lsp.TextEdit | { _index: integer }
|
||||
@@ -1298,7 +1301,6 @@ end
|
||||
--- 2. Successive empty lines are collapsed into a single empty line
|
||||
--- 3. Thematic breaks are expanded to the given width
|
||||
---
|
||||
---@private
|
||||
---@param contents string[]
|
||||
---@param opts? vim.lsp.util._normalize_markdown.Opts
|
||||
---@return string[] table of lines containing normalized Markdown
|
||||
@@ -1369,7 +1371,6 @@ local function close_preview_autocmd(events, winnr, bufnrs)
|
||||
end
|
||||
end
|
||||
|
||||
---@private
|
||||
--- Computes size of float needed to show contents (with optional wrapping)
|
||||
---
|
||||
---@param contents string[] of lines to show in window
|
||||
@@ -1796,7 +1797,7 @@ function M.symbols_to_items(symbols, bufnr, position_encoding)
|
||||
'symbols_to_items must be called with valid position encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
position_encoding = vim.lsp.get_clients({ bufnr = bufnr })[1].offset_encoding
|
||||
position_encoding = assert(vim.lsp.get_clients({ bufnr = bufnr })[1]).offset_encoding
|
||||
end
|
||||
|
||||
local items = {} --- @type vim.quickfix.entry[]
|
||||
@@ -1874,11 +1875,11 @@ end
|
||||
---@return string filetype or "markdown" if it was unchanged.
|
||||
function M.try_trim_markdown_code_blocks(lines)
|
||||
vim.deprecate('vim.lsp.util.try_trim_markdown_code_blocks()', 'nil', '0.12')
|
||||
local language_id = lines[1]:match('^```(.*)')
|
||||
local language_id = assert(lines[1]):match('^```(.*)')
|
||||
if language_id then
|
||||
local has_inner_code_fence = false
|
||||
for i = 2, (#lines - 1) do
|
||||
local line = lines[i]
|
||||
local line = lines[i] --[[@as string]]
|
||||
if line:sub(1, 3) == '```' then
|
||||
has_inner_code_fence = true
|
||||
break
|
||||
@@ -1937,7 +1938,7 @@ end
|
||||
--- Utility function for getting the encoding of the first LSP client on the given buffer.
|
||||
---@deprecated
|
||||
---@param bufnr integer buffer handle or 0 for current, defaults to current
|
||||
---@return string encoding first client if there is one, nil otherwise
|
||||
---@return 'utf-8'|'utf-16'|'utf-32' encoding first client if there is one, nil otherwise
|
||||
function M._get_offset_encoding(bufnr)
|
||||
validate('bufnr', bufnr, 'number', true)
|
||||
|
||||
@@ -1963,6 +1964,7 @@ function M._get_offset_encoding(bufnr)
|
||||
)
|
||||
end
|
||||
end
|
||||
--- @cast offset_encoding -? hack - not safe
|
||||
|
||||
return offset_encoding
|
||||
end
|
||||
@@ -2056,7 +2058,7 @@ end
|
||||
--- Create the workspace params
|
||||
---@param added lsp.WorkspaceFolder[]
|
||||
---@param removed lsp.WorkspaceFolder[]
|
||||
---@return lsp.WorkspaceFoldersChangeEvent
|
||||
---@return lsp.DidChangeWorkspaceFoldersParams
|
||||
function M.make_workspace_params(added, removed)
|
||||
return { event = { added = added, removed = removed } }
|
||||
end
|
||||
@@ -2105,7 +2107,7 @@ function M.character_offset(buf, row, col, offset_encoding)
|
||||
'character_offset must be called with valid offset encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
offset_encoding = vim.lsp.get_clients({ bufnr = buf })[1].offset_encoding
|
||||
offset_encoding = assert(vim.lsp.get_clients({ bufnr = buf })[1]).offset_encoding
|
||||
end
|
||||
return vim.str_utfindex(line, offset_encoding, col, false)
|
||||
end
|
||||
@@ -2168,7 +2170,6 @@ end
|
||||
---@field method? vim.lsp.protocol.Method.ClientToServer.Request
|
||||
---@field type? string
|
||||
|
||||
---@private
|
||||
--- Cancel all {filter}ed requests.
|
||||
---
|
||||
---@param filter? vim.lsp.util._cancel_requests.Filter
|
||||
@@ -2203,10 +2204,9 @@ end
|
||||
---@field client_id? integer Client ID to refresh (default: all clients)
|
||||
---@field handler? lsp.Handler
|
||||
|
||||
---@private
|
||||
--- Request updated LSP information for a buffer.
|
||||
---
|
||||
---@param method string LSP method to call
|
||||
---@param method vim.lsp.protocol.Method.ClientToServer.Request LSP method to call
|
||||
---@param opts? vim.lsp.util._refresh.Opts Options table
|
||||
function M._refresh(method, opts)
|
||||
opts = opts or {}
|
||||
|
||||
Reference in New Issue
Block a user