Skip to content

Commit

Permalink
fix: replace tbl_flatten to flatten():totable() if using nvim-0.10 (#131
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pablobfonseca authored May 23, 2024
1 parent 3767179 commit aa4442a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lua/null-ls/utils/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local api = vim.api
local util = require("null-ls.utils.tbl_flatten")

local is_windows = vim.loop.os_uname().version:match("Windows")
local path_separator = is_windows and "\\" or "/"
Expand Down Expand Up @@ -100,7 +101,7 @@ M.make_conditional_utils = function()

return {
has_file = function(...)
local patterns = vim.tbl_flatten({ ... })
local patterns = util.tbl_flatten({ ... })
for _, name in ipairs(patterns) do
local full_path = vim.loop.fs_realpath(name)
if full_path and M.path.exists(full_path) then
Expand All @@ -110,7 +111,7 @@ M.make_conditional_utils = function()
return false
end,
root_has_file = function(...)
local patterns = vim.tbl_flatten({ ... })
local patterns = util.tbl_flatten({ ... })
for _, name in ipairs(patterns) do
if M.path.exists(M.path.join(root, name)) then
return true
Expand Down Expand Up @@ -260,7 +261,7 @@ M.path = {
return fs_stat_stat ~= nil
end,
join = function(...)
return table.concat(vim.tbl_flatten({ ... }), path_separator):gsub(path_separator .. "+", path_separator)
return table.concat(util.tbl_flatten({ ... }), path_separator):gsub(path_separator .. "+", path_separator)
end,
-- An iterator like vim.fs.parents but includes the start_path.
ancestors = function(start_path)
Expand All @@ -278,7 +279,7 @@ M.path = {
---@vararg string patterns
---@return fun(startpath: string, fun(root_dir: string|nil)): nil root_dir
M.root_pattern_async = function(...)
local patterns = vim.tbl_flatten({ ... })
local patterns = util.tbl_flatten({ ... })

local function match(path)
for _, pattern in ipairs(patterns) do
Expand Down Expand Up @@ -313,7 +314,7 @@ end
---@vararg string patterns
---@return fun(startpath: string): string|nil root_dir
M.root_pattern = function(...)
local patterns = vim.tbl_flatten({ ... })
local patterns = util.tbl_flatten({ ... })

local function matcher(path)
if not path then
Expand Down
7 changes: 7 additions & 0 deletions lua/null-ls/utils/tbl_flatten.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
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

0 comments on commit aa4442a

Please sign in to comment.