Skip to content

Commit 5532482

Browse files
fix: replace deprecated table operations for neovim v0.10 (#489)
Co-authored-by: Sindre T. Strøm <[email protected]>
1 parent 51a8098 commit 5532482

File tree

8 files changed

+39
-13
lines changed

8 files changed

+39
-13
lines changed

lua/diffview/lib.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ M.views = {}
1818

1919
function M.diffview_open(args)
2020
local default_args = config.get_config().default_args.DiffviewOpen
21-
local argo = arg_parser.parse(vim.tbl_flatten({ default_args, args }))
21+
local argo = arg_parser.parse(utils.flatten({ default_args, args }))
2222
local rev_arg = argo.args[1]
2323

24-
logger:info("[command call] :DiffviewOpen " .. table.concat(vim.tbl_flatten({
24+
logger:info("[command call] :DiffviewOpen " .. table.concat(utils.flatten({
2525
default_args,
2626
args,
2727
}), " "))
@@ -69,9 +69,9 @@ end
6969
---@param args string[]
7070
function M.file_history(range, args)
7171
local default_args = config.get_config().default_args.DiffviewFileHistory
72-
local argo = arg_parser.parse(vim.tbl_flatten({ default_args, args }))
72+
local argo = arg_parser.parse(utils.flatten({ default_args, args }))
7373

74-
logger:info("[command call] :DiffviewFileHistory " .. table.concat(vim.tbl_flatten({
74+
logger:info("[command call] :DiffviewFileHistory " .. table.concat(utils.flatten({
7575
default_args,
7676
args,
7777
}), " "))

lua/diffview/logger.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function Logger.dstring(object)
174174

175175
if mt and mt.__tostring then
176176
return tostring(object)
177-
elseif vim.tbl_islist(object) then
177+
elseif utils.islist(object) then
178178
if #object == 0 then return "[]" end
179179
local s = ""
180180

lua/diffview/multi_job.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ end
217217

218218
---@return string[]
219219
function MultiJob:stdout()
220-
return vim.tbl_flatten(
220+
return utils.flatten(
221221
---@param value diffview.Job
222222
vim.tbl_map(function(value)
223223
return value.stdout
@@ -227,7 +227,7 @@ end
227227

228228
---@return string[]
229229
function MultiJob:stderr()
230-
return vim.tbl_flatten(
230+
return utils.flatten(
231231
---@param value diffview.Job
232232
vim.tbl_map(function(value)
233233
return value.stderr

lua/diffview/stream.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ end
3333
---@param src table|function
3434
function Stream:create_src(src)
3535
if type(src) == "table" then
36-
if vim.tbl_islist(src) then
36+
if utils.islist(src) then
3737
local itr = ipairs(src)
3838

3939
return function()

lua/diffview/utils.lua

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,32 @@ function M.merge_sort(t, comparator)
13441344
split_merge(t, 1, #t, comparator)
13451345
end
13461346

1347+
--- @diagnostic disable-next-line: deprecated
1348+
M.islist = vim.fn.has("nvim-0.10") == 1 and vim.islist or vim.tbl_islist
1349+
1350+
--- @param t table
1351+
--- @return any[]
1352+
function M.flatten(t)
1353+
local result = {}
1354+
1355+
--- @param _t table<any,any>
1356+
local function recurse(_t)
1357+
local n = #_t
1358+
for i = 1, n do
1359+
local v = _t[i]
1360+
if type(v) == 'table' then
1361+
recurse(v)
1362+
elseif v then
1363+
table.insert(result, v)
1364+
end
1365+
end
1366+
end
1367+
1368+
recurse(t)
1369+
1370+
return result
1371+
end
1372+
13471373
M.path_sep = path_sep
13481374

13491375
--- @param t table

lua/diffview/vcs/adapter.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ end
154154
function VCSAdapter:exec_sync(args, cwd_or_opt)
155155
if not self.class.bootstrap.done then self.class.run_bootstrap() end
156156

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

159159
if not self.class.bootstrap.ok then
160160
logger:error(

lua/diffview/vcs/adapters/git/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function GitAdapter.run_bootstrap()
9898
return err(fmt("Configured `git_cmd` is not executable: '%s'", git_cmd[1]))
9999
end
100100

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

104104
if not bs.version_string then
@@ -170,7 +170,7 @@ end
170170
---@param path string
171171
---@return string?
172172
local function get_toplevel(path)
173-
local out, code = utils.job(vim.tbl_flatten({
173+
local out, code = utils.job(utils.flatten({
174174
config.get_config().git_cmd,
175175
{ "rev-parse", "--path-format=absolute", "--show-toplevel" },
176176
}), path)

lua/diffview/vcs/adapters/hg/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function HgAdapter.run_bootstrap()
5858
return err(fmt("Configured `hg_cmd` is not executable: '%s'", hg_cmd[1]))
5959
end
6060

61-
local out = utils.job(vim.tbl_flatten({ hg_cmd, "version" }))
61+
local out = utils.job(utils.flatten({ hg_cmd, "version" }))
6262
local version = out[1] and out[1]:match("Mercurial .*%(version (%S*)%)") or nil
6363
if not version then
6464
return err("Could not get Mercurial version!")
@@ -127,7 +127,7 @@ end
127127
---@param path string
128128
---@return string?
129129
local function get_toplevel(path)
130-
local out, code = utils.job(vim.tbl_flatten({config.get_config().hg_cmd, {"root"}}), path)
130+
local out, code = utils.job(utils.flatten({config.get_config().hg_cmd, {"root"}}), path)
131131
if code ~= 0 then
132132
return nil
133133
end

0 commit comments

Comments
 (0)