Skip to content

Commit

Permalink
fix: adapt to Nvim deprecations in 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
clason committed May 16, 2024
1 parent 52f5001 commit a71ef5a
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lua/telescope/builtin/__files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local log = require "telescope.log"

local Path = require "plenary.path"

local flatten = vim.tbl_flatten
local flatten = utils.flatten
local filter = vim.tbl_filter

local files = {}
Expand Down
8 changes: 4 additions & 4 deletions lua/telescope/builtin/__git.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ git.files = function(opts)
prompt_title = "Git Files",
__locations_input = true,
finder = finders.new_oneshot_job(
vim.tbl_flatten {
utils.flatten {
opts.git_command,
show_untracked and "--others" or nil,
recurse_submodules and "--recurse-submodules" or nil,
Expand Down Expand Up @@ -193,7 +193,7 @@ git.bcommits = function(opts)

local title = "Git BCommits"
local finder = finders.new_oneshot_job(
vim.tbl_flatten {
utils.flatten {
opts.git_command,
opts.current_file,
},
Expand Down Expand Up @@ -234,7 +234,7 @@ git.bcommits_range = function(opts)

local title = "Git BCommits in range"
local finder = finders.new_oneshot_job(
vim.tbl_flatten {
utils.flatten {
opts.git_command,
line_range,
},
Expand Down Expand Up @@ -432,7 +432,7 @@ end
local try_worktrees = function(opts)
local worktrees = conf.git_worktrees

if vim.tbl_islist(worktrees) then
if utils.islist(worktrees) then
for _, wt in ipairs(worktrees) do
if vim.startswith(opts.cwd, wt.toplevel) then
opts.toplevel = wt.toplevel
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/builtin/__internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ end

internal.man_pages = function(opts)
opts.sections = vim.F.if_nil(opts.sections, { "1" })
assert(vim.tbl_islist(opts.sections), "sections should be a list")
assert(utils.islist(opts.sections), "sections should be a list")
opts.man_cmd = utils.get_lazy_default(opts.man_cmd, function()
local uname = vim.loop.os_uname()
local sysname = string.lower(uname.sysname)
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/builtin/__lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ local function list_or_jump(action, title, params, opts)
end

local locations = {}
if not vim.tbl_islist(result) then
if not utils.tbl_islist(result) then
locations = { result }
end
vim.list_extend(locations, result)
Expand Down
6 changes: 4 additions & 2 deletions lua/telescope/config/resolve.lua
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ resolver.resolve_anchor_pos = function(anchor, p_width, p_height, max_columns, m
return pos
end

-- duplicate from utils.lua to keep self-contained
local islist = vim.fn.has "nvim-0.10" == 1 and vim.islist or vim.tbl_islist
-- Win option always returns a table with preview, results, and prompt.
-- It handles many different ways. Some examples are as follows:
--
Expand All @@ -292,7 +294,7 @@ end
-- prompt = {...},
-- }
resolver.win_option = function(val, default)
if type(val) ~= "table" or vim.tbl_islist(val) then
if type(val) ~= "table" or islist(val) then
if val == nil then
val = default
end
Expand All @@ -303,7 +305,7 @@ resolver.win_option = function(val, default)
prompt = val,
}
elseif type(val) == "table" then
assert(not vim.tbl_islist(val))
assert(not islist(val))

local val_to_set = val[1]
if val_to_set == nil then
Expand Down
3 changes: 2 additions & 1 deletion lua/telescope/finders/async_static_finder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ local scheduler = require("plenary.async").util.scheduler

local make_entry = require "telescope.make_entry"

local islist = vim.fn.has "nvim-0.10" == 1 and vim.islist or vim.tbl_islist
return function(opts)
local input_results
if vim.tbl_islist(opts) then
if islist(opts) then
input_results = opts
else
input_results = opts.results
Expand Down
8 changes: 4 additions & 4 deletions lua/telescope/pickers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,10 @@ function Picker:find()
end
a.nvim_feedkeys(a.nvim_replace_termcodes(keys, true, false, true), "ni", true)
else
utils.notify(
"pickers.find",
{ msg = "`initial_mode` should be one of ['normal', 'insert'] but passed " .. self.initial_mode, level = "ERROR" }
)
utils.notify("pickers.find", {
msg = "`initial_mode` should be one of ['normal', 'insert'] but passed " .. self.initial_mode,
level = "ERROR",
})
end

local main_loop = async.void(function()
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/previewers/term_previewer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ local bat_maker = function(filename, lnum, start, finish)
end
end

return vim.tbl_flatten {
return utils.flatten {
command,
bat_options,
"--",
Expand Down
7 changes: 7 additions & 0 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ local utils = {}

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

utils.islist = vim.fn.has "nvim-0.10" == 1 and vim.islist or vim.tbl_islist

local flatten = function(t)
return vim.iter(t):flatten():totable()
end
utils.flatten = vim.fn.has "nvim-0.10" == 1 and flatten or vim.tbl_flatten

--- Hybrid of `vim.fn.expand()` and custom `vim.fs.normalize()`
---
--- Paths starting with '%', '#' or '<' are expanded with `vim.fn.expand()`.
Expand Down
7 changes: 6 additions & 1 deletion plugin/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ end, {
local n = #l - 2

if n == 0 then
local commands = vim.tbl_flatten { builtin_list, extensions_list }
local commands = { builtin_list, extensions_list }
if vim.fn.has "nvim-0.10" then
commands = vim.iter(commands):flatten():totable()
else
commands = vim.tbl_flatten(commands)
end
table.sort(commands)

return vim.tbl_filter(function(val)
Expand Down

0 comments on commit a71ef5a

Please sign in to comment.