Skip to content

Commit

Permalink
refactor: adapt to deprecated jump_to_location (#3344)
Browse files Browse the repository at this point in the history
tris203 authored Oct 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent f06e7a8 commit 85922dd
Showing 3 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lua/telescope/builtin/__files.lua
Original file line number Diff line number Diff line change
@@ -442,7 +442,7 @@ files.treesitter = function(opts)
end

results = utils.filter_symbols(results, opts)
if results == nil then
if vim.tbl_isempty(results) then
-- error message already printed in `utils.filter_symbols`
return
end
19 changes: 10 additions & 9 deletions lua/telescope/builtin/__lsp.lua
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
@@ -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!",
level = "ERROR",
})
return
return {}
elseif not (has_ignore or has_symbols) then
return results
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",
level = "ERROR",
})
return
return {}
end

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",
level = "ERROR",
})
return
return {}
end

opts.symbols = vim.tbl_map(string.lower, opts.symbols)

0 comments on commit 85922dd

Please sign in to comment.