Skip to content

Commit 351f010

Browse files
authored
Merge branch 'nvim-lua:master' into scan_symlink
2 parents 771fa46 + 4f71c0c commit 351f010

29 files changed

+413
-142
lines changed

.github/workflows/default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- os: ubuntu-22.04
1818
rev: v0.8.3/nvim-linux64.tar.gz
1919
- os: ubuntu-22.04
20-
rev: v0.9.0/nvim-linux64.tar.gz
20+
rev: v0.9.1/nvim-linux64.tar.gz
2121
steps:
2222
- uses: actions/checkout@v3
2323
- run: date +%F > todays-date

.luacheckrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ read_globals = {
2727
exclude_files = {
2828
"lua/plenary/profile/lua_profiler.lua",
2929
"lua/plenary/profile/memory_profiler.lua",
30-
"lua/plenary/vararg/rotate.lua",
3130
"lua/plenary/async_lib/*.lua",
3231
}
3332

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.PHONY: test generate_filetypes lint luarocks_upload test_luarocks_install
22
test:
3-
nvim --headless --noplugin -u scripts/minimal.vim -c "PlenaryBustedDirectory tests/plenary/ {minimal_init = 'tests/minimal_init.vim'}"
3+
nvim --headless --noplugin -u scripts/minimal.vim -c "PlenaryBustedDirectory tests/plenary/ {minimal_init = 'tests/minimal_init.vim', sequential = true}"
44

55
generate_filetypes:
66
nvim --headless -c 'luafile scripts/update_filetypes_from_github.lua' -c 'qa!'

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ use "nvim-lua/plenary.nvim"
2828

2929
## Modules
3030

31-
- `plenary.async`
32-
- `plenary.async_lib`
33-
- `plenary.job`
34-
- `plenary.path`
35-
- `plenary.scandir`
36-
- `plenary.context_manager`
37-
- `plenary.test_harness`
38-
- `plenary.filetype`
39-
- `plenary.strings`
31+
- [plenary.async](#plenaryasync)
32+
- [plenary.async_lib](#plenaryasync_lib)
33+
- [plenary.job](#plenaryjob)
34+
- [plenary.path](#plenarypath)
35+
- [plenary.scandir](#plenaryscandir)
36+
- [plenary.context_manager](#plenarycontext_manager)
37+
- [plenary.test_harness](#plenarytest_harness)
38+
- [plenary.filetype](#plenaryfiletype)
39+
- [plenary.strings](#plenarystrings)
4040

4141
### plenary.async
4242

@@ -99,7 +99,6 @@ end
9999
#### Plugins using this
100100

101101
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
102-
- [gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim)
103102
- [vgit.nvim](https://github.com/tanvirtin/vgit.nvim)
104103
- [neogit](https://github.com/TimUntersberger/neogit)
105104
- [neo-tree.nvim](https://github.com/nvim-neo-tree/neo-tree.nvim)

data/plenary/filetypes/builtin.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ return {
3636
['graphql'] = 'graphql',
3737
['hbs'] = 'handlebars',
3838
['hdbs'] = 'handlebars',
39+
['hlsl'] = 'hlsl',
40+
['jai'] = 'jai',
3941
['janet'] = 'janet',
4042
['jl'] = 'julia',
4143
['jsx'] = 'javascriptreact',

lua/plenary/async/api.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ return setmetatable({}, {
88
util.scheduler()
99
end
1010

11-
vim.api[k](...)
11+
return vim.api[k](...)
1212
end
1313
end,
1414
})

lua/plenary/async/async.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ local f = require "plenary.functional"
77
local M = {}
88

99
local function is_callable(fn)
10-
return type(fn) == "function" or type(getmetatable(fn)["__call"]) == "function"
10+
return type(fn) == "function" or (type(fn) == "table" and type(getmetatable(fn)["__call"]) == "function")
1111
end
1212

1313
---because we can't store varargs

lua/plenary/async/control.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ function Condvar:notify_all()
3232
callback()
3333
end
3434

35-
for i = 1, len do
35+
for _ = 1, len do
3636
-- table.remove will ensure that indexes are correct and make "ipairs" safe,
3737
-- which is not the case for "self.handles[i] = nil"
38-
table.remove(self.handles, i)
38+
table.remove(self.handles)
3939
end
4040
end
4141

lua/plenary/async/util.lua

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ M.sleep = a.wrap(defer_swapped, 2)
2222
M.block_on = function(async_function, timeout)
2323
async_function = M.protected(async_function)
2424

25-
local stat, ret
25+
local stat
26+
local ret = {}
2627

2728
a.run(async_function, function(stat_, ...)
2829
stat = stat_
@@ -75,14 +76,14 @@ M.join = function(async_fns)
7576
return results
7677
end
7778

78-
---Returns a future that when run will select the first async_function that finishes
79-
---@param async_funs table: The async_function that you want to select
79+
---Returns a result from the future that finishes at the first
80+
---@param async_functions table: The futures that you want to select
8081
---@return ...
81-
M.run_first = a.wrap(function(async_funs, step)
82+
M.run_first = a.wrap(function(async_functions, step)
8283
local ran = false
8384

84-
for _, future in ipairs(async_funs) do
85-
assert(type(future) == "function", "type error :: future must be function")
85+
for _, async_function in ipairs(async_functions) do
86+
assert(type(async_function) == "function", "type error :: future must be function")
8687

8788
local callback = function(...)
8889
if not ran then
@@ -91,10 +92,22 @@ M.run_first = a.wrap(function(async_funs, step)
9192
end
9293
end
9394

94-
future(callback)
95+
async_function(callback)
9596
end
9697
end, 2)
9798

99+
---Returns a result from the functions that finishes at the first
100+
---@param funcs table: The async functions that you want to select
101+
---@return ...
102+
M.race = function(funcs)
103+
local async_functions = vim.tbl_map(function(func)
104+
return function(callback)
105+
a.run(func, callback)
106+
end
107+
end, funcs)
108+
return M.run_first(async_functions)
109+
end
110+
98111
M.run_all = function(async_fns, callback)
99112
a.run(function()
100113
M.join(async_fns)

lua/plenary/busted.lua

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ local pop_description = function()
5959
end
6060

6161
local add_new_each = function()
62-
current_before_each[current_description[#current_description]] = {}
63-
current_after_each[current_description[#current_description]] = {}
62+
current_before_each[#current_description] = {}
63+
current_after_each[#current_description] = {}
6464
end
6565

6666
local clear_last_each = function()
67-
current_before_each[current_description[#current_description]] = nil
68-
current_after_each[current_description[#current_description]] = nil
67+
current_before_each[#current_description] = nil
68+
current_after_each[#current_description] = nil
6969
end
7070

7171
local call_inner = function(desc, func)
@@ -140,11 +140,11 @@ mod.inner_describe = function(desc, func)
140140
end
141141

142142
mod.before_each = function(fn)
143-
table.insert(current_before_each[current_description[#current_description]], fn)
143+
table.insert(current_before_each[#current_description], fn)
144144
end
145145

146146
mod.after_each = function(fn)
147-
table.insert(current_after_each[current_description[#current_description]], fn)
147+
table.insert(current_after_each[#current_description], fn)
148148
end
149149

150150
mod.clear = function()
@@ -161,7 +161,7 @@ local indent = function(msg, spaces)
161161
end
162162

163163
local run_each = function(tbl)
164-
for _, v in pairs(tbl) do
164+
for _, v in ipairs(tbl) do
165165
for _, w in ipairs(v) do
166166
if type(w) == "function" then
167167
w()
@@ -215,6 +215,8 @@ clear = mod.clear
215215
assert = require "luassert"
216216

217217
mod.run = function(file)
218+
file = file:gsub("\\", "/")
219+
218220
print("\n" .. HEADER)
219221
print("Testing: ", file)
220222

lua/plenary/curl.lua

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ Curl Wrapper
33
44
all curl methods accepts
55
6-
url = "The url to make the request to.", (string)
7-
query = "url query, append after the url", (table)
8-
body = "The request body" (string/filepath/table)
9-
auth = "Basic request auth, 'user:pass', or {"user", "pass"}" (string/array)
10-
form = "request form" (table)
11-
raw = "any additonal curl args, it must be an array/list." (array)
12-
dry_run = "whether to return the args to be ran through curl." (boolean)
13-
output = "where to download something." (filepath)
14-
timeout = "request timeout in mseconds" (number)
6+
url = "The url to make the request to.", (string)
7+
query = "url query, append after the url", (table)
8+
body = "The request body" (string/filepath/table)
9+
auth = "Basic request auth, 'user:pass', or {"user", "pass"}" (string/array)
10+
form = "request form" (table)
11+
raw = "any additonal curl args, it must be an array/list." (array)
12+
dry_run = "whether to return the args to be ran through curl." (boolean)
13+
output = "where to download something." (filepath)
14+
timeout = "request timeout in mseconds" (number)
15+
http_version = "HTTP version to use: 'HTTP/0.9', 'HTTP/1.0', 'HTTP/1.1', 'HTTP/2', or 'HTTP/3'" (string)
1516
1617
and returns table:
1718
@@ -179,6 +180,19 @@ parse.accept_header = function(s)
179180
return { "-H", "Accept: " .. s }
180181
end
181182

183+
parse.http_version = function(s)
184+
if not s then
185+
return
186+
end
187+
if s == "HTTP/0.9" or s == "HTTP/1.0" or s == "HTTP/1.1" or s == "HTTP/2" or s == "HTTP/3" then
188+
s = s:lower()
189+
s = s:gsub("/", "")
190+
return { "--" .. s }
191+
else
192+
error "Unknown HTTP version."
193+
end
194+
end
195+
182196
-- Parse Request -------------------------------------------
183197
------------------------------------------------------------
184198
parse.request = function(opts)
@@ -215,6 +229,7 @@ parse.request = function(opts)
215229
append(parse.form(opts.form))
216230
append(parse.file(opts.in_file))
217231
append(parse.auth(opts.auth))
232+
append(parse.http_version(opts.http_version))
218233
append(opts.raw)
219234
if opts.output then
220235
table.insert(result, { "-o", opts.output })
@@ -244,7 +259,7 @@ end
244259
local request = function(specs)
245260
local response = {}
246261
local args, opts = parse.request(vim.tbl_extend("force", {
247-
compressed = true,
262+
compressed = package.config:sub(1, 1) ~= "\\",
248263
dry_run = false,
249264
dump = util.gen_dump_path(),
250265
}, specs))

lua/plenary/fun.lua

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
local tbl = require "plenary.tbl"
2-
31
local M = {}
42

5-
function M.bind(fn, ...)
6-
if select("#", ...) == 1 then
7-
local arg = ...
8-
return function(...)
9-
fn(arg, ...)
10-
end
11-
end
12-
13-
local args = tbl.pack(...)
14-
return function(...)
15-
fn(tbl.unpack(args), ...)
16-
end
17-
end
3+
M.bind = require("plenary.functional").partial
184

195
function M.arify(fn, argc)
206
return function(...)

lua/plenary/functional.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ function f.join(array, sep)
1616
return table.concat(vim.tbl_map(tostring, array), sep)
1717
end
1818

19-
function f.partial(fun, ...)
20-
local args = { ... }
21-
return function(...)
22-
return fun(unpack(args), ...)
19+
local function bind_n(fn, n, a, ...)
20+
if n == 0 then
21+
return fn
2322
end
23+
return bind_n(function(...)
24+
return fn(a, ...)
25+
end, n - 1, ...)
26+
end
27+
28+
function f.partial(fun, ...)
29+
return bind_n(fun, select("#", ...), ...)
2430
end
2531

2632
function f.any(fun, iterable)

lua/plenary/job.lua

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ local uv = vim.loop
44
local F = require "plenary.functional"
55

66
---@class Job
7-
---@field command string : Command to run
8-
---@field args Array : List of arguments to pass
9-
---@field cwd string : Working directory for job
10-
---@field env Map|Array : Environment looking like: { ['VAR'] = 'VALUE } or { 'VAR=VALUE' }
11-
---@field skip_validation boolean : Skip validating the arguments
12-
---@field enable_handlers boolean : If set to false, disables all callbacks associated with output
13-
---@field on_start function : Run when starting job
14-
---@field on_stdout function : (error: string, data: string, self? Job)
15-
---@field on_stderr function : (error: string, data: string, self? Job)
16-
---@field on_exit function : (self, code: number, signal: number)
17-
---@field maximum_results number : stop processing results after this number
18-
---@field writer Job|table|string : Job that writes to stdin of this job.
19-
---@field detached boolean : Spawn the child in a detached state making it a process group leader
20-
---@field enabled_recording boolean
7+
---@field command string Command to run
8+
---@field args? string[] List of arguments to pass
9+
---@field cwd? string Working directory for job
10+
---@field env? table<string, string>|string[] Environment looking like: { ['VAR'] = 'VALUE' } or { 'VAR=VALUE' }
11+
---@field interactive? boolean
12+
---@field detached? boolean Spawn the child in a detached state making it a process group leader
13+
---@field skip_validation? boolean Skip validating the arguments
14+
---@field enable_handlers? boolean If set to false, disables all callbacks associated with output (default: true)
15+
---@field enabled_recording? boolean
16+
---@field on_start? fun()
17+
---@field on_stdout? fun(error: string, data: string, self?: Job)
18+
---@field on_stderr? fun(error: string, data: string, self?: Job)
19+
---@field on_exit? fun(self: Job, code: number, signal: number)
20+
---@field maximum_results? number Stop processing results after this number
21+
---@field writer? Job|table|string Job that writes to stdin of this job.
2122
local Job = {}
2223
Job.__index = Job
2324

@@ -65,7 +66,7 @@ local function expand(path)
6566
return assert(uv.fs_realpath(path), string.format("Path must be valid: %s", path))
6667
else
6768
-- TODO: Probably want to check that this is valid here... otherwise that's weird.
68-
return vim.fn.expand(vim.fn.escape(path, "$"), true)
69+
return vim.fn.expand(vim.fn.escape(path, "[]$"), true)
6970
end
7071
end
7172

lua/plenary/log.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
-- This library is free software; you can redistribute it and/or modify it
88
-- under the terms of the MIT license. See LICENSE for details.
99

10+
local Path = require "plenary.path"
11+
1012
local p_debug = vim.fn.getenv "DEBUG_PLENARY"
1113
if p_debug == vim.NIL then
1214
p_debug = false
@@ -79,7 +81,7 @@ log.new = function(config, standalone)
7981

8082
local outfile = vim.F.if_nil(
8183
config.outfile,
82-
string.format("%s/%s.log", vim.api.nvim_call_function("stdpath", { "cache" }), config.plugin)
84+
Path:new(vim.api.nvim_call_function("stdpath", { "cache" }), config.plugin .. ".log").filename
8385
)
8486

8587
local obj
@@ -159,7 +161,7 @@ log.new = function(config, standalone)
159161

160162
-- Output to log file
161163
if config.use_file then
162-
local outfile_parent_path = require("plenary.path"):new(outfile):parent()
164+
local outfile_parent_path = Path:new(outfile):parent()
163165
if not outfile_parent_path:exists() then
164166
outfile_parent_path:mkdir { parents = true }
165167
end

0 commit comments

Comments
 (0)