Skip to content

Commit

Permalink
chore: nvim 0.11 changes and deprecations
Browse files Browse the repository at this point in the history
fix(devicons): lowercase extensions/file names
fix(lines|blines): enable multiple selecttion
  • Loading branch information
ibhagwan committed May 17, 2024
1 parent e412b1b commit 923f7d4
Show file tree
Hide file tree
Showing 24 changed files with 138 additions and 118 deletions.
2 changes: 1 addition & 1 deletion lua/fzf-lua/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ M.normalize_selected = function(actions, selected)
-- so it can always be enumerated safely
if not actions or not selected then return end
local action = _default_action
if utils.tbl_length(actions) > 1 or not actions[_default_action] then
if utils.tbl_count(actions) > 1 or not actions[_default_action] then
-- keybind should be in item #1
-- default keybind is an empty string
-- so we leave that as "default"
Expand Down
8 changes: 4 additions & 4 deletions lua/fzf-lua/cmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function M.run_command(cmd, ...)
local val = arg:match("=") and arg:match("=(.*)$")
if val and #val > 0 then
local ok, loaded = serpent.load(val)
if ok and (type(loaded) ~= "table" or not vim.tbl_isempty(loaded)) then
if ok and (type(loaded) ~= "table" or not utils.tbl_isempty(loaded)) then
opts[key] = loaded
else
opts[key] = val
Expand Down Expand Up @@ -95,7 +95,7 @@ function M._candidates(line, cmp_items)
if n < 0 then return end

if n == 0 then
local commands = vim.tbl_flatten({ builtin_list })
local commands = utils.tbl_flatten({ builtin_list })
table.sort(commands)

commands = vim.tbl_filter(function(val)
Expand Down Expand Up @@ -147,7 +147,7 @@ function M._candidates(line, cmp_items)
fzf_opts = false,
__HLS = "hls", -- rename prefix
}) do
opts = vim.tbl_flatten({ opts, vim.tbl_filter(function(x)
opts = utils.tbl_flatten({ opts, vim.tbl_filter(function(x)
-- Exclude global options that can be specified only during `setup`,
-- e.g.'`winopts.preview.default` as this might confuse the user
return not M.options_md()["setup." .. x]
Expand All @@ -162,7 +162,7 @@ function M._candidates(line, cmp_items)
vim.tbl_map(function(o)
-- Cut the first part, e.g. "files.cwd" -> "cwd"
o = o:match("%..*$"):sub(2)
if not vim.tbl_contains(opts, o) then
if not utils.tbl_contains(opts, o) then
table.insert(opts, o)
end
end, opts_from_docs)
Expand Down
2 changes: 1 addition & 1 deletion lua/fzf-lua/cmp_src.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ end
---@return lsp.MarkupContent?
function Src:_get_documentation(completion_item)
local options_md = require("fzf-lua.cmd").options_md()
if not options_md or vim.tbl_isempty(options_md) then return end
if not options_md or not next(options_md) then return end
-- Test for `label:lower()` to match both `grep_c{word|WORD}`
local markdown = options_md[completion_item.label] or options_md[completion_item.label:lower()]
if not markdown and completion_item.data then
Expand Down
12 changes: 6 additions & 6 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ local contents_from_arr = function(cont_arr)
contents = {}
for _, t in ipairs(cont_arr) do
assert(type(t.contents) == cont_type, "Unable to combine contents of different types")
contents = utils.tbl_extend(contents, t.prefix and
contents = utils.tbl_join(contents, t.prefix and
vim.tbl_map(function(x)
return t.prefix .. x
end, t.contents)
Expand Down Expand Up @@ -253,7 +253,7 @@ M.CTX = function(includeBuflist)
-- buffers/tabs use these we only include the current
-- list of buffers when requested
if includeBuflist and not M.__CTX.buflist then
-- also add a map for faster lookups than `vim.tbl_contains`
-- also add a map for faster lookups than `utils.tbl_contains`
-- TODO: is it really faster since we must use string keys?
M.__CTX.bufmap = {}
M.__CTX.buflist = vim.api.nvim_list_bufs()
Expand Down Expand Up @@ -515,7 +515,7 @@ M.create_fzf_colors = function(opts)
table.insert(spec, list[i])
end
end
if not vim.tbl_isempty(spec) then
if not utils.tbl_isempty(spec) then
table.insert(spec, 1, flag)
table.insert(tbl, table.concat(spec, ":"))
end
Expand All @@ -524,11 +524,11 @@ M.create_fzf_colors = function(opts)
end
end

return not vim.tbl_isempty(tbl) and table.concat(tbl, ",")
return not utils.tbl_isempty(tbl) and table.concat(tbl, ",")
end

M.create_fzf_binds = function(binds)
if not binds or vim.tbl_isempty(binds) then return end
if not binds or utils.tbl_isempty(binds) then return end
local tbl = {}
local dedup = {}
for k, v in pairs(binds) do
Expand Down Expand Up @@ -900,7 +900,7 @@ M.set_header = function(opts, hdr_tbl)
end
end
-- table.concat fails if the table indexes aren't consecutive
return not vim.tbl_isempty(ret) and (function()
return not utils.tbl_isempty(ret) and (function()
local t = {}
for _, i in pairs(ret) do
table.insert(t, i)
Expand Down
4 changes: 0 additions & 4 deletions lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,9 @@ M.defaults.lines = {
show_unlisted = false,
no_term_buffers = true,
fzf_opts = {
["--no-multi"] = true,
["--delimiter"] = "[\\]:]",
["--nth"] = "2..",
["--tiebreak"] = "index",
["--tabstop"] = "1",
},
line_field_index = "{3}",
_actions = function() return M.globals.actions.buffers end,
Expand All @@ -553,11 +551,9 @@ M.defaults.blines = {
show_unlisted = true,
no_term_buffers = false,
fzf_opts = {
["--no-multi"] = true,
["--delimiter"] = "[:]",
["--with-nth"] = "2..",
["--tiebreak"] = "index",
["--tabstop"] = "1",
},
line_field_index = "{2}",
_actions = function() return M.globals.actions.buffers end,
Expand Down
8 changes: 5 additions & 3 deletions lua/fzf-lua/devicons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ M.load_icons = function()
end
return M.__DEVICONS_LIB.get_icons()
end)
if not ok or not all_devicons or vim.tbl_isempty(all_devicons) then
if not ok or not all_devicons or utils.tbl_isempty(all_devicons) then
-- something is wrong with devicons
-- can't use `error` due to fast event
print("[Fzf-lua] error: devicons.get_icons() is nil or empty!")
Expand Down Expand Up @@ -164,7 +164,7 @@ M.get_devicon = function(filepath, extensionOverride)
end

local icon, color
local filename = path.tail(filepath)
local filename = path.tail(filepath):lower()
local ext = extensionOverride or path.extension(filename, true)

-- lookup directly by filename
Expand All @@ -173,12 +173,14 @@ M.get_devicon = function(filepath, extensionOverride)
icon, color = by_filename.icon, by_filename.color
end

if ext then ext = ext:lower() end

-- check for `ext` as extension can be nil, e.g. "dockerfile"
-- lookup by 2 part extensions, e.g. "foo.test.tsx"
if ext and not icon and M.STATE.icons.ext_has_2part[ext] then
local ext2 = path.extension(filename:sub(1, #filename - #ext - 1))
if ext2 then
local by_ext_2part = M.STATE.icons.by_ext_2part[ext2 .. "." .. ext]
local by_ext_2part = M.STATE.icons.by_ext_2part[ext2:lower() .. "." .. ext]
if by_ext_2part then
icon, color = by_ext_2part.icon, by_ext_2part.color
end
Expand Down
10 changes: 5 additions & 5 deletions lua/fzf-lua/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
-- instance never terminates which hangs fzf on exit
local FZF_DEFAULT_COMMAND = nil

utils.tbl_extend(cmd, fzf_cli_args or {})
utils.tbl_join(cmd, fzf_cli_args or {})
if type(opts.fzf_cli_args) == "table" then
utils.tbl_extend(cmd, opts.fzf_cli_args)
utils.tbl_join(cmd, opts.fzf_cli_args)
elseif type(opts.fzf_cli_args) == "string" then
utils.tbl_extend(cmd, { opts.fzf_cli_args })
utils.tbl_join(cmd, { opts.fzf_cli_args })
end

if contents then
Expand Down Expand Up @@ -179,7 +179,7 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
-- error out, but that doesn't matter so we just break out of the loop.
if contents then
if type(contents) == "table" then
if not vim.tbl_isempty(contents) then
if not utils.tbl_isempty(contents) then
write_cb(vim.tbl_map(function(x)
return x .. "\n"
end, contents))
Expand Down Expand Up @@ -251,7 +251,7 @@ function M.raw_fzf(contents, fzf_cli_args, opts)
and { "cmd", "/d", "/e:off", "/f:off", "/v:off", "/c" }
or { "sh", "-c" }
if utils.__IS_WINDOWS then
utils.tbl_extend(shell_cmd, cmd)
utils.tbl_join(shell_cmd, cmd)
else
table.insert(shell_cmd, table.concat(cmd, " "))
end
Expand Down
4 changes: 2 additions & 2 deletions lua/fzf-lua/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ end

M.lcol = function(entry, opts)
if not entry then return nil end
local hl_colnr = vim.tbl_contains(opts._cached_hls or {}, "path_colnr")
local hl_colnr = utils.tbl_contains(opts._cached_hls or {}, "path_colnr")
and opts.hls.path_colnr or "blue"
local hl_linenr = vim.tbl_contains(opts._cached_hls or {}, "path_linenr")
local hl_linenr = utils.tbl_contains(opts._cached_hls or {}, "path_linenr")
and opts.hls.path_linenr or "green"
local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)
return string.format("%s:%s%s%s",
Expand Down
22 changes: 10 additions & 12 deletions lua/fzf-lua/previewer/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
-- stop ueberzug shell job
self:stop_ueberzug()
local entry = self:parse_entry(entry_str)
if vim.tbl_isempty(entry) then return end
if utils.tbl_isempty(entry) then return end
if entry.bufnr and not api.nvim_buf_is_loaded(entry.bufnr)
and vim.api.nvim_buf_is_valid(entry.bufnr) then
-- buffer is not loaded, can happen when calling "lines" with `set nohidden`
Expand Down Expand Up @@ -648,7 +648,7 @@ function Previewer.buffer_or_file:populate_preview_buf(entry_str)
assert(entry.path)
-- not found in cache, attempt to load
local tmpbuf = self:get_tmp_buffer()
if self.extensions and not vim.tbl_isempty(self.extensions) then
if self.extensions and not utils.tbl_isempty(self.extensions) then
local ext = path.extension(entry.path)
local cmd = ext and self.extensions[ext:lower()]
if cmd and self:populate_terminal_cmd(tmpbuf, cmd, entry) then
Expand Down Expand Up @@ -727,7 +727,7 @@ local ts_attach_08 = function(bufnr, ft)
local is_table = type(config.additional_vim_regex_highlighting) == "table"
if
config.additional_vim_regex_highlighting
and (not is_table or vim.tbl_contains(config.additional_vim_regex_highlighting, lang))
and (not is_table or utils.tbl_contains(config.additional_vim_regex_highlighting, lang))
then
vim.bo[bufnr].syntax = ft
end
Expand Down Expand Up @@ -770,11 +770,9 @@ function Previewer.buffer_or_file:do_syntax(entry)
if syntax_limit_reached > 0 and self.opts.silent == false then
utils.info(string.format(
"syntax disabled for '%s' (%s), consider increasing '%s(%d)'", entry.path,
utils._if(syntax_limit_reached == 1,
("%d lines"):format(lcount),
("%db"):format(bytes)),
utils._if(syntax_limit_reached == 1, "syntax_limit_l", "syntax_limit_b"),
utils._if(syntax_limit_reached == 1, self.syntax_limit_l, self.syntax_limit_b)
syntax_limit_reached == 1 and ("%d lines"):format(lcount) or ("%db"):format(bytes),
syntax_limit_reached == 1 and "syntax_limit_l" or "syntax_limit_b",
syntax_limit_reached == 1 and self.syntax_limit_l or self.syntax_limit_b
))
end
if syntax_limit_reached == 0 then
Expand All @@ -796,9 +794,9 @@ function Previewer.buffer_or_file:do_syntax(entry)
self.treesitter.enable == false or
self.treesitter.disable == true or
(type(self.treesitter.enable) == "table" and
not vim.tbl_contains(self.treesitter.enable, ft)) or
not utils.tbl_contains(self.treesitter.enable, ft)) or
(type(self.treesitter.disable) == "table" and
vim.tbl_contains(self.treesitter.disable, ft)) then
utils.tbl_contains(self.treesitter.disable, ft)) then
return false
end
return true
Expand Down Expand Up @@ -1220,7 +1218,7 @@ function Previewer.quickfix:populate_preview_buf(entry_str)
local qf_list = self.opts._is_loclist
and vim.fn.getloclist(self.win.src_winid, { all = "", nr = tonumber(nr) })
or vim.fn.getqflist({ all = "", nr = tonumber(nr) })
if vim.tbl_isempty(qf_list) or vim.tbl_isempty(qf_list.items) then
if utils.tbl_isempty(qf_list) or utils.tbl_isempty(qf_list.items) then
return
end

Expand Down Expand Up @@ -1262,7 +1260,7 @@ end
function Previewer.autocmds:populate_preview_buf(entry_str)
if not self.win or not self.win:validate_preview() then return end
local entry = self:parse_entry(entry_str)
if vim.tbl_isempty(entry) then return end
if utils.tbl_isempty(entry) then return end
self._is_vimL_command = false
if entry.path == "<none>" then
self._is_vimL_command = true
Expand Down
6 changes: 3 additions & 3 deletions lua/fzf-lua/previewer/codeaction.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ local function diff_workspace_edit(workspace_edit, offset_encoding, diff_opts)
end

local all_changes = workspace_edit.changes
if all_changes and not vim.tbl_isempty(all_changes) then
if all_changes and not utils.tbl_isempty(all_changes) then
for uri, changes in pairs(all_changes) do
local path = vim.fn.fnamemodify(vim.uri_to_fname(uri), ":.")
local bufnr = vim.uri_to_bufnr(uri)
Expand Down Expand Up @@ -170,11 +170,11 @@ local function preview_action_tuple(self, idx, callback)
local choice = self.opts._items[idx]
local bufnr = assert(choice.ctx.bufnr, "Must have buffer number")
local reg = client.dynamic_capabilities:get(ms.textDocument_codeAction, { bufnr = bufnr })
return vim.tbl_get(reg or {}, "registerOptions", "resolveProvider")
return utils.tbl_get(reg or {}, "registerOptions", "resolveProvider")
or client.supports_method(ms.codeAction_resolve)
end)()
-- prior to nvim 0.10 we could check `client.server_capabilities`
or vim.tbl_get(client.server_capabilities, "codeActionProvider", "resolveProvider")
or utils.tbl_get(client.server_capabilities, "codeActionProvider", "resolveProvider")
if not action.edit and client and supports_resolve then
-- Action is not a workspace edit, attempt to resolve the code action
-- in case it resolves to a workspace edit
Expand Down
2 changes: 1 addition & 1 deletion lua/fzf-lua/previewer/fzf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ end
function Previewer.git_diff:cmdline(o)
o = o or {}
local act = shell.raw_preview_action_cmd(function(items, fzf_lines, fzf_columns)
if not items or vim.tbl_isempty(items) then
if not items or utils.tbl_isempty(items) then
utils.warn("shell error while running preview action.")
return
end
Expand Down
2 changes: 1 addition & 1 deletion lua/fzf-lua/providers/buffers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ local function gen_buffer_entry(opts, buf, max_bufnr, cwd)
end
local max_bufnr_w = 3 + #tostring(max_bufnr) + utils.ansi_escseq_len(bufnrstr)
local item_str = string.format("%s%s%s%s%s%s%s%s",
utils._if(opts._prefix, opts._prefix, ""),
opts._prefix or "",
string.format("%-" .. tostring(max_bufnr_w) .. "s", bufnrstr),
utils.nbsp,
flags,
Expand Down
4 changes: 2 additions & 2 deletions lua/fzf-lua/providers/colorschemes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function AsyncDownloadManager:load_db(db)
utils.warn(string.format("package %s: missing 'url'", k))
return false
end
if type(p.colorschemes) ~= "table" or vim.tbl_isempty(p.colorschemes) then
if type(p.colorschemes) ~= "table" or utils.tbl_isempty(p.colorschemes) then
utils.warn(string.format("package %s: missing or empty 'colorschemes'", k))
return false
end
Expand Down Expand Up @@ -268,7 +268,7 @@ function AsyncDownloadManager:delete(plugin)
end

function AsyncDownloadManager:queue(plugin, job_args)
if vim.tbl_count(self.job_ids) < self.max_threads then
if utils.tbl_count(self.job_ids) < self.max_threads then
self:jobstart(plugin, job_args)
else
table.insert(self.job_stack, { plugin, job_args })
Expand Down
2 changes: 1 addition & 1 deletion lua/fzf-lua/providers/dap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ M.breakpoints = function(opts)
if not dap() then return end
local dap_bps = require "dap.breakpoints"

if vim.tbl_isempty(dap_bps.get()) then
if utils.tbl_isempty(dap_bps.get()) then
utils.info("Breakpoint list is empty.")
return
end
Expand Down
8 changes: 4 additions & 4 deletions lua/fzf-lua/providers/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ M.diagnostics = function(opts)
if utils.__HAS_NVIM_010 then
local sign_confs = vim.diagnostic.config().signs
local level = vim.diagnostic.severity[k:upper()]
if type(sign_confs) ~= "table" or vim.tbl_isempty(sign_confs) then sign_confs = nil end
if type(sign_confs) ~= "table" or utils.tbl_isempty(sign_confs) then sign_confs = nil end
opts.__signs[v.severity].text =
(not opts.diag_icons or not sign_confs or not sign_confs.text or not sign_confs.text[level])
and v.default or vim.trim(sign_confs.text[level])
Expand All @@ -81,7 +81,7 @@ M.diagnostics = function(opts)
local sign_def = vim.fn.sign_getdefined(v.name)
-- can be empty when config set to (#480):
-- vim.diagnostic.config({ signs = false })
if vim.tbl_isempty(sign_def) then sign_def = nil end
if utils.tbl_isempty(sign_def) then sign_def = nil end
opts.__signs[v.severity].text =
(not opts.diag_icons or not sign_def or not sign_def[1].text)
and v.default or vim.trim(sign_def[1].text)
Expand Down Expand Up @@ -140,7 +140,7 @@ M.diagnostics = function(opts)
local has_diags = false
if vim.diagnostic then
-- format: { <diag array> }
has_diags = not vim.tbl_isempty(diag_results)
has_diags = not utils.tbl_isempty(diag_results)
else
-- format: { [bufnr] = <diag array>, ... }
for _, diags in pairs(diag_results) do
Expand Down Expand Up @@ -186,7 +186,7 @@ M.diagnostics = function(opts)
for _, diag in ipairs(diags) do
-- workspace diagnostics may include
-- empty tables for unused buffers
if not vim.tbl_isempty(diag) and filter_diag_severity(opts, diag.severity) then
if not utils.tbl_isempty(diag) and filter_diag_severity(opts, diag.severity) then
-- wrap with 'vim.schedule' or calls to vim.{fn|api} fail:
-- E5560: vimL function must not be called in a lua loop callback
vim.schedule(function()
Expand Down
Loading

0 comments on commit 923f7d4

Please sign in to comment.