Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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