Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace deprecated table operations for neovim v0.10 #489

Merged
merged 4 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lua/diffview/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ M.views = {}

function M.diffview_open(args)
local default_args = config.get_config().default_args.DiffviewOpen
local argo = arg_parser.parse(vim.tbl_flatten({ default_args, args }))
local argo = arg_parser.parse(utils.flatten({ default_args, args }))
local rev_arg = argo.args[1]

logger:info("[command call] :DiffviewOpen " .. table.concat(vim.tbl_flatten({
logger:info("[command call] :DiffviewOpen " .. table.concat(utils.flatten({
default_args,
args,
}), " "))
Expand Down Expand Up @@ -69,9 +69,9 @@ end
---@param args string[]
function M.file_history(range, args)
local default_args = config.get_config().default_args.DiffviewFileHistory
local argo = arg_parser.parse(vim.tbl_flatten({ default_args, args }))
local argo = arg_parser.parse(utils.flatten({ default_args, args }))

logger:info("[command call] :DiffviewFileHistory " .. table.concat(vim.tbl_flatten({
logger:info("[command call] :DiffviewFileHistory " .. table.concat(utils.flatten({
default_args,
args,
}), " "))
Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function Logger.dstring(object)

if mt and mt.__tostring then
return tostring(object)
elseif vim.tbl_islist(object) then
elseif utils.islist(object) then
if #object == 0 then return "[]" end
local s = ""

Expand Down
4 changes: 2 additions & 2 deletions lua/diffview/multi_job.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ end

---@return string[]
function MultiJob:stdout()
return vim.tbl_flatten(
return utils.flatten(
---@param value diffview.Job
vim.tbl_map(function(value)
return value.stdout
Expand All @@ -227,7 +227,7 @@ end

---@return string[]
function MultiJob:stderr()
return vim.tbl_flatten(
return utils.flatten(
---@param value diffview.Job
vim.tbl_map(function(value)
return value.stderr
Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/stream.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end
---@param src table|function
function Stream:create_src(src)
if type(src) == "table" then
if vim.tbl_islist(src) then
if utils.islist(src) then
local itr = ipairs(src)

return function()
Expand Down
26 changes: 26 additions & 0 deletions lua/diffview/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,32 @@ function M.merge_sort(t, comparator)
split_merge(t, 1, #t, comparator)
end

--- @diagnostic disable-next-line: deprecated
M.islist = vim.fn.has("nvim-0.10") == 1 and vim.islist or vim.tbl_islist

--- @param t table
--- @return any[]
function M.flatten(t)
local result = {}

--- @param _t table<any,any>
local function recurse(_t)
local n = #_t
for i = 1, n do
local v = _t[i]
if type(v) == 'table' then
recurse(v)
elseif v then
table.insert(result, v)
end
end
end

recurse(t)

return result
end

M.path_sep = path_sep

--- @param t table
Expand Down
2 changes: 1 addition & 1 deletion lua/diffview/vcs/adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ end
function VCSAdapter:exec_sync(args, cwd_or_opt)
if not self.class.bootstrap.done then self.class.run_bootstrap() end

local cmd = vim.tbl_flatten({ self:get_command(), args })
local cmd = utils.flatten({ self:get_command(), args })

if not self.class.bootstrap.ok then
logger:error(
Expand Down
4 changes: 2 additions & 2 deletions lua/diffview/vcs/adapters/git/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function GitAdapter.run_bootstrap()
return err(fmt("Configured `git_cmd` is not executable: '%s'", git_cmd[1]))
end

local out = utils.job(vim.tbl_flatten({ git_cmd, "version" }))
local out = utils.job(utils.flatten({ git_cmd, "version" }))
bs.version_string = out[1] and out[1]:match("git version (%S+)") or nil

if not bs.version_string then
Expand Down Expand Up @@ -170,7 +170,7 @@ end
---@param path string
---@return string?
local function get_toplevel(path)
local out, code = utils.job(vim.tbl_flatten({
local out, code = utils.job(utils.flatten({
config.get_config().git_cmd,
{ "rev-parse", "--path-format=absolute", "--show-toplevel" },
}), path)
Expand Down
4 changes: 2 additions & 2 deletions lua/diffview/vcs/adapters/hg/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function HgAdapter.run_bootstrap()
return err(fmt("Configured `hg_cmd` is not executable: '%s'", hg_cmd[1]))
end

local out = utils.job(vim.tbl_flatten({ hg_cmd, "version" }))
local out = utils.job(utils.flatten({ hg_cmd, "version" }))
local version = out[1] and out[1]:match("Mercurial .*%(version (%S*)%)") or nil
if not version then
return err("Could not get Mercurial version!")
Expand Down Expand Up @@ -127,7 +127,7 @@ end
---@param path string
---@return string?
local function get_toplevel(path)
local out, code = utils.job(vim.tbl_flatten({config.get_config().hg_cmd, {"root"}}), path)
local out, code = utils.job(utils.flatten({config.get_config().hg_cmd, {"root"}}), path)
if code ~= 0 then
return nil
end
Expand Down