Skip to content

Commit a3e3bc8

Browse files
authored
fix(compat): in fast vim loop issue (#589)
fixes regression introduced in ce8556d
1 parent b5c8de0 commit a3e3bc8

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

lua/plenary/compat.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local m = {}
2+
3+
m.flatten = (function()
4+
if vim.fn.has "nvim-0.11" == 1 then
5+
return function(t)
6+
return vim.iter(t):flatten():totable()
7+
end
8+
else
9+
return function(t)
10+
return vim.tbl_flatten(t)
11+
end
12+
end
13+
end)()
14+
15+
m.islist = vim.islist or vim.tbl_islist
16+
17+
return m

lua/plenary/curl.lua

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,7 @@ local util, parse = {}, {}
3636
local F = require "plenary.functional"
3737
local J = require "plenary.job"
3838
local P = require "plenary.path"
39-
40-
local flatten = function(t)
41-
if vim.fn.has "nvim-0.11" == 1 then
42-
return vim.iter(t):flatten():totable()
43-
else
44-
return vim.tbl_flatten(t)
45-
end
46-
end
39+
local compat = require "plenary.compat"
4740

4841
-- Utils ----------------------------------------------------
4942
-------------------------------------------------------------
@@ -62,7 +55,7 @@ util.url_encode = function(str)
6255
end
6356

6457
util.kv_to_list = function(kv, prefix, sep)
65-
return flatten(F.kv_map(function(kvp)
58+
return compat.flatten(F.kv_map(function(kvp)
6659
return { prefix, kvp[1] .. sep .. kvp[2] }
6760
end, kv))
6861
end
@@ -251,7 +244,7 @@ parse.request = function(opts)
251244
table.insert(result, { "-o", opts.output })
252245
end
253246
table.insert(result, parse.url(opts.url, opts.query))
254-
return flatten(result), opts
247+
return compat.flatten(result), opts
255248
end
256249

257250
-- Parse response ------------------------------------------

lua/plenary/iterators.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
local co = coroutine
99
local f = require "plenary.functional"
10+
local compat = require "plenary.compat"
1011

1112
--------------------------------------------------------------------------------
1213
-- Tools
@@ -38,8 +39,6 @@ function Iterator:__tostring()
3839
return "<iterator>"
3940
end
4041

41-
local is_list = vim.islist or vim.tbl_islist
42-
4342
-- A special hack for zip/chain to skip last two state, if a wrapped iterator
4443
-- has been passed
4544
local numargs = function(...)
@@ -109,7 +108,7 @@ local rawiter = function(obj, param, state)
109108
end
110109
end
111110

112-
if is_list(obj) then
111+
if compat.islist(obj) then
113112
return ipairs(obj)
114113
else
115114
-- hash

lua/plenary/job.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local vim = vim
22
local uv = vim.loop
3-
local is_list = vim.islist or vim.tbl_islist
3+
local compat = require "plenary.compat"
44

55
local F = require "plenary.functional"
66

@@ -417,7 +417,7 @@ function Job:_execute()
417417
if self.writer then
418418
if Job.is_job(self.writer) then
419419
self.writer:_execute()
420-
elseif type(self.writer) == "table" and is_list(self.writer) then
420+
elseif type(self.writer) == "table" and compat.islist(self.writer) then
421421
local writer_len = #self.writer
422422
for i, v in ipairs(self.writer) do
423423
self.stdin:write(v)

lua/plenary/scandir.lua

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
local Path = require "plenary.path"
22
local os_sep = Path.path.sep
33
local F = require "plenary.functional"
4+
local compat = require "plenary.compat"
45

56
local uv = vim.loop
6-
local flatten = function(t)
7-
if vim.fn.has "nvim-0.11" == 1 then
8-
return vim.iter(t):flatten():totable()
9-
else
10-
return vim.tbl_flatten(t)
11-
end
12-
end
137

148
local m = {}
159

@@ -158,8 +152,8 @@ m.scan_dir = function(path, opts)
158152
opts = opts or {}
159153

160154
local data = {}
161-
local base_paths = flatten { path }
162-
local next_dir = flatten { path }
155+
local base_paths = compat.flatten { path }
156+
local next_dir = compat.flatten { path }
163157

164158
local gitignore = opts.respect_gitignore and make_gitignore(base_paths) or nil
165159
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)
211205
opts = opts or {}
212206

213207
local data = {}
214-
local base_paths = flatten { path }
215-
local next_dir = flatten { path }
208+
local base_paths = compat.flatten { path }
209+
local next_dir = compat.flatten { path }
216210
local current_dir = table.remove(next_dir, 1)
217211

218212
-- TODO(conni2461): get gitignore is not async

tests/plenary/path_spec.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
local Path = require "plenary.path"
22
local path = Path.path
3-
local is_list = vim.islist or vim.tbl_islist
3+
local compat = require "plenary.compat"
44

55
describe("Path", function()
66
it("should find valid files", function()
@@ -593,7 +593,7 @@ describe("Path", function()
593593
it("should extract the ancestors of the path", function()
594594
local p = Path:new(vim.loop.cwd())
595595
local parents = p:parents()
596-
assert(is_list(parents))
596+
assert(compat.islist(parents))
597597
for _, parent in pairs(parents) do
598598
assert.are.same(type(parent), "string")
599599
end

0 commit comments

Comments
 (0)