Skip to content

Commit 6f35d79

Browse files
fix: replace tbl_flatten to flatten():totable() (#410)
1 parent 420288e commit 6f35d79

File tree

5 files changed

+18
-6
lines changed

5 files changed

+18
-6
lines changed

lua/neotest/lib/file/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local nio = require("nio")
44
local filetype = require("plenary.filetype")
55
local fu = require("neotest.lib.func_util")
66
local types = require("neotest.types")
7+
local utils = require("neotest.utils")
78
local Tree = types.Tree
89

910
local neotest = { lib = {} }
@@ -354,7 +355,7 @@ end
354355
---@param ... string Patterns to match e.g "*.py"
355356
---@return fun(path: string): string | nil
356357
function neotest.lib.files.match_root_pattern(...)
357-
local patterns = vim.tbl_flatten({ ... })
358+
local patterns = utils.tbl_flatten({ ... })
358359
return function(start_path)
359360
local start_parents = Path:new(start_path):parents()
360361
local home = os.getenv("HOME")

lua/neotest/lib/positions/init.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local Path = require("plenary.path")
22
local Tree = require("neotest.types").Tree
3+
local utils = require("neotest.utils")
34

45
local neotest = { lib = {} }
56

@@ -251,7 +252,7 @@ function neotest.lib.positions.parse_tree(positions, opts)
251252
---@param parents neotest.Position[] Parent positions for the position
252253
position_id = function(position, parents)
253254
return table.concat(
254-
vim.tbl_flatten({
255+
utils.tbl_flatten({
255256
position.path,
256257
vim.tbl_map(function(pos)
257258
return pos.name

lua/neotest/logging.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local config = require("neotest.config")
2+
local utils = require("neotest.utils")
23
local loggers = {}
34

45
local log_date_format = "%FT%H:%M:%SZ%z"
@@ -37,7 +38,7 @@ function Logger.new(filename, opts)
3738
end)()
3839

3940
local function path_join(...)
40-
return table.concat(vim.tbl_flatten({ ... }), path_sep)
41+
return table.concat(utils.tbl_flatten({ ... }), path_sep)
4142
end
4243

4344
logger._level = opts.level or config.log_level

lua/neotest/utils/init.lua

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
local M = {}
2+
3+
function M.tbl_flatten(t)
4+
return vim.fn.has("nvim-0.11") == 1 and vim.iter(t):flatten(math.huge):totable()
5+
or vim.tbl_flatten(t)
6+
end
7+
8+
return M

scripts/gendocs.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- TODO: A lot of this is private code from minidoc, which could be removed if made public
22

33
local minidoc = require("mini.doc")
4+
local utils = require("neotest.utils")
45

56
local H = {}
67
--stylua: ignore start
@@ -107,7 +108,7 @@ H.default_input = function()
107108
table.insert(res, files)
108109
end
109110

110-
return vim.tbl_flatten(res)
111+
return utils.tbl_flatten(res)
111112
end
112113

113114
-- Parsing --------------------------------------------------------------------
@@ -297,7 +298,7 @@ H.toc_insert = function(s)
297298
toc_entry:clear_lines()
298299
end
299300

300-
for _, l in ipairs(vim.tbl_flatten(toc_lines)) do
301+
for _, l in ipairs(utils.tbl_flatten(toc_lines)) do
301302
s:insert(l)
302303
end
303304
end
@@ -620,7 +621,7 @@ H.collect_strings = function(x)
620621
end
621622
end, x)
622623
-- Flatten to only have strings and not table of strings (from `vim.split`)
623-
return vim.tbl_flatten(res)
624+
return utils.tbl_flatten(res)
624625
end
625626

626627
H.file_read = function(path)

0 commit comments

Comments
 (0)