Skip to content

Commit

Permalink
fix: replace tbl_flatten to flatten():totable() (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobfonseca committed May 22, 2024
1 parent 8765cbc commit def97d9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lua/nio/logger.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local util = require("nio.util")

local loggers = {}

local log_date_format = "%FT%H:%M:%SZ%z"
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
8 changes: 8 additions & 0 deletions lua/nio/util.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 util = require("nio.util")

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 util.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(util.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 util.tbl_flatten(res)
end

H.file_read = function(path)
Expand Down

0 comments on commit def97d9

Please sign in to comment.