refactor: adapt to deprecated jump_to_location (#3344)

This commit is contained in:
Tristan Knight
2024-10-29 01:22:28 +00:00
committed by GitHub
parent f06e7a8871
commit 85922dde37
3 changed files with 14 additions and 13 deletions

View File

@@ -100,7 +100,7 @@ end
--- convert `item` type back to something we can pass to `vim.lsp.util.jump_to_location`
--- stopgap for pre-nvim 0.10 - after which we can simply use the `user_data`
--- field on the items in `vim.lsp.util.locations_to_items`
---@param item vim.lsp.util.locations_to_items.ret
---@param item vim.quickfix.entry
---@param offset_encoding string|nil utf-8|utf-16|utf-32
---@return lsp.Location
local function item_to_location(item, offset_encoding)
@@ -134,9 +134,9 @@ end
---| "textDocument/implementation"
---@param action telescope.lsp.list_or_jump_action
---@param items vim.lsp.util.locations_to_items.ret[]
---@param items vim.quickfix.entry[]
---@param opts table
---@return vim.lsp.util.locations_to_items.ret[]
---@return vim.quickfix.entry[]
local apply_action_handler = function(action, items, opts)
if action == "textDocument/references" and not opts.include_current_line then
local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1]
@@ -148,9 +148,9 @@ local apply_action_handler = function(action, items, opts)
return items
end
---@param items vim.lsp.util.locations_to_items.ret[]
---@param items vim.quickfix.entry[]
---@param opts table
---@return vim.lsp.util.locations_to_items.ret[]
---@return vim.quickfix.entry[]
local function filter_file_ignore_patters(items, opts)
local file_ignore_patterns = vim.F.if_nil(opts.file_ignore_patterns, conf.file_ignore_patterns)
file_ignore_patterns = file_ignore_patterns or {}
@@ -242,7 +242,7 @@ local function list_or_jump(action, title, funname, params, opts)
end
local location = item_to_location(item, first_encoding)
vim.lsp.util.jump_to_location(location, first_encoding, opts.reuse_win)
vim.lsp.util.show_document(location, first_encoding, { reuse_win = opts.reuse_win })
else
pickers
.new(opts, {
@@ -263,6 +263,7 @@ end
lsp.references = function(opts)
opts.include_current_line = vim.F.if_nil(opts.include_current_line, false)
---@class lsp.TextDocumentPositionParams
local params = vim.lsp.util.make_position_params(opts.winnr)
params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) }
return list_or_jump("textDocument/references", "LSP References", "builtin.lsp_references", params, opts)
@@ -339,7 +340,7 @@ lsp.document_symbols = function(opts)
local locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr) or {}
locations = utils.filter_symbols(locations, opts, symbols_sorter)
if locations == nil then
if vim.tbl_isempty(locations) then
-- error message already printed in `utils.filter_symbols`
return
end
@@ -382,7 +383,7 @@ lsp.workspace_symbols = function(opts)
local locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {}
locations = utils.filter_symbols(locations, opts, symbols_sorter)
if locations == nil then
if vim.tbl_isempty(locations) then
-- error message already printed in `utils.filter_symbols`
return
end
@@ -424,7 +425,7 @@ local function get_workspace_symbols_requester(bufnr, opts)
cancel = vim.lsp.buf_request_all(bufnr, "workspace/symbol", { query = prompt }, tx)
local results = rx() ---@type table<integer, {error: lsp.ResponseError?, result: lsp.WorkspaceSymbol?}>
local locations = {} ---@type vim.lsp.util.locations_to_items.ret[]
local locations = {} ---@type vim.quickfix.entry[]
for _, client_res in pairs(results) do
if client_res.error then