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

@@ -442,7 +442,7 @@ files.treesitter = function(opts)
end end
results = utils.filter_symbols(results, opts) results = utils.filter_symbols(results, opts)
if results == nil then if vim.tbl_isempty(results) then
-- error message already printed in `utils.filter_symbols` -- error message already printed in `utils.filter_symbols`
return return
end end

View File

@@ -100,7 +100,7 @@ end
--- convert `item` type back to something we can pass to `vim.lsp.util.jump_to_location` --- 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` --- 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` --- 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 ---@param offset_encoding string|nil utf-8|utf-16|utf-32
---@return lsp.Location ---@return lsp.Location
local function item_to_location(item, offset_encoding) local function item_to_location(item, offset_encoding)
@@ -134,9 +134,9 @@ end
---| "textDocument/implementation" ---| "textDocument/implementation"
---@param action telescope.lsp.list_or_jump_action ---@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 ---@param opts table
---@return vim.lsp.util.locations_to_items.ret[] ---@return vim.quickfix.entry[]
local apply_action_handler = function(action, items, opts) local apply_action_handler = function(action, items, opts)
if action == "textDocument/references" and not opts.include_current_line then if action == "textDocument/references" and not opts.include_current_line then
local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1] 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 return items
end end
---@param items vim.lsp.util.locations_to_items.ret[] ---@param items vim.quickfix.entry[]
---@param opts table ---@param opts table
---@return vim.lsp.util.locations_to_items.ret[] ---@return vim.quickfix.entry[]
local function filter_file_ignore_patters(items, opts) local function filter_file_ignore_patters(items, opts)
local file_ignore_patterns = vim.F.if_nil(opts.file_ignore_patterns, conf.file_ignore_patterns) local file_ignore_patterns = vim.F.if_nil(opts.file_ignore_patterns, conf.file_ignore_patterns)
file_ignore_patterns = file_ignore_patterns or {} file_ignore_patterns = file_ignore_patterns or {}
@@ -242,7 +242,7 @@ local function list_or_jump(action, title, funname, params, opts)
end end
local location = item_to_location(item, first_encoding) 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 else
pickers pickers
.new(opts, { .new(opts, {
@@ -263,6 +263,7 @@ end
lsp.references = function(opts) lsp.references = function(opts)
opts.include_current_line = vim.F.if_nil(opts.include_current_line, false) 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) local params = vim.lsp.util.make_position_params(opts.winnr)
params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) } params.context = { includeDeclaration = vim.F.if_nil(opts.include_declaration, true) }
return list_or_jump("textDocument/references", "LSP References", "builtin.lsp_references", params, opts) 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 {} local locations = vim.lsp.util.symbols_to_items(result or {}, opts.bufnr) or {}
locations = utils.filter_symbols(locations, opts, symbols_sorter) 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` -- error message already printed in `utils.filter_symbols`
return return
end end
@@ -382,7 +383,7 @@ lsp.workspace_symbols = function(opts)
local locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {} local locations = vim.lsp.util.symbols_to_items(server_result or {}, opts.bufnr) or {}
locations = utils.filter_symbols(locations, opts, symbols_sorter) 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` -- error message already printed in `utils.filter_symbols`
return return
end 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) 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 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 for _, client_res in pairs(results) do
if client_res.error then if client_res.error then

View File

@@ -121,7 +121,7 @@ utils.filter_symbols = function(results, opts, post_filter)
msg = "Either opts.symbols or opts.ignore_symbols, can't process opposing options at the same time!", msg = "Either opts.symbols or opts.ignore_symbols, can't process opposing options at the same time!",
level = "ERROR", level = "ERROR",
}) })
return return {}
elseif not (has_ignore or has_symbols) then elseif not (has_ignore or has_symbols) then
return results return results
elseif has_ignore then elseif has_ignore then
@@ -133,7 +133,7 @@ utils.filter_symbols = function(results, opts, post_filter)
msg = "Please pass ignore_symbols as either a string or a list of strings", msg = "Please pass ignore_symbols as either a string or a list of strings",
level = "ERROR", level = "ERROR",
}) })
return return {}
end end
opts.ignore_symbols = vim.tbl_map(string.lower, opts.ignore_symbols) opts.ignore_symbols = vim.tbl_map(string.lower, opts.ignore_symbols)
@@ -149,7 +149,7 @@ utils.filter_symbols = function(results, opts, post_filter)
msg = "Please pass filtering symbols as either a string or a list of strings", msg = "Please pass filtering symbols as either a string or a list of strings",
level = "ERROR", level = "ERROR",
}) })
return return {}
end end
opts.symbols = vim.tbl_map(string.lower, opts.symbols) opts.symbols = vim.tbl_map(string.lower, opts.symbols)