fix: replace tbl_flatten to flatten():totable() (#18)

This commit is contained in:
Pablo Fonseca 2024-05-22 15:25:58 +01:00 committed by GitHub
parent 8765cbc4d0
commit def97d9351
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View file

@ -1,3 +1,5 @@
local util = require("nio.util")
local loggers = {}
local log_date_format = "%FT%H:%M:%SZ%z"
@ -36,7 +38,7 @@ function Logger.new(filename, opts)
end)()
local function path_join(...)
return table.concat(vim.tbl_flatten({ ... }), path_sep)
return table.concat(util.tbl_flatten({ ... }), path_sep)
end
logger._level = opts.level or vim.log.levels.WARN
@ -52,7 +54,7 @@ function Logger.new(filename, opts)
local log_info = vim.loop.fs_stat(logger._filename)
if log_info and log_info.size > LARGE then
local warn_msg =
string.format("Nio log is large (%d MB): %s", log_info.size / (1000 * 1000), logger._filename)
string.format("Nio log is large (%d MB): %s", log_info.size / (1000 * 1000), logger._filename)
vim.notify(warn_msg, vim.log.levels.WARN)
end

8
lua/nio/util.lua Normal file
View file

@ -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

View file

@ -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 util = require("nio.util")
local H = {}
--stylua: ignore start
@ -107,7 +108,7 @@ H.default_input = function()
table.insert(res, files)
end
return vim.tbl_flatten(res)
return util.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(util.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 util.tbl_flatten(res)
end
H.file_read = function(path)