Skip to content

Commit ce8556d

Browse files
authored
fix: 0.11 compat (#586)
1 parent 08e3019 commit ce8556d

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

lua/plenary/curl.lua

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ local F = require "plenary.functional"
3737
local J = require "plenary.job"
3838
local P = require "plenary.path"
3939

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
47+
4048
-- Utils ----------------------------------------------------
4149
-------------------------------------------------------------
4250

@@ -54,7 +62,7 @@ util.url_encode = function(str)
5462
end
5563

5664
util.kv_to_list = function(kv, prefix, sep)
57-
return vim.tbl_flatten(F.kv_map(function(kvp)
65+
return flatten(F.kv_map(function(kvp)
5866
return { prefix, kvp[1] .. sep .. kvp[2] }
5967
end, kv))
6068
end
@@ -243,7 +251,7 @@ parse.request = function(opts)
243251
table.insert(result, { "-o", opts.output })
244252
end
245253
table.insert(result, parse.url(opts.url, opts.query))
246-
return vim.tbl_flatten(result), opts
254+
return flatten(result), opts
247255
end
248256

249257
-- Parse response ------------------------------------------

lua/plenary/iterators.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ function Iterator:__tostring()
3838
return "<iterator>"
3939
end
4040

41+
local is_list = vim.islist or vim.tbl_islist
42+
4143
-- A special hack for zip/chain to skip last two state, if a wrapped iterator
4244
-- has been passed
4345
local numargs = function(...)
@@ -107,7 +109,7 @@ local rawiter = function(obj, param, state)
107109
end
108110
end
109111

110-
if vim.tbl_islist(obj) then
112+
if is_list(obj) then
111113
return ipairs(obj)
112114
else
113115
-- hash

lua/plenary/job.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local vim = vim
22
local uv = vim.loop
3+
local is_list = vim.islist or vim.tbl_islist
34

45
local F = require "plenary.functional"
56

@@ -416,7 +417,7 @@ function Job:_execute()
416417
if self.writer then
417418
if Job.is_job(self.writer) then
418419
self.writer:_execute()
419-
elseif type(self.writer) == "table" and vim.tbl_islist(self.writer) then
420+
elseif type(self.writer) == "table" and is_list(self.writer) then
420421
local writer_len = #self.writer
421422
for i, v in ipairs(self.writer) do
422423
self.stdin:write(v)

lua/plenary/scandir.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ local os_sep = Path.path.sep
33
local F = require "plenary.functional"
44

55
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
613

714
local m = {}
815

@@ -151,8 +158,8 @@ m.scan_dir = function(path, opts)
151158
opts = opts or {}
152159

153160
local data = {}
154-
local base_paths = vim.tbl_flatten { path }
155-
local next_dir = vim.tbl_flatten { path }
161+
local base_paths = flatten { path }
162+
local next_dir = flatten { path }
156163

157164
local gitignore = opts.respect_gitignore and make_gitignore(base_paths) or nil
158165
local match_search_pat = opts.search_pattern and gen_search_pat(opts.search_pattern) or nil
@@ -204,8 +211,8 @@ m.scan_dir_async = function(path, opts)
204211
opts = opts or {}
205212

206213
local data = {}
207-
local base_paths = vim.tbl_flatten { path }
208-
local next_dir = vim.tbl_flatten { path }
214+
local base_paths = flatten { path }
215+
local next_dir = flatten { path }
209216
local current_dir = table.remove(next_dir, 1)
210217

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

tests/plenary/path_spec.lua

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

45
describe("Path", function()
56
it("should find valid files", function()
@@ -592,7 +593,7 @@ describe("Path", function()
592593
it("should extract the ancestors of the path", function()
593594
local p = Path:new(vim.loop.cwd())
594595
local parents = p:parents()
595-
assert(vim.tbl_islist(parents))
596+
assert(is_list(parents))
596597
for _, parent in pairs(parents) do
597598
assert.are.same(type(parent), "string")
598599
end

0 commit comments

Comments
 (0)