mirror of
https://github.com/neovim/neovim.git
synced 2026-05-24 05:40:08 +00:00
Merge #39730 from ofseed/lsp-remove-deprecated
This commit is contained in:
@@ -2894,7 +2894,7 @@ apply_text_document_edit({text_document_edit}, {index}, {position_encoding},
|
||||
• {text_document_edit} (`lsp.TextDocumentEdit`)
|
||||
• {index} (`integer?`) Optional index of the edit, if from
|
||||
a list of edits (or nil, if not from a list)
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`)
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
|
||||
• {change_annotations} (`table<string, lsp.ChangeAnnotation>?`)
|
||||
|
||||
See also: ~
|
||||
@@ -2945,18 +2945,17 @@ buf_highlight_references({bufnr}, {references}, {position_encoding})
|
||||
• https://microsoft.github.io/language-server-protocol/specification/#textDocumentContentChangeEvent
|
||||
|
||||
*vim.lsp.util.character_offset()*
|
||||
character_offset({buf}, {row}, {col}, {offset_encoding})
|
||||
character_offset({buf}, {row}, {col}, {position_encoding})
|
||||
Returns the UTF-32 and UTF-16 offsets for a position in a certain buffer.
|
||||
|
||||
Parameters: ~
|
||||
• {buf} (`integer`) buffer number (0 for current)
|
||||
• {row} (`integer`) 0-indexed line
|
||||
• {col} (`integer`) 0-indexed byte offset in line
|
||||
• {offset_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) defaults to
|
||||
`offset_encoding` of first client of `buf`
|
||||
• {buf} (`integer`) buffer number (0 for current)
|
||||
• {row} (`integer`) 0-indexed line
|
||||
• {col} (`integer`) 0-indexed byte offset in line
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
|
||||
|
||||
Return: ~
|
||||
(`integer`) `offset_encoding` index of the character in line {row}
|
||||
(`integer`) `position_encoding` index of the character in line {row}
|
||||
column {col} in buffer {buf}
|
||||
|
||||
*vim.lsp.util.convert_input_to_markdown_lines()*
|
||||
@@ -3026,8 +3025,7 @@ locations_to_items({locations}, {position_encoding})
|
||||
|
||||
Parameters: ~
|
||||
• {locations} (`lsp.Location[]|lsp.LocationLink[]`)
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) default to first
|
||||
client of buffer
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
|
||||
|
||||
Return: ~
|
||||
(`vim.quickfix.entry[]`) See |setqflist()| for the format
|
||||
@@ -3193,7 +3191,7 @@ show_document({location}, {position_encoding}, {opts})
|
||||
|
||||
Parameters: ~
|
||||
• {location} (`lsp.Location|lsp.LocationLink`)
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`)
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
|
||||
• {opts} (`table?`) A table with the following fields:
|
||||
• {focus}? (`boolean`) Whether to focus/jump to
|
||||
location if possible. (defaults: true)
|
||||
@@ -3212,8 +3210,7 @@ symbols_to_items({symbols}, {bufnr}, {position_encoding})
|
||||
list of symbols
|
||||
• {bufnr} (`integer?`) buffer handle or 0 for current,
|
||||
defaults to current
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'?`) default to first
|
||||
client of buffer
|
||||
• {position_encoding} (`'utf-8'|'utf-16'|'utf-32'`)
|
||||
|
||||
Return: ~
|
||||
(`vim.quickfix.entry[]`) See |setqflist()| for the format
|
||||
|
||||
@@ -762,36 +762,6 @@ function vim.deep_equal(a, b)
|
||||
return deep_equal(a, b)
|
||||
end
|
||||
|
||||
--- Add the reverse lookup values to an existing table.
|
||||
--- For example:
|
||||
--- `tbl_add_reverse_lookup { A = 1 } == { [1] = 'A', A = 1 }`
|
||||
---
|
||||
--- Note that this *modifies* the input.
|
||||
---@deprecated
|
||||
---@param o table Table to add the reverse to
|
||||
---@return table o
|
||||
function vim.tbl_add_reverse_lookup(o)
|
||||
vim.deprecate('vim.tbl_add_reverse_lookup', nil, '0.12')
|
||||
|
||||
--- @cast o table<any,any>
|
||||
--- @type any[]
|
||||
local keys = vim.tbl_keys(o)
|
||||
for _, k in ipairs(keys) do
|
||||
local v = o[k]
|
||||
if o[v] then
|
||||
error(
|
||||
string.format(
|
||||
'The reverse lookup found an existing value for %q while processing key %q',
|
||||
tostring(v),
|
||||
tostring(k)
|
||||
)
|
||||
)
|
||||
end
|
||||
o[v] = k
|
||||
end
|
||||
return o
|
||||
end
|
||||
|
||||
--- Gets a (nested) value from table `o` given by a sequence of keys `...`, or `nil` if not found.
|
||||
---
|
||||
--- Note: To _set_ deeply nested keys, see |vim.tbl_deep_extend()|.
|
||||
@@ -948,12 +918,6 @@ function vim.isarray(t)
|
||||
end
|
||||
end
|
||||
|
||||
--- @deprecated
|
||||
function vim.tbl_islist(t)
|
||||
vim.deprecate('vim.tbl_islist', 'vim.islist', '0.12')
|
||||
return vim.islist(t)
|
||||
end
|
||||
|
||||
--- Tests if `t` is a "list": a table indexed _only_ by contiguous integers starting from 1 (what
|
||||
--- |lua-length| calls a "regular array").
|
||||
---
|
||||
|
||||
@@ -461,12 +461,6 @@ function M.enable(enable)
|
||||
end
|
||||
end
|
||||
|
||||
--- @deprecated
|
||||
function M.disable()
|
||||
vim.deprecate('vim.loader.disable', 'vim.loader.enable(false)', '0.12')
|
||||
vim.loader.enable(false)
|
||||
end
|
||||
|
||||
--- Tracks the time spent in a function
|
||||
--- @generic F: function
|
||||
--- @param f F
|
||||
|
||||
@@ -1166,12 +1166,6 @@ function lsp.get_clients(filter)
|
||||
return clients
|
||||
end
|
||||
|
||||
---@deprecated
|
||||
function lsp.get_active_clients(filter)
|
||||
vim.deprecate('vim.lsp.get_active_clients()', 'vim.lsp.get_clients()', '0.12')
|
||||
return lsp.get_clients(filter)
|
||||
end
|
||||
|
||||
-- Minimum time before warning about LSP exit_timeout on Nvim exit.
|
||||
local min_warn_exit_timeout = 100
|
||||
|
||||
@@ -1535,21 +1529,6 @@ function lsp.client_is_stopped(client_id)
|
||||
return not lsp.get_client_by_id(client_id)
|
||||
end
|
||||
|
||||
--- Gets a map of client_id:client pairs for the given buffer, where each value
|
||||
--- is a |vim.lsp.Client| object.
|
||||
---
|
||||
---@param bufnr integer? Buffer handle, or 0 for current
|
||||
---@return table result is table of (client_id, client) pairs
|
||||
---@deprecated Use |vim.lsp.get_clients()| instead.
|
||||
function lsp.buf_get_clients(bufnr)
|
||||
vim.deprecate('vim.lsp.buf_get_clients()', 'vim.lsp.get_clients()', '0.12')
|
||||
local result = {} --- @type table<integer,vim.lsp.Client>
|
||||
for _, client in ipairs(lsp.get_clients({ bufnr = vim._resolve_bufnr(bufnr) })) do
|
||||
result[client.id] = client
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
--- Log level dictionary with reverse lookup as well.
|
||||
---
|
||||
--- Can be used to lookup the number from the name or the
|
||||
@@ -1591,42 +1570,6 @@ function lsp.get_log_path()
|
||||
return log.get_filename()
|
||||
end
|
||||
|
||||
---@nodoc
|
||||
--- Invokes a function for each LSP client attached to a buffer.
|
||||
---
|
||||
---@param bufnr integer Buffer number
|
||||
---@param fn function Function to run on each client attached to buffer
|
||||
--- {bufnr}. The function takes the client, client ID, and
|
||||
--- buffer number as arguments.
|
||||
---@deprecated use lsp.get_clients({ bufnr = bufnr }) with regular loop
|
||||
function lsp.for_each_buffer_client(bufnr, fn)
|
||||
vim.deprecate(
|
||||
'vim.lsp.for_each_buffer_client()',
|
||||
'lsp.get_clients({ bufnr = bufnr }) with regular loop',
|
||||
'0.12'
|
||||
)
|
||||
bufnr = vim._resolve_bufnr(bufnr)
|
||||
|
||||
for _, client in pairs(lsp.get_clients({ bufnr = bufnr })) do
|
||||
fn(client, client.id, bufnr)
|
||||
end
|
||||
end
|
||||
|
||||
--- @deprecated
|
||||
--- Function to manage overriding defaults for LSP handlers.
|
||||
---@param handler (lsp.Handler) See |lsp-handler|
|
||||
---@param override_config (table) Table containing the keys to override behavior of the {handler}
|
||||
function lsp.with(handler, override_config)
|
||||
vim.deprecate(
|
||||
'vim.lsp.with()',
|
||||
'Pass the configuration to equivalent functions in `vim.lsp.buf`',
|
||||
'0.12'
|
||||
)
|
||||
return function(err, result, ctx, config)
|
||||
return handler(err, result, ctx, vim.tbl_deep_extend('force', config or {}, override_config))
|
||||
end
|
||||
end
|
||||
|
||||
--- Map of client-defined handlers implementing custom (off-spec) commands which a server may
|
||||
--- invoke. Each key is a unique command name; each value is a function which is called when an LSP
|
||||
--- action (code action, code lenses, …) requests it by name.
|
||||
|
||||
@@ -521,27 +521,6 @@ function M.signature_help(config)
|
||||
end)
|
||||
end
|
||||
|
||||
--- @deprecated
|
||||
--- Retrieves the completion items at the current cursor position. Can only be
|
||||
--- called in Insert mode.
|
||||
---
|
||||
---@param context table (context support not yet implemented) Additional information
|
||||
--- about the context in which a completion was triggered (how it was triggered,
|
||||
--- and by which trigger character, if applicable)
|
||||
---
|
||||
---@see vim.lsp.protocol.CompletionTriggerKind
|
||||
function M.completion(context)
|
||||
validate('context', context, 'table', true)
|
||||
vim.deprecate('vim.lsp.buf.completion', 'vim.lsp.completion.trigger', '0.12')
|
||||
return lsp.buf_request(
|
||||
0,
|
||||
'textDocument/completion',
|
||||
client_positional_params({
|
||||
context = context,
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param mode "v"|"V"
|
||||
---@return table {start={row,col}, end={row,col}} using (1, 0) indexing
|
||||
@@ -1426,22 +1405,6 @@ function M.code_action(opts)
|
||||
end)
|
||||
end
|
||||
|
||||
--- @deprecated
|
||||
--- Executes an LSP server command.
|
||||
--- @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, 'string')
|
||||
validate('arguments', command_params.arguments, 'table', true)
|
||||
vim.deprecate('execute_command', 'client:exec_cmd', '0.12')
|
||||
command_params = {
|
||||
command = command_params.command,
|
||||
arguments = command_params.arguments,
|
||||
workDoneToken = command_params.workDoneToken,
|
||||
}
|
||||
lsp.buf_request(0, 'workspace/executeCommand', command_params)
|
||||
end
|
||||
|
||||
---@type { index: integer, ranges: lsp.Range[] }?
|
||||
local selection_ranges = nil
|
||||
|
||||
|
||||
@@ -318,37 +318,6 @@ function M.on_diagnostic(error, result, ctx)
|
||||
end
|
||||
end
|
||||
|
||||
--- Get the diagnostics by line
|
||||
---
|
||||
--- Marked private as this is used internally by the LSP subsystem, but
|
||||
--- most users should instead prefer |vim.diagnostic.get()|.
|
||||
---
|
||||
---@param bufnr integer|nil The buffer number
|
||||
---@param line_nr integer|nil The line number
|
||||
---@param opts {severity?:lsp.DiagnosticSeverity}?
|
||||
--- - severity: (lsp.DiagnosticSeverity)
|
||||
--- - Only return diagnostics with this severity.
|
||||
---@param client_id integer|nil the client id
|
||||
---@return table Table with map of line number to list of diagnostics.
|
||||
--- Structured: { [1] = {...}, [5] = {.... } }
|
||||
---@private
|
||||
function M.get_line_diagnostics(bufnr, line_nr, opts, client_id)
|
||||
vim.deprecate('vim.lsp.diagnostic.get_line_diagnostics', 'vim.diagnostic.get', '0.12')
|
||||
local diag_opts = {} --- @type vim.diagnostic.GetOpts
|
||||
|
||||
if opts and opts.severity then
|
||||
diag_opts.severity = severity_lsp_to_vim(opts.severity)
|
||||
end
|
||||
|
||||
if client_id then
|
||||
diag_opts.namespace = M.get_namespace(client_id)
|
||||
end
|
||||
|
||||
diag_opts.lnum = line_nr or (api.nvim_win_get_cursor(0)[1] - 1)
|
||||
|
||||
return M.from(vim.diagnostic.get(bufnr, diag_opts))
|
||||
end
|
||||
|
||||
--- Clear diagnostics from pull based clients
|
||||
local function clear(bufnr)
|
||||
for _, namespace in pairs(client_pull_namespaces) do
|
||||
|
||||
@@ -117,54 +117,6 @@ local function create_window_without_focus()
|
||||
return new
|
||||
end
|
||||
|
||||
--- Replaces text in a range with new text.
|
||||
---
|
||||
--- CAUTION: Changes in-place!
|
||||
---
|
||||
---@deprecated
|
||||
---@param lines string[] Original list of strings
|
||||
---@param A [integer, integer] Start position; a 2-tuple of {line,col} numbers
|
||||
---@param B [integer, integer] End position; a 2-tuple {line,col} numbers
|
||||
---@param new_lines string[] list of strings to replace the original
|
||||
---@return string[] The modified {lines} object
|
||||
function M.set_lines(lines, A, B, new_lines)
|
||||
vim.deprecate('vim.lsp.util.set_lines()', nil, '0.12')
|
||||
-- 0-indexing to 1-indexing
|
||||
local i_0 = A[1] + 1
|
||||
-- If it extends past the end, truncate it to the end. This is because the
|
||||
-- way the LSP describes the range including the last newline is by
|
||||
-- specifying a line number after what we would call the last line.
|
||||
local i_n = math.min(B[1] + 1, #lines)
|
||||
if not (i_0 >= 1 and i_0 <= #lines + 1 and i_n >= 1 and i_n <= #lines) then
|
||||
error('Invalid range: ' .. vim.inspect({ A = A, B = B, #lines, new_lines }))
|
||||
end
|
||||
local prefix = ''
|
||||
local suffix = assert(lines[i_n]):sub(B[2] + 1)
|
||||
if A[2] > 0 then
|
||||
prefix = assert(lines[i_0]):sub(1, A[2])
|
||||
end
|
||||
local n = i_n - i_0 + 1
|
||||
if n ~= #new_lines then
|
||||
for _ = 1, n - #new_lines do
|
||||
table.remove(lines, i_0)
|
||||
end
|
||||
for _ = 1, #new_lines - n do
|
||||
table.insert(lines, i_0, '')
|
||||
end
|
||||
end
|
||||
for i = 1, #new_lines do
|
||||
lines[i - 1 + i_0] = new_lines[i]
|
||||
end
|
||||
if #suffix > 0 then
|
||||
local i = i_0 + #new_lines - 1
|
||||
lines[i] = lines[i] .. suffix
|
||||
end
|
||||
if #prefix > 0 then
|
||||
lines[i_0] = prefix .. lines[i_0]
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
--- @param fn fun(x:any):any[]
|
||||
--- @return function
|
||||
local function sort_by_key(fn)
|
||||
@@ -498,7 +450,7 @@ end
|
||||
---
|
||||
---@param text_document_edit lsp.TextDocumentEdit
|
||||
---@param index? integer: Optional index of the edit, if from a list of edits (or nil, if not from a list)
|
||||
---@param position_encoding? 'utf-8'|'utf-16'|'utf-32'
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@param change_annotations? table<string, lsp.ChangeAnnotation>
|
||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentEdit
|
||||
function M.apply_text_document_edit(
|
||||
@@ -507,15 +459,10 @@ function M.apply_text_document_edit(
|
||||
position_encoding,
|
||||
change_annotations
|
||||
)
|
||||
vim.validate('position_encoding', position_encoding, 'string')
|
||||
|
||||
local text_document = text_document_edit.textDocument
|
||||
local bufnr = vim.uri_to_bufnr(text_document.uri)
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'apply_text_document_edit must be called with valid position encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
-- `VersionedTextDocumentIdentifier`s version may be null
|
||||
-- https://microsoft.github.io/language-server-protocol/specification#versionedTextDocumentIdentifier
|
||||
@@ -695,13 +642,8 @@ end
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32' (required)
|
||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
|
||||
function M.apply_workspace_edit(workspace_edit, position_encoding)
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'apply_workspace_edit must be called with valid position encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return
|
||||
end
|
||||
vim.validate('position_encoding', position_encoding, 'string')
|
||||
|
||||
if workspace_edit.documentChanges then
|
||||
for idx, change in ipairs(workspace_edit.documentChanges) do
|
||||
if change.kind == 'rename' then
|
||||
@@ -1010,22 +952,17 @@ end
|
||||
--- Shows document and optionally jumps to the location.
|
||||
---
|
||||
---@param location lsp.Location|lsp.LocationLink
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'?
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@param opts? vim.lsp.util.show_document.Opts
|
||||
---@return boolean `true` if succeeded
|
||||
function M.show_document(location, position_encoding, opts)
|
||||
vim.validate('position_encoding', position_encoding, 'string')
|
||||
|
||||
-- location may be Location or LocationLink
|
||||
local uri = location.uri or location.targetUri
|
||||
if uri == nil then
|
||||
return false
|
||||
end
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'show_document must be called with valid position encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
return false
|
||||
end
|
||||
local bufnr = vim.uri_to_bufnr(uri)
|
||||
|
||||
opts = opts or {}
|
||||
@@ -1075,18 +1012,6 @@ function M.show_document(location, position_encoding, opts)
|
||||
return true
|
||||
end
|
||||
|
||||
--- Jumps to a location.
|
||||
---
|
||||
---@deprecated use `vim.lsp.util.show_document` with `{focus=true}` instead
|
||||
---@param location lsp.Location|lsp.LocationLink
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'?
|
||||
---@param reuse_win boolean? Jump to existing window if buffer is already open.
|
||||
---@return boolean `true` if the jump succeeded
|
||||
function M.jump_to_location(location, position_encoding, reuse_win)
|
||||
vim.deprecate('vim.lsp.util.jump_to_location', nil, '0.12')
|
||||
return M.show_document(location, position_encoding, { reuse_win = reuse_win, focus = true })
|
||||
end
|
||||
|
||||
--- Previews a location in a floating window
|
||||
---
|
||||
--- behavior depends on type of location:
|
||||
@@ -1878,17 +1803,10 @@ end)
|
||||
--- |setloclist()|.
|
||||
---
|
||||
---@param locations lsp.Location[]|lsp.LocationLink[]
|
||||
---@param position_encoding? 'utf-8'|'utf-16'|'utf-32'
|
||||
--- default to first client of buffer
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@return vim.quickfix.entry[] # See |setqflist()| for the format
|
||||
function M.locations_to_items(locations, position_encoding)
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'locations_to_items must be called with valid position encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
position_encoding = vim.lsp.get_clients({ bufnr = 0 })[1].offset_encoding
|
||||
end
|
||||
vim.validate('position_encoding', position_encoding, 'string')
|
||||
|
||||
local items = {} --- @type vim.quickfix.entry[]
|
||||
|
||||
@@ -1945,18 +1863,12 @@ end
|
||||
---
|
||||
---@param symbols lsp.DocumentSymbol[]|lsp.SymbolInformation[]|lsp.WorkspaceSymbol[] list of symbols
|
||||
---@param bufnr? integer buffer handle or 0 for current, defaults to current
|
||||
---@param position_encoding? 'utf-8'|'utf-16'|'utf-32'
|
||||
--- default to first client of buffer
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@return vim.quickfix.entry[] # See |setqflist()| for the format
|
||||
function M.symbols_to_items(symbols, bufnr, position_encoding)
|
||||
vim.validate('position_encoding', position_encoding, 'string')
|
||||
|
||||
bufnr = vim._resolve_bufnr(bufnr)
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'symbols_to_items must be called with valid position encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
position_encoding = assert(vim.lsp.get_clients({ bufnr = bufnr })[1]).offset_encoding
|
||||
end
|
||||
|
||||
local items = {} --- @type vim.quickfix.entry[]
|
||||
for _, symbol in ipairs(symbols) do
|
||||
@@ -2013,59 +1925,6 @@ function M.symbols_to_items(symbols, bufnr, position_encoding)
|
||||
return items
|
||||
end
|
||||
|
||||
--- Removes empty lines from the beginning and end.
|
||||
---@deprecated use `vim.split()` with `trimempty` instead
|
||||
---@param lines table list of lines to trim
|
||||
---@return table trimmed list of lines
|
||||
function M.trim_empty_lines(lines)
|
||||
vim.deprecate('vim.lsp.util.trim_empty_lines()', 'vim.split() with `trimempty`', '0.12')
|
||||
local start = 1
|
||||
for i = 1, #lines do
|
||||
if lines[i] ~= nil and #lines[i] > 0 then
|
||||
start = i
|
||||
break
|
||||
end
|
||||
end
|
||||
local finish = 1
|
||||
for i = #lines, 1, -1 do
|
||||
if lines[i] ~= nil and #lines[i] > 0 then
|
||||
finish = i
|
||||
break
|
||||
end
|
||||
end
|
||||
return vim.list_slice(lines, start, finish)
|
||||
end
|
||||
|
||||
--- Accepts markdown lines and tries to reduce them to a filetype if they
|
||||
--- comprise just a single code block.
|
||||
---
|
||||
--- CAUTION: Modifies the input in-place!
|
||||
---
|
||||
---@deprecated
|
||||
---@param lines string[] list of lines
|
||||
---@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 = assert(lines[1]):match('^```(.*)')
|
||||
if language_id then
|
||||
local has_inner_code_fence = false
|
||||
for i = 2, (#lines - 1) do
|
||||
local line = lines[i] --[[@as string]]
|
||||
if line:sub(1, 3) == '```' then
|
||||
has_inner_code_fence = true
|
||||
break
|
||||
end
|
||||
end
|
||||
-- No inner code fences + starting with code fence = hooray.
|
||||
if not has_inner_code_fence then
|
||||
table.remove(lines, 1)
|
||||
table.remove(lines)
|
||||
return language_id
|
||||
end
|
||||
end
|
||||
return 'markdown'
|
||||
end
|
||||
|
||||
---@param win integer?: |window-ID| or 0 for current, defaults to current
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
local function make_position_param(win, position_encoding)
|
||||
@@ -2092,54 +1951,12 @@ end
|
||||
function M.make_position_params(win, position_encoding)
|
||||
win = win or 0
|
||||
local buf = api.nvim_win_get_buf(win)
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'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 {
|
||||
textDocument = M.make_text_document_params(buf),
|
||||
position = make_position_param(win, position_encoding),
|
||||
}
|
||||
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 '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)
|
||||
|
||||
local offset_encoding --- @type 'utf-8'|'utf-16'|'utf-32'?
|
||||
|
||||
for _, client in pairs(vim.lsp.get_clients({ bufnr = bufnr })) do
|
||||
if client.offset_encoding == nil then
|
||||
vim.notify_once(
|
||||
string.format(
|
||||
'Client (id: %s) offset_encoding is nil. Do not unset offset_encoding.',
|
||||
client.id
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
end
|
||||
local this_offset_encoding = client.offset_encoding
|
||||
if not offset_encoding then
|
||||
offset_encoding = this_offset_encoding
|
||||
elseif offset_encoding ~= this_offset_encoding then
|
||||
vim.notify_once(
|
||||
'warning: multiple different client offset_encodings detected for buffer, vim.lsp.util._get_offset_encoding() uses the offset_encoding from the first client',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
end
|
||||
--- @cast offset_encoding -? hack - not safe
|
||||
|
||||
return offset_encoding
|
||||
end
|
||||
|
||||
--- Using the current position in the current buffer, creates an object that
|
||||
--- can be used as a building block for several LSP requests, such as
|
||||
--- `textDocument/codeAction`, `textDocument/colorPresentation`,
|
||||
@@ -2150,14 +1967,6 @@ end
|
||||
---@return { textDocument: { uri: lsp.DocumentUri }, range: lsp.Range }
|
||||
function M.make_range_params(win, position_encoding)
|
||||
local buf = api.nvim_win_get_buf(win or 0)
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'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(win, position_encoding)
|
||||
return {
|
||||
textDocument = M.make_text_document_params(buf),
|
||||
@@ -2178,16 +1987,9 @@ end
|
||||
function M.make_given_range_params(start_pos, end_pos, bufnr, position_encoding)
|
||||
validate('start_pos', start_pos, 'table', true)
|
||||
validate('end_pos', end_pos, 'table', true)
|
||||
validate('position_encoding', position_encoding, 'string', true)
|
||||
validate('position_encoding', position_encoding, 'string')
|
||||
|
||||
bufnr = vim._resolve_bufnr(bufnr)
|
||||
if position_encoding == nil then
|
||||
vim.notify_once(
|
||||
'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]
|
||||
local A = { unpack(start_pos or api.nvim_buf_get_mark(bufnr, '<')) }
|
||||
--- @type [integer, integer]
|
||||
@@ -2268,37 +2070,13 @@ end
|
||||
---@param buf integer buffer number (0 for current)
|
||||
---@param row integer 0-indexed line
|
||||
---@param col integer 0-indexed byte offset in line
|
||||
---@param offset_encoding? 'utf-8'|'utf-16'|'utf-32'
|
||||
--- defaults to `offset_encoding` of first client of `buf`
|
||||
---@return integer `offset_encoding` index of the character in line {row} column {col} in buffer {buf}
|
||||
function M.character_offset(buf, row, col, offset_encoding)
|
||||
local line = get_line(buf, row)
|
||||
if offset_encoding == nil then
|
||||
vim.notify_once(
|
||||
'character_offset must be called with valid offset encoding',
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
offset_encoding = assert(vim.lsp.get_clients({ bufnr = buf })[1]).offset_encoding
|
||||
end
|
||||
return vim.str_utfindex(line, offset_encoding, col, false)
|
||||
end
|
||||
---@param position_encoding 'utf-8'|'utf-16'|'utf-32'
|
||||
---@return integer `position_encoding` index of the character in line {row} column {col} in buffer {buf}
|
||||
function M.character_offset(buf, row, col, position_encoding)
|
||||
vim.validate('position_encoding', position_encoding, 'string')
|
||||
|
||||
--- Helper function to return nested values in language server settings
|
||||
---
|
||||
---@param settings table language server settings
|
||||
---@param section string indicating the field of the settings table
|
||||
---@return table|string|vim.NIL The value of settings accessed via section. `vim.NIL` if not found.
|
||||
---@deprecated
|
||||
function M.lookup_section(settings, section)
|
||||
vim.deprecate('vim.lsp.util.lookup_section()', 'vim.tbl_get() with `vim.split`', '0.12')
|
||||
for part in vim.gsplit(section, '.', { plain = true }) do
|
||||
--- @diagnostic disable-next-line:no-unknown
|
||||
settings = settings[part]
|
||||
if settings == nil then
|
||||
return vim.NIL
|
||||
end
|
||||
end
|
||||
return settings
|
||||
local line = get_line(buf, row)
|
||||
return vim.str_utfindex(line, position_encoding, col, false)
|
||||
end
|
||||
|
||||
--- Converts line range (0-based, end-inclusive) to lsp range,
|
||||
|
||||
@@ -1315,29 +1315,6 @@ describe('lua stdlib', function()
|
||||
eq({ 2 }, exec_lua [[ return vim.list_extend({}, {2;a=1}, -1, 2) ]])
|
||||
end)
|
||||
|
||||
it('vim.tbl_add_reverse_lookup', function()
|
||||
eq(
|
||||
true,
|
||||
exec_lua [[
|
||||
local a = { A = 1 }
|
||||
vim.tbl_add_reverse_lookup(a)
|
||||
return vim.deep_equal(a, { A = 1; [1] = 'A'; })
|
||||
]]
|
||||
)
|
||||
-- Throw an error for trying to do it twice (run into an existing key)
|
||||
local code = [[
|
||||
local res = {}
|
||||
local a = { A = 1 }
|
||||
vim.tbl_add_reverse_lookup(a)
|
||||
assert(vim.deep_equal(a, { A = 1; [1] = 'A'; }))
|
||||
vim.tbl_add_reverse_lookup(a)
|
||||
]]
|
||||
matches(
|
||||
'The reverse lookup found an existing value for "[1A]" while processing key "[1A]"$',
|
||||
pcall_err(exec_lua, code)
|
||||
)
|
||||
end)
|
||||
|
||||
it('vim.spairs', function()
|
||||
local res = ''
|
||||
local table = {
|
||||
|
||||
@@ -681,79 +681,6 @@ describe('vim.lsp.util', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('lsp.util.jump_to_location', function()
|
||||
local target_bufnr --- @type integer
|
||||
|
||||
before_each(function()
|
||||
target_bufnr = exec_lua(function()
|
||||
local bufnr = vim.uri_to_bufnr('file:///fake/uri')
|
||||
local lines = { '1st line of text', 'å å ɧ 汉语 ↥ 🤦 🦄' }
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, lines)
|
||||
return bufnr
|
||||
end)
|
||||
end)
|
||||
|
||||
local location = function(start_line, start_char, end_line, end_char)
|
||||
return {
|
||||
uri = 'file:///fake/uri',
|
||||
range = {
|
||||
start = { line = start_line, character = start_char },
|
||||
['end'] = { line = end_line, character = end_char },
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
local jump = function(msg)
|
||||
eq(true, exec_lua('return vim.lsp.util.jump_to_location(...)', msg, 'utf-16'))
|
||||
eq(target_bufnr, fn.bufnr('%'))
|
||||
return {
|
||||
line = fn.line('.'),
|
||||
col = fn.col('.'),
|
||||
}
|
||||
end
|
||||
|
||||
it('jumps to a Location', function()
|
||||
local pos = jump(location(0, 9, 0, 9))
|
||||
eq(1, pos.line)
|
||||
eq(10, pos.col)
|
||||
end)
|
||||
|
||||
it('jumps to a LocationLink', function()
|
||||
local pos = jump({
|
||||
targetUri = 'file:///fake/uri',
|
||||
targetSelectionRange = {
|
||||
start = { line = 0, character = 4 },
|
||||
['end'] = { line = 0, character = 4 },
|
||||
},
|
||||
targetRange = {
|
||||
start = { line = 1, character = 5 },
|
||||
['end'] = { line = 1, character = 5 },
|
||||
},
|
||||
})
|
||||
eq(1, pos.line)
|
||||
eq(5, pos.col)
|
||||
end)
|
||||
|
||||
it('jumps to the correct multibyte column', function()
|
||||
local pos = jump(location(1, 2, 1, 2))
|
||||
eq(2, pos.line)
|
||||
eq(4, pos.col)
|
||||
eq('å', fn.expand('<cword>'))
|
||||
end)
|
||||
|
||||
it('adds current position to jumplist before jumping', function()
|
||||
api.nvim_win_set_buf(0, target_bufnr)
|
||||
local mark = api.nvim_buf_get_mark(target_bufnr, "'")
|
||||
eq({ 1, 0 }, mark)
|
||||
|
||||
api.nvim_win_set_cursor(0, { 2, 3 })
|
||||
jump(location(0, 9, 0, 9))
|
||||
|
||||
mark = api.nvim_buf_get_mark(target_bufnr, "'")
|
||||
eq({ 2, 3 }, mark)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('lsp.util.show_document', function()
|
||||
local target_bufnr --- @type integer
|
||||
local target_bufnr2 --- @type integer
|
||||
@@ -816,6 +743,29 @@ describe('vim.lsp.util', function()
|
||||
eq('i', api.nvim_get_mode().mode)
|
||||
end)
|
||||
|
||||
it('jumps to a LocationLink', function()
|
||||
local pos = show_document({
|
||||
targetUri = 'file:///fake/uri',
|
||||
targetSelectionRange = {
|
||||
start = { line = 0, character = 4 },
|
||||
['end'] = { line = 0, character = 4 },
|
||||
},
|
||||
targetRange = {
|
||||
start = { line = 1, character = 5 },
|
||||
['end'] = { line = 1, character = 5 },
|
||||
},
|
||||
}, true, true)
|
||||
eq(1, pos.line)
|
||||
eq(5, pos.col)
|
||||
end)
|
||||
|
||||
it('jumps to the correct multibyte column', function()
|
||||
local pos = show_document(location(1, 2, 1, 2), true, true)
|
||||
eq(2, pos.line)
|
||||
eq(4, pos.col)
|
||||
eq('å', fn.expand('<cword>'))
|
||||
end)
|
||||
|
||||
it('jumps to a Location if focus is true via handler', function()
|
||||
exec_lua(create_server_definition)
|
||||
local result = exec_lua(function()
|
||||
@@ -849,6 +799,18 @@ describe('vim.lsp.util', function()
|
||||
eq(10, pos.col)
|
||||
end)
|
||||
|
||||
it('adds current position to jumplist before jumping', function()
|
||||
api.nvim_win_set_buf(0, target_bufnr)
|
||||
local mark = api.nvim_buf_get_mark(target_bufnr, "'")
|
||||
eq({ 1, 0 }, mark)
|
||||
|
||||
api.nvim_win_set_cursor(0, { 2, 3 })
|
||||
show_document(location(0, 9, 0, 9), true, true)
|
||||
|
||||
mark = api.nvim_buf_get_mark(target_bufnr, "'")
|
||||
eq({ 2, 3 }, mark)
|
||||
end)
|
||||
|
||||
it('does not add current position to jumplist if not focus', function()
|
||||
api.nvim_win_set_buf(0, target_bufnr)
|
||||
local mark = api.nvim_buf_get_mark(target_bufnr, "'")
|
||||
@@ -1045,18 +1007,6 @@ describe('vim.lsp.util', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('lsp.util.trim.trim_empty_lines', function()
|
||||
it('properly trims empty lines', function()
|
||||
eq(
|
||||
{ { 'foo', 'bar' } },
|
||||
exec_lua(function()
|
||||
--- @diagnostic disable-next-line:deprecated
|
||||
return vim.lsp.util.trim_empty_lines({ { 'foo', 'bar' }, nil })
|
||||
end)
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('lsp.util.convert_signature_help_to_markdown_lines', function()
|
||||
it('can handle negative activeSignature', function()
|
||||
local result = exec_lua(function()
|
||||
|
||||
Reference in New Issue
Block a user