fix(compat): in fast vim loop issue (#589)

fixes regression introduced in ce8556d
This commit is contained in:
Simon Hauser 2024-05-20 20:33:47 +02:00 committed by GitHub
parent b5c8de02a4
commit a3e3bc82a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 31 additions and 28 deletions

17
lua/plenary/compat.lua Normal file
View file

@ -0,0 +1,17 @@
local m = {}
m.flatten = (function()
if vim.fn.has "nvim-0.11" == 1 then
return function(t)
return vim.iter(t):flatten():totable()
end
else
return function(t)
return vim.tbl_flatten(t)
end
end
end)()
m.islist = vim.islist or vim.tbl_islist
return m

View file

@ -36,14 +36,7 @@ local util, parse = {}, {}
local F = require "plenary.functional"
local J = require "plenary.job"
local P = require "plenary.path"
local flatten = function(t)
if vim.fn.has "nvim-0.11" == 1 then
return vim.iter(t):flatten():totable()
else
return vim.tbl_flatten(t)
end
end
local compat = require "plenary.compat"
-- Utils ----------------------------------------------------
-------------------------------------------------------------
@ -62,7 +55,7 @@ util.url_encode = function(str)
end
util.kv_to_list = function(kv, prefix, sep)
return flatten(F.kv_map(function(kvp)
return compat.flatten(F.kv_map(function(kvp)
return { prefix, kvp[1] .. sep .. kvp[2] }
end, kv))
end
@ -251,7 +244,7 @@ parse.request = function(opts)
table.insert(result, { "-o", opts.output })
end
table.insert(result, parse.url(opts.url, opts.query))
return flatten(result), opts
return compat.flatten(result), opts
end
-- Parse response ------------------------------------------

View file

@ -7,6 +7,7 @@
local co = coroutine
local f = require "plenary.functional"
local compat = require "plenary.compat"
--------------------------------------------------------------------------------
-- Tools
@ -38,8 +39,6 @@ function Iterator:__tostring()
return "<iterator>"
end
local is_list = vim.islist or vim.tbl_islist
-- A special hack for zip/chain to skip last two state, if a wrapped iterator
-- has been passed
local numargs = function(...)
@ -109,7 +108,7 @@ local rawiter = function(obj, param, state)
end
end
if is_list(obj) then
if compat.islist(obj) then
return ipairs(obj)
else
-- hash

View file

@ -1,6 +1,6 @@
local vim = vim
local uv = vim.loop
local is_list = vim.islist or vim.tbl_islist
local compat = require "plenary.compat"
local F = require "plenary.functional"
@ -417,7 +417,7 @@ function Job:_execute()
if self.writer then
if Job.is_job(self.writer) then
self.writer:_execute()
elseif type(self.writer) == "table" and is_list(self.writer) then
elseif type(self.writer) == "table" and compat.islist(self.writer) then
local writer_len = #self.writer
for i, v in ipairs(self.writer) do
self.stdin:write(v)

View file

@ -1,15 +1,9 @@
local Path = require "plenary.path"
local os_sep = Path.path.sep
local F = require "plenary.functional"
local compat = require "plenary.compat"
local uv = vim.loop
local flatten = function(t)
if vim.fn.has "nvim-0.11" == 1 then
return vim.iter(t):flatten():totable()
else
return vim.tbl_flatten(t)
end
end
local m = {}
@ -158,8 +152,8 @@ m.scan_dir = function(path, opts)
opts = opts or {}
local data = {}
local base_paths = flatten { path }
local next_dir = flatten { path }
local base_paths = compat.flatten { path }
local next_dir = compat.flatten { path }
local gitignore = opts.respect_gitignore and make_gitignore(base_paths) or nil
local match_search_pat = opts.search_pattern and gen_search_pat(opts.search_pattern) or nil
@ -211,8 +205,8 @@ m.scan_dir_async = function(path, opts)
opts = opts or {}
local data = {}
local base_paths = flatten { path }
local next_dir = flatten { path }
local base_paths = compat.flatten { path }
local next_dir = compat.flatten { path }
local current_dir = table.remove(next_dir, 1)
-- TODO(conni2461): get gitignore is not async

View file

@ -1,6 +1,6 @@
local Path = require "plenary.path"
local path = Path.path
local is_list = vim.islist or vim.tbl_islist
local compat = require "plenary.compat"
describe("Path", function()
it("should find valid files", function()
@ -593,7 +593,7 @@ describe("Path", function()
it("should extract the ancestors of the path", function()
local p = Path:new(vim.loop.cwd())
local parents = p:parents()
assert(is_list(parents))
assert(compat.islist(parents))
for _, parent in pairs(parents) do
assert.are.same(type(parent), "string")
end