diff --git a/runtime/lua/vim/_core/shared.lua b/runtime/lua/vim/_core/shared.lua index a67e8513a1..0965ceac65 100644 --- a/runtime/lua/vim/_core/shared.lua +++ b/runtime/lua/vim/_core/shared.lua @@ -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 - --- @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"). --- diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua index 6aa79a0244..4880795116 100644 --- a/runtime/lua/vim/loader.lua +++ b/runtime/lua/vim/loader.lua @@ -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 diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index c64429df41..cc23d69d69 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -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 - 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. diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index d69546b700..f3b6ea3fc8 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -511,27 +511,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 @@ -1416,22 +1395,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 diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 7463664f1f..ec8801567e 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -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 diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index a8759218ff..76ace87471 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -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) @@ -1075,18 +1027,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: @@ -2013,59 +1953,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 +1979,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 +1995,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), @@ -2180,14 +2017,6 @@ function M.make_given_range_params(start_pos, end_pos, bufnr, position_encoding) validate('end_pos', end_pos, 'table', true) validate('position_encoding', position_encoding, 'string', true) 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] @@ -2283,24 +2112,6 @@ function M.character_offset(buf, row, col, offset_encoding) return vim.str_utfindex(line, offset_encoding, col, false) end ---- 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 -end - --- Converts line range (0-based, end-inclusive) to lsp range, --- handles absence of a trailing newline --- diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 4d896b9558..e1afb8d521 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -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 = { diff --git a/test/functional/plugin/lsp/util_spec.lua b/test/functional/plugin/lsp/util_spec.lua index 56c273e277..4e6625af7b 100644 --- a/test/functional/plugin/lsp/util_spec.lua +++ b/test/functional/plugin/lsp/util_spec.lua @@ -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('')) - 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('')) + 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()