Skip to content

Commit

Permalink
fix: replace tbl_flatten to flatten():totable() (nvim-neotest#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobfonseca authored May 22, 2024
1 parent 420288e commit 6f35d79
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lua/neotest/lib/file/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {} }
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion lua/neotest/lib/positions/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local Path = require("plenary.path")
local Tree = require("neotest.types").Tree
local utils = require("neotest.utils")

local neotest = { lib = {} }

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lua/neotest/logging.lua
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lua/neotest/utils/init.lua
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions scripts/gendocs.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 --------------------------------------------------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6f35d79

Please sign in to comment.