diff --git a/lua/neotest/lib/file/init.lua b/lua/neotest/lib/file/init.lua index 89297d24..404bfd8d 100644 --- a/lua/neotest/lib/file/init.lua +++ b/lua/neotest/lib/file/init.lua @@ -4,6 +4,7 @@ local nio = require("nio") local filetype = require("plenary.filetype") local fu = require("neotest.lib.func_util") local types = require("neotest.types") +local utils = require("neotest.utils") local Tree = types.Tree local neotest = { lib = {} } @@ -354,7 +355,7 @@ end ---@param ... string Patterns to match e.g "*.py" ---@return fun(path: string): string | nil function neotest.lib.files.match_root_pattern(...) - local patterns = vim.tbl_flatten({ ... }) + local patterns = utils.tbl_flatten({ ... }) return function(start_path) local start_parents = Path:new(start_path):parents() local home = os.getenv("HOME") diff --git a/lua/neotest/lib/positions/init.lua b/lua/neotest/lib/positions/init.lua index 208a1b54..3e11b75c 100644 --- a/lua/neotest/lib/positions/init.lua +++ b/lua/neotest/lib/positions/init.lua @@ -1,5 +1,6 @@ local Path = require("plenary.path") local Tree = require("neotest.types").Tree +local utils = require("neotest.utils") local neotest = { lib = {} } @@ -251,7 +252,7 @@ function neotest.lib.positions.parse_tree(positions, opts) ---@param parents neotest.Position[] Parent positions for the position position_id = function(position, parents) return table.concat( - vim.tbl_flatten({ + utils.tbl_flatten({ position.path, vim.tbl_map(function(pos) return pos.name diff --git a/lua/neotest/logging.lua b/lua/neotest/logging.lua index b611dd39..cc982535 100644 --- a/lua/neotest/logging.lua +++ b/lua/neotest/logging.lua @@ -1,4 +1,5 @@ local config = require("neotest.config") +local utils = require("neotest.utils") local loggers = {} local log_date_format = "%FT%H:%M:%SZ%z" @@ -37,7 +38,7 @@ function Logger.new(filename, opts) end)() local function path_join(...) - return table.concat(vim.tbl_flatten({ ... }), path_sep) + return table.concat(utils.tbl_flatten({ ... }), path_sep) end logger._level = opts.level or config.log_level diff --git a/lua/neotest/utils/init.lua b/lua/neotest/utils/init.lua new file mode 100644 index 00000000..04234180 --- /dev/null +++ b/lua/neotest/utils/init.lua @@ -0,0 +1,8 @@ +local M = {} + +function M.tbl_flatten(t) + return vim.fn.has("nvim-0.11") == 1 and vim.iter(t):flatten(math.huge):totable() + or vim.tbl_flatten(t) +end + +return M diff --git a/scripts/gendocs.lua b/scripts/gendocs.lua index c7fde5e6..abcca9ee 100644 --- a/scripts/gendocs.lua +++ b/scripts/gendocs.lua @@ -1,6 +1,7 @@ -- TODO: A lot of this is private code from minidoc, which could be removed if made public local minidoc = require("mini.doc") +local utils = require("neotest.utils") local H = {} --stylua: ignore start @@ -107,7 +108,7 @@ H.default_input = function() table.insert(res, files) end - return vim.tbl_flatten(res) + return utils.tbl_flatten(res) end -- Parsing -------------------------------------------------------------------- @@ -297,7 +298,7 @@ H.toc_insert = function(s) toc_entry:clear_lines() end - for _, l in ipairs(vim.tbl_flatten(toc_lines)) do + for _, l in ipairs(utils.tbl_flatten(toc_lines)) do s:insert(l) end end @@ -620,7 +621,7 @@ H.collect_strings = function(x) end end, x) -- Flatten to only have strings and not table of strings (from `vim.split`) - return vim.tbl_flatten(res) + return utils.tbl_flatten(res) end H.file_read = function(path)