Skip to content

Commit

Permalink
Merge branch 'nvim-telescope:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Wordluc authored Nov 28, 2024
2 parents 66dfab1 + 85922dd commit f7292a7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 17 deletions.
7 changes: 7 additions & 0 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2602,6 +2602,13 @@ UTILS *telescope.utils*

Utilities for writing telescope pickers

utils.str_byteindex() *telescope.utils.str_byteindex()*


Return: ~
integer


utils.path_expand({path}) *telescope.utils.path_expand()*
Hybrid of `vim.fn.expand()` and custom `vim.fs.normalize()`

Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/builtin/__files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions lua/telescope/builtin/__git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,18 @@ git.status = function(opts)
sorter = conf.file_sorter(opts),
on_complete = {
function(self)
local lines = self.manager:num_results()
local prompt = action_state.get_current_line()
if lines == 0 and prompt == "" then

-- HACK: self.manager:num_results() can return 0 despite having results
-- due to some async/event loop shenanigans (#3316)
local count = 0
for _, entry in pairs(self.finder.results) do
if entry and entry.valid ~= false then
count = count + 1
end
end

if count == 0 and prompt == "" then
utils.notify("builtin.git_status", {
msg = "No changes found",
level = "ERROR",
Expand Down
21 changes: 11 additions & 10 deletions lua/telescope/builtin/__lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ 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)
local line = item.lnum - 1
local character = vim.lsp.util._str_utfindex_enc(item.text, item.col, offset_encoding) - 1
local character = utils.str_byteindex(item.text, item.col, offset_encoding or "utf-16") - 1
local uri
if utils.is_uri(item.filename) then
uri = item.filename
Expand Down Expand Up @@ -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]
Expand All @@ -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 {}
Expand Down Expand Up @@ -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, {
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,7 @@ function make_entry.gen_from_git_status(opts)
return nil
end

return setmetatable({
return make_entry.set_default_entry_mt({
value = file,
status = mod,
ordinal = entry,
Expand Down
18 changes: 15 additions & 3 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ local utils = {}

utils.iswin = vim.loop.os_uname().sysname == "Windows_NT"

---@param s string
---@param i number
---@param encoding "utf-8" | "utf-16" | "utf-32"
---@return integer
utils.str_byteindex = function(s, i, encoding)
if vim.fn.has "nvim-0.11" == 1 then
return vim.str_byteindex(s, encoding, i, false)
else
return vim.lsp.util._str_byteindex_enc(s, i, encoding)
end
end

--TODO(clason): Remove when dropping support for Nvim 0.9
utils.islist = vim.fn.has "nvim-0.10" == 1 and vim.islist or vim.tbl_islist
local flatten = function(t)
Expand Down Expand Up @@ -109,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
Expand All @@ -121,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)
Expand All @@ -137,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)
Expand Down

0 comments on commit f7292a7

Please sign in to comment.