mirror of
https://github.com/nvim-lua/plenary.nvim
synced 2024-09-16 13:24:05 +02:00
fix(compat): in fast vim loop issue (#589)
fixes regression introduced in ce8556d
This commit is contained in:
parent
b5c8de02a4
commit
a3e3bc82a3
6 changed files with 31 additions and 28 deletions
17
lua/plenary/compat.lua
Normal file
17
lua/plenary/compat.lua
Normal 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
|
|
@ -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 ------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue