nvim-lua / plenary.nvim Goto Github PK
View Code? Open in Web Editor NEWplenary: full; complete; entire; absolute; unqualified. All the lua functions I don't want to write twice.
License: MIT License
plenary: full; complete; entire; absolute; unqualified. All the lua functions I don't want to write twice.
License: MIT License
Thats more of a tracking issue. I kinda wanna do it but want some opinions first.
@tami5 Curl is great but we have way too many layers:
I was thinking maybe we could just rewrite it with native c bindings (ffi) which would give us something like this:
Currently i am thinking having a curl
, curl_job
and curl_native
module. We try to load native
curl and if that isn't available then we fallback to curl_job
. curl
is basically the public interface which will handle the fallback.
So if someone says i only wanna support curl_native
he can also just call that.
We can also do some curl_extension
stuff that is not supported with curl_job
. Like providing stuff for the curl_multi
interface. See here section The multi Interface
@tjdevries "Overkill" for plenary to do something like this?
Hey, I recently created a plugin that makes use of the plenary curl wrapper and someone has raised an issue regarding JSON formatted POST requests.
After some debugging information, it was found that the problem is generated when the wrapper starts to deal with the body (if you like to take a look, see #3).
The expected result of the JSON
{
"email": "[email protected]",
"username": "foo"
}
it would be something like
curl -d '{"email": "[email protected]", "username": "foo"}'
to be treated as JSON when sending the respective headers (Content-Type: application/json
).
Instead, the body goes through a reassignment and is then passed to a function that renders it as form data as it's a table. That is, instead of the expected result given above, you receive
curl -d "[email protected]" -d "username=foo"
and that causes a Bad Request to be returned (status code 400)
Is there a way to handle the body differently if the header Content-Type: application/json
was passed to curl?
Reference lines of code:
Hi, I have tested out rest.nvim plugin for working with API calls, that is using plenary.curl as a workhorse. I have reviewed some of the source code and tests in plenary.curl and it seems to me it works only with login:password authorization via the auth element of opts table. What is the recommended way of running plenary.curl with Authorization: Bearer token header? Just as a normal header?
@tjdevries it would cool if the library has a function in readme that plugin developers can copy to add plenery as dep under lua/dep/plenary
and the same goes for popup
, as temporary work around until you finish with what you are planning todo.
It will save users from adding extra Plug statements and wave the need to update them if anything change the host.
Thanks
I am unsure about the naming though. What do you think? Is there stuff for data retrieving missing, which has no user interaction?
checklist
git branch --all
(WIP git module)git remote -v
git status -s
uses colors => instead use git --porcelain
. Only porcellain has a stability guarantee. usage.git stash list
=> would be extremely useful, if people use proper messages for stashing => 2d array of stashindex = 0..n with content x=name of branch y=short description of commitNONGOALS
I don't really know anything about busted, so obviously let me know if I'm just misunderstanding the right way to use this but if I have a test with pending
:
it('expands mid-word', function()
pending('norcalli/snippets.nvim#17')
insert('(\\a<Tab>')
assert.is.equal('(α', vim.fn.nvim_get_current_line())
feed('ggdG') -- FIXME: Start with clear buffers...
end)
because I know it fails, and then I run it, I see
Starting...Scheduling: lua/tests/unicode_spec.lua
========================================
Testing: @/Users/julian/Development/lean.nvim/lua/tests/unicode_spec.lua
Success || translations expands \-prefixed predefined substitutions on tab
Success || translations does not autoexpand
Pending || translations expands mid-word norcalli/snippets.nvim#17
Error detected while processing command line:
Fail || translations expands mid-word
.../julian/Development/lean.nvim/lua/tests/unicode_spec.lua:25: Expected objects to be equal.
Passed in:
(string) '(\a'
Expected:
(string) '(α'
stack traceback:
.../julian/Development/lean.nvim/lua/tests/unicode_spec.lua:25: in function <.../julian/Development/lean.nvim/lua/tests/unicode_spec.lua:21>
Success: 2
Failed : 1
Errors : 0
========================================
Tests Failed. Exit: 1
where the test I marked pending has failed the build. I see busted has a --suppress-pending
, so if that's what's needed to get this not to fail maybe there just needs to be a way to enable that in plenary too, but why it's not the default seems weird to me. Maybe you'll enlighten me there :)
(Also it took a few minutes of looking for either "expected failure" or "todo" which are xUnit terms to finally find pending
, but I see busted's docs don't use those terms anywhere)
I am trying to run a job and analyze the return code to decide what to do. When I put a print()
call in the on_exit
callback, I see it prints twice and looks like different arguments are being supplied each time. Sometimes I get the code but other times I don't. Is this intended?
Example fn:
function job_test()
local Job = require'plenary.job'
local job = Job:new{
command = "ls",
on_exit = function(...)
print(...)
end,
}
job:start()
job:shutdown()
end
It outputs:
table: 0x420071d0 nil nil
nil
If I had to guess, I'd say it's being called with self
one of the times, but not the other.
It happens because uv.fs_scandir
calls callback on directories in the input path and the first of those callbacks
can call on_exit, even though more directories remain to be processed.
Consider using uv.fs_readdir
instead.
Logs:
Fetching LuaJIT 2.1.0-beta3 (cached)
Verifying SHA256 checksum
Building LuaJIT 2.1.0-beta3
Running make
==== Building LuaJIT 2.1.0-beta3 ====
/Library/Developer/CommandLineTools/usr/bin/make -C src
HOSTCC host/minilua.o
HOSTLINK host/minilua
DYNASM host/buildvm_arch.h
HOSTCC host/buildvm.o
HOSTCC host/buildvm_asm.o
HOSTCC host/buildvm_peobj.o
HOSTCC host/buildvm_lib.o
HOSTCC host/buildvm_fold.o
HOSTLINK host/buildvm
BUILDVM lj_vm.S
ASM lj_vm.o
CC lj_gc.o
BUILDVM lj_ffdef.h
CC lj_err.o
CC lj_char.o
BUILDVM lj_bcdef.h
CC lj_bc.o
CC lj_obj.o
CC lj_buf.o
CC lj_str.o
CC lj_tab.o
CC lj_func.o
CC lj_udata.o
CC lj_meta.o
CC lj_debug.o
CC lj_state.o
CC lj_dispatch.o
CC lj_vmevent.o
CC lj_vmmath.o
CC lj_strscan.o
CC lj_strfmt.o
CC lj_strfmt_num.o
CC lj_api.o
CC lj_profile.o
CC lj_lex.o
CC lj_parse.o
CC lj_bcread.o
CC lj_bcwrite.o
CC lj_load.o
CC lj_ir.o
CC lj_opt_mem.o
BUILDVM lj_folddef.h
CC lj_opt_fold.o
CC lj_opt_narrow.o
CC lj_opt_dce.o
CC lj_opt_loop.o
CC lj_opt_split.o
CC lj_opt_sink.o
CC lj_mcode.o
CC lj_snap.o
CC lj_record.o
CC lj_crecord.o
BUILDVM lj_recdef.h
CC lj_ffrecord.o
CC lj_asm.o
CC lj_trace.o
CC lj_gdbjit.o
CC lj_ctype.o
CC lj_cdata.o
CC lj_cconv.o
CC lj_ccall.o
CC lj_ccallback.o
CC lj_carith.o
CC lj_clib.o
CC lj_cparse.o
CC lj_lib.o
CC lj_alloc.o
CC lib_aux.o
BUILDVM lj_libdef.h
CC lib_base.o
CC lib_math.o
CC lib_bit.o
CC lib_string.o
CC lib_table.o
CC lib_io.o
CC lib_os.o
CC lib_package.o
CC lib_debug.o
CC lib_jit.o
CC lib_ffi.o
CC lib_init.o
AR libluajit.a
CC luajit.o
BUILDVM jit/vmdef.lua
DYNLINK libluajit.so
LINK luajit
Undefined symbols for architecture x86_64:
"__Unwind_DeleteException", referenced from:
_lj_err_unwind_dwarf in libluajit.a(lj_err.o)
"__Unwind_GetCFA", referenced from:
_lj_err_unwind_dwarf in libluajit.a(lj_err.o)
"__Unwind_RaiseException", referenced from:
_lj_err_throw in libluajit.a(lj_err.o)
"__Unwind_SetGR", referenced from:
_lj_err_unwind_dwarf in libluajit.a(lj_err.o)
"__Unwind_SetIP", referenced from:
_lj_err_unwind_dwarf in libluajit.a(lj_err.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [luajit] Error 1
make: *** [default] Error 2
Error: got exitcode 2 from command make
[Process exited 1]
Neovim version:
NVIM v0.5.0-589-g91572ddad
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: /Applications/Xcode-10.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/Users/travis/build/neovim/bot-ci/build/neovim/build/config -I/Users/travis/build/neovim/bot-ci/build/neovim/src -I/Users/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/usr/local/opt/gettext/include -I/Users/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/Users/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by [email protected]
Features: +acl +iconv +tui
See ":help feature-compile"
system vimrc file: "$VIM/sysinit.vim"
fall-back for $VIM: "/share/nvim"
Run :checkhealth for more info
Proposed solution:
set environment MACOSX_DEPLOYMENT_TARGET to 10.15
Use something like this and guess the filetype from the buffer name.
Sorry, this is really petty, but going to ask anyways :)
I don't suppose there's an existing way to swap which argument in plenary
's test framework is considered "got" and which is "expected"?
I.e. assert.is.equal(2, 3)
currently assumes 2
is expected
. Obviously this matters only for the error messages it looks like are printed.
Both conventions are common I think -- got, expected
and expected, got
, but yeah can this be swapped or not currently (or ever?)?
I'd like to use the root_pattern function in telescope and don't want to rely on the user having lspconfig.
As plenary is a requirement for Telescope and it is meant to provide lua utils it seems like a good fit.
There may be other functions from lspconfig.util that would fit with plenary.
I have some code that uses vim.fn
and I wanted to write some tests for it.
I followed mocking example to try to mock vim.fn calls, but no luck. On other side, vim.api
can be properly mocked if instead of vim.fn
I use vim.api.nvim_call_function
. Example:
local mock = require('luassert.mock')
local function change_line(content)
return vim.fn.setline('.', content)
end
local function change_line_api(content)
return vim.api.nvim_call_function('setline', { '.', content })
end
describe('plenary', function()
it('fails to mock vim.fn', function()
local fn = mock(vim.fn, true)
fn.setline.returns('ok')
local result = change_line('Some content')
assert.are.same('ok', result)
assert.stub(fn.setline).was_called_with('.', 'Some content')
mock.revert(fn)
end)
it('mocks when used as vim.api.nvim_call_function', function()
local api = mock(vim.api, true)
api.nvim_call_function.returns('ok')
local result = change_line_api('Some content')
assert.are.same('ok', result)
assert.stub(api.nvim_call_function).was_called_with('setline', {'.', 'Some content'})
mock.revert(api)
end)
end)
I noticed that vim.fn
has an __index
magic method, but I have no idea what it's doing.
Is there a way to mock vim.fn
?
if you have the following paths
then you call make_relative("/home/user/repo") will return "-feat" since it just does a sub
@tami5 s wish :)
For
Fail || depm.use installs and setup filetypes plugins
/home/tamibam/repos/depm.nvim/tests/auto/depm_spec.lua:65: should have add a Filetype autocmd.
Expected objects to be the same.
Passed in:
(boolean) false
Expected:
(boolean) true
stack traceback:
/home/tamibam/repos/depm.nvim/tests/auto/depm_spec.lua:65: in function 'test'
/home/tamibam/repos/depm.nvim/tests/auto/depm_spec.lua:29: in function </home/tamibam/repos/depm.nvim/tests/auto/depm_spec.lua:24>
To
Fail || depm.use installs and setup filetypes plugin `/.../auto/depm_spec.lua:65:`
Case: should have add a Filetype autocmd.
Passed in: (boolean) false
Expected: (boolean) true
Stack Traceback:
/home/tamibam/repos/depm.nvim/tests/auto/depm_spec.lua:65: in function 'test'
/home/tamibam/repos/depm.nvim/tests/auto/depm_spec.lua:29: in function </home/tamibam/repos/depm.nvim/tests/auto/depm_spec.lua:
Changes are:
luassert
which we bundle so we can do it but i am not so sure if we should do that :)Passed in
and Expected
output on one line. Requires changes in luassert
Thats a somewhat good issue for newcommers :)
Due to how unpack
(actually, the #
operator) works, passing nil
as an argument to an async-function will also omit all further arguments from the call.
Minimal reproduction of the problem:
local a = require 'plenary.async_lib'
local async, await, run = a.async, a.await, a.run
local func_one = async(function (a, b, c)
print(a, b, c) -- will print "a nil nil" instead of "a nil c"
end)
local func_two = async(function ()
await(func_one('a', nil, 'c'))
end)
run(func_two())
This problem is fixed in lua 5.4 with a new pack method, which simply appends an n
field holding the true length of the table and can easily be backported as
function pack (...)
return {n=select('#',...); ...}
end
An equivalent unpack that takes the stored length into account would then look like this:
function save_unpack(t, i, j)
return unpack(t, i or 1, j or t.n or #t)
end
Maybe I'm not understanding the concept of Job
or shutdown
, but I expect the started process to finish when I shutdown the job with the shutdown
function (or at least send the signal given as parameter), but it's not doing either for some processes.
I have set up a simple configuration to reproduce this issue
config.lua
--- use your own way to load plugins
vim.fn['plug#begin']('~/.vim/plugged')
vim.fn["plug#"]('nvim-lua/plenary.nvim')
vim.fn['plug#end']()
--- @type Job
local Job = require("plenary.job")
MyJob = Job:new({
command = "mycommand.sh",
on_exit = vim.schedule_wrap(function(self, code, signal)
print(string.format("PID: %d | code: %d | signal: %d", self.pid, code, signal))
end),
})
MyJob:start()
neovim -u config.lua
:lua print(MyJob.pid)
sudo strace -p <pid>
where is the pid obtained in the previous step.:lua MyJob:shutdown(0, 3)
. I expect the process to receive a SIGQUIT(3) signal but nothing appears in the strace
output. It doesn't matter if you run shutdown
without arguments or with another signals, still no output in strace
. However, shutdown
executes on_exit
correctly and prints the following PID: <pid> | code: 0 | signal: 3
.strace
should output something when it receives a signal, run kill -n 3 <pid>
:lua vim.loop.kill(MyJob.pid, 3)
Am I doing something wrong? What should I use in order to stop the process instead?
Just for some context, this is where I'm trying to use it, right now using vim.loop.kill
as a workaround (in that code I'm killing a process started by the job instead), but I'm expecting the following to work
function M.stop()
if job then
job:shutdown() -- or maybe use a signal to terminate the process
end
I'm getting the following behaviour instead: (almost a copy of this comment in a PR for flutter-tools.nvim
Execute a command to start the job: (The first one is the job, second one the child process)
Both processes are in the process tree, bash
and dart
(the parent of zsh
is my terminal)
Executing the stop lua function inside neovim executes the on_exit
function, but the processes are still there (both of them actually, same tree)
After exiting the processes, instead of terminating, are detached and moved to the root (systemd
):
I think the setup instructions for test_harness
need a bit more information.
I have installed plenary via vim-plug, then included the following in my config:
-- Installs neorocks if necessary and then installs the package you need.
-- Is not synchronous, so should be called from Neovim's command line most likely.
neorocks.install('penlight', 'pl')
-- ensure_installed(package_name, lua_name, headless)
-- Only installs if currently not installed.
--
-- package_name : str - Name of the package for luarocks
-- lua_name : (optional) str - Name of the package that you can require. Used to determine if we have it installed already (not from luarocks)
neorocks.ensure_installed('penlight', 'pl')
neorocks.ensure_installed('lua-cjson', 'cjson')
If I try to source it, I get the "Neorocks is not yet set up" error.
If I try to run my tests as described (with the additional require in the test), I get the same "Neorocks not set up error"
inspecting the code, it's looking for a dir, which isn't created, because Neorocks isn't setup (obviously).
But I have no idea how I'm supposed to manually set it up. I tried neorocks.install('neorocks', '..????') but that didn't work (because neorocks isnt a luarocks package). I see its got a setup hererocks, but that's something sort of different.
I feel like there's just some step missing, like Plug 'nvim-lua/plenary.vim' after: 'magic_command_to_fix_my_life'
or something?
I have tried to run some plenary.curl dependent plugin on Windows (with curl) but it fails on the very early stage, I think because of this line where it creates a tmp file in the hardcoded /tmp/ folder that is not acceptable path in Windows. Here is a reproducible example:
local curl = require('plenary.curl')
curl.request{
url = "https://postman-echo.com/get",
method = "get",
accept = "application/json"
}
It throws the following error in my nvim (NVIM v0.5.0-dev+1423-ge2d3ad7bc):
E5113: Error while calling lua chunk: ...Data\Local\nvim\plugged\plenary.nvim\lua\plenary\job.lua:495: 'curl -sSL -D /tmp/plenary_curl_b69140fb.headers --compressed -X GET -H Accept: application/json https://postman-echo.com/get' wa
s unable to complete in 10000 ms
Error executing luv callback:
...ata\Local\nvim\plugged\plenary.nvim\lua\plenary\path.lua:571: ENOENT: no such file or directory: /tmp/plenary_curl_b69140fb.headers
It works on wsl.
Hey @tjdevries awesome work. I like the new commands very useful.
For now PlenaryBustedDirectory to a file works okay and opens popup.
After playing around with the new job weappers (thanks conni <3) in building update module in my next package manager, I felt that the current api implementation might a bit robust and can be simplified a bit, idk perhaps, using dict to configure bulk jobs then run it is better.
Here I'm suggesting to create an api that enable users to define bulk jobs configuration then call service:start()
or service:bulk_start()
.
Below is two code snippet one using the current api, and the other is an example of what I mean above.
local post = function(stage)
return vim.schedule_wrap(function (j, c)
if c == 0 then
return dtask:close(update_repo_msgs[stage].succ, concat(j:result(), "\n"), true)
else
return dtask:close(update_repo_msgs[stage].error, concat(j:stderr_result(), "\n"), false)
end
end)
end
local close_fn = vim.schedule_wrap(function(j, c)
if c == 0 then
return dtask:update(update_repo_msgs['fetch'].succ, concat(j:result(), "\n"), true)
else
return dtask:close(update_repo_msgs['fetch'].error, concat(j:stderr_result(), "\n"), false)
end
end)
local update_repo_service = function(spec, dtask)
local fetch, check, merge, rebase, stash, unstash = gen_update_jobs(spec.path)
local can_rebase = cfg.rebase_on_update
local can_stash = cfg.stash_on_update
dtask:start("Checking for updates ...")
fetch:after(close_fn)
fetch:and_then_on_success(check)
check:after_success(vim.schedule_wrap(function(j)
local ahead, behind, in_sync, unstaged_changes = get_repo_status(j:result())
if in_sync then
dtask:close(update_repo_msgs["in_sync"].succ, nil, true)
elseif unstaged_changes and ahead and can_stash then
check:and_then_on_success(stash)
stash:after_success(vim.schedule_wrap(function()
dtask:update(update_repo_msgs["stash"].enter)
dtask:update(update_repo_msgs['rebase']['info'])
end))
stash:and_then_on_success(rebase)
rebase:after(post'rebase')
rebase:and_then(unstash)
elseif unstaged_changes and behind and can_stash then
check:and_then(stash)
stash:and_then_on_success(merge)
stash:after_success(vim.schedule_wrap(function()
dtask:update(update_repo_msgs["stash"].leave)
dtask:update(update_repo_msgs['merge']['info'])
return
end))
merge:after(post'merge')
merge:and_then(unstash)
elseif behind and not ahead then
check:and_then(merge)
check:after_success(vim.schedule_wrap(function()
return dtask:update(update_repo_msgs['merge']['info'])
end))
merge:after(post'merge')
elseif behind or ahead then
if can_rebase and ahead then
check:and_then(rebase)
check:after_success(vim.schedule_wrap(function()
return dtask:update(update_repo_msgs['rebase']['info'])
end))
rebase:after(post'rebase')
else
dtask:close(update_repo_msgs["conflict"].error, nil, false)
end
end
end))
dtask:start(update_repo_msgs['fetch']['info'])
fetch:start()
end
Becomes this
local update_repo_service = function(spec, dtask)
local switch = vim.schedule_wrap(function(j)
local ahead, behind, in_sync, unstaged_changes = get_repo_status(j:result())
local one = unstaged_changes and ahead and can_stash
local two = unstaged_changes and behind and can_stash
local three = behind and not ahead
local four = can_rebase and ahead
if in_sync then dtask:close(update_repo_msgs["in_sync"].succ, nil, true)
elseif one then j:attach_case(1)
elseif two then j:attach_case(2)
elseif three then j.jobs["merge"]:attach()
elseif four then j.jobs["rebase"]:attach()
else dtask:close(update_repo_msgs["conflict"].error, nil, false)
end
end)-- maybe switcher api
return Job:new_bulk {
jobs = {"main", "check", "merge", "rebase", "stash", "unstash"}, -- maybe better inferred from first level keys
cases = {
[1] = function(jobs) jobs["stash"]:attach(1) end,
[2] = function(jobs) jobs["stash"]:attach(2) end
}
main = {
command = "git",
args = {'fetch', '--depth=999999', '--progress'},
cwd = spec.path,
before = vim.schedule_wrap(function(_) return dtask:update(update_repo_msgs['main']['info']) end),
after = close_fn,
after_succ = vim.schedule_wrap(function(j) end),
after_failure = vim.schedule_wrap(function(j) end),
on_finish = "",
on_succ = "check",
on_failure = "another_job_name defined in opts.job"
},
check = { command = "git", args = {"status", "-sb"}, cwd = spec.path, after_succ = switch },
stash = {
command = "git",
args = {"stash"},
cwd = spec.path,
cases = {
[1] = function(j) return jobs["rebase"]:attach(1) end,
[2] = function(j) return jobs["merge"]:attach(1) end
},
before = vim.schedule_wrap(function()
dtask:update(update_repo_msgs["stash"].enter)
end),
-- or -----------------------------------
after_succ = {
[1] = function(j) jobs["rebase"]:attach(1) end
[2] = function(j) jobs["merge"]:attach(1) end
}
},
merge = {
command = "git",
args = {"merge"},
cwd = spec.path
before = vim.schedule_wrap(function()
return dtask:update(update_repo_msgs['merge']['info'])
end)
after = post'merge'
on_finish = function(jobs)
if jobs["stash"].started then
return "unstash",
else
end
end
},
rebase = {
command = "git",
args = {'rebase', '--verbose' },
cwd = spec.path,
before = vim.schedule_wrap(function()
dtask:update(update_repo_msgs['rebase']['info'])
end),
after = post'rebase',
on_finish = function(jobs)
if jobs["stash"].started then
return "unstash",
else
end
end
},
unstash = {}
}
end
Steps to reproduce
local Job = require'plenary.job'
Job:new({
command = 'rg',
args = { '--files', '.' },
on_exit = function(j, return_val)
print(return_val)
print(j:result())
end,
}):sync()
Will crash neovim-qt and plain nvim. Tested on g7bf62ab02.
Neovim use it and a lot of plugins like lsp-config or packer.nvim use it too now, it would make sense to put the log here too.
I'd like to have telescope.log
with the others files and if I'm not wrong, the change need to be here and not in telescope repo
I can make a PR if needed
The problematic line:
plenary.nvim/lua/plenary/neorocks.lua
Line 223 in 1e58553
Proposed solution:
...
local user_shell = os.getenv("SHELL")
local shell = user_shell:gmatch("([^/]*)$")()
if shell == "fish" then
return string.format('source %s', install_location:joinpath('bin', 'activate.fish'):absolute())
...
No description provided.
Should never use buf
and win
. Should be specific and follow normal naming conventions:
bufnr
-> buffer number
win_id
-> window id
It would be cool if the user can have more control over the float windows, such as passing window options to be executed, set border and border buffer colors .. etc.
For example:
local set_buf_opts = function(bufnr, buf_opts)
for k, v in pairs(vim.tbl_extend("keep", buf_opts, { -- defaults
bufhidden = "wipe",
buflisted = false,
swapfile = false,
buftype = "nofile"
})) do vim.api.nvim_buf_set_option(bufnr, k, v) end
end
local set_win_opts = function(win_id, win_opts)
for k, v in pairs(vim.tbl_extend("keep", win_opts, { -- defaults
signcolumn = 'no',
foldenable = false,
list = false,
wrap = false,
spell = false,
number = false,
relativenumber = false,
winhl = "NormalFloat:Normal"
})) do vim.api.nvim_win_set_option(win_id, k, v) end
end
Any chance to get some http helper in here? I don't know if there is any cross platform plugin for lua that handles this. I don't even know if we care about Windows support here :D.
I found this as a wrapper around curl, but I don't know if there's maybe a better solution
After todays update, I get the following error:
E5108 Error executing lua ... /packer/start/plenary.nvim/lua/plenary/scandir.lua:243: attempt to redefine 'passwd' at line 6
It looks like 243 is right in the middle of the latest commit and there's no error when I roll back to the previous commit. It only occurs when I try to use telescope, but it happens every time for every function and categorically prevents me from looking at planets.
I'm happy to provide whatever details you like but I imagine the usual minimal vimrc etc. isn't going to help much for an os dependent function if the problem is with my setup... so you'll have to help me help you to help me and lmk what relevant details are useful.
Telescope (plenary) seems broken on latest neovim (6dd04ed5f)?
lua require('telescope.builtin').git_files()
Results in:
Error detected while processing command line:
E5108: Error executing lua ...ck/bundle/opt/plenary.nvim/lua/plenary
/window/border.lua:138: Vim(autocmd):E680: <buffer=13>: invalid buffer number
After a git bisect:
1def3d1542d6a65f057e743faea39a760b50db87 is the first bad commit
commit 1def3d1542d6a65f057e743faea39a760b50db87
Author: jing <[email protected]>
Date: Sat Jan 9 13:15:23 2021 +0800
api/window: use the "noblock" variants in nvim_win_set_buf
after commit 92c6383cdca977("vim-patch:8.1.1425: win_execute() does not set window pointers properly"),
nvim_win_set_buf can use switch_win_noblock and restore_win_noblock.
It makes nvim_win_set_buf don't block autocmds so that it will be more
"without side-effects" as said in help text.
Signed-off-by: jing <[email protected]>
src/nvim/api/window.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Link to commit can be found here: neovim/neovim@1def3d1
Hey, I've had to clone the repository again, and have found that it's a bit heavy (~12MB) even to download and can cause it to fail on slow connections with the default packer settings (60s timeout).
After doing a little search I have found that it's a nvim.appimage.1
file that doesn't exist and that it's stored in the .pack
file.
Here are the steps I took and how to reduce the repository size locally by up to 90% (1.2MB), all steps must be done from the repository root:
git verify-pack -v .git/objects/pack/pack-26ca0b79e92d096b8ce4eb32e16238ca74461801.idx \
| sort -k 3 -n \
| tail -10
943f15
):git rev-list --objects --all | grep 'first few chars of the sha1 from previous output'
git filter-branch --index-filter 'git rm --cached --ignore-unmatch nvim.appimage.1' -- --all
rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc --aggressive --prune=now
size-pack
, should be a lot smaller now:git count-objects -v
Adding a simple environment variable to a plenary job makes it fail.
For example, this PR adds a single variable to a job and makes it throw the following error
```
packer.nvim: Error running config for octo.nvim: .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:400: Failed to spawn process: {
_additional_on_exit_callbacks = {},
_shutdown_check = <userdata 1>,
_stderr_results = {},
_stdout_results = {},
_user_on_exit = <function 1>,
args = { "auth", "status" },
command = "gh",
enable_handlers = true,
enable_recording = true,
env = { "NO_COLOR=1" },
interactive = true,
pid = "ENOENT: no such file or directory",
stderr = <userdata 2>,
stdin = <userdata 3>,
stdout = <userdata 4>,
user_data = {},
= <1>{
__index = <table 1>,
_create_uv_options = <function 2>,
_execute = <function 3>,
_pipes_are_closed = <function 4>,
_prepare_pipes = <function 5>,
_reset = <function 6>,
_shutdown = <function 7>,
_stop = <function 8>,
add_on_exit_callback = <function 9>,
after = <function 10>,
after_failure = <function 11>,
after_success = <function 12>,
and_then = <function 13>,
and_then_on_failure = <function 14>,
and_then_on_failure_wrap = <function 15>,
and_then_on_success = <function 16>,
and_then_on_success_wrap = <function 17>,
and_then_wrap = <function 18>,
chain = <function 19>,
chain_status = <function 20>,
co_wait = <function 21>,
is_job = <function 22>,
join = <function 23>,
new = <function 24>,
pid = <function 25>,
result = <function 26>,
send = <function 27>,
shutdown = <function 28>,
start = <function 29>,
stderr_result = <function 30>,
sync = <function 31>,
wait = <function 32>
}
}
stack traceback:
^I.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:400: in function '_execute'
^I.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:443: in function 'start'
^I.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:447: in function 'sync'
^I...re/nvim/site/pack/packer/start/octo.nvim/lua/octo/gh.lua:51: in function 'run'
^I...share/nvim/site/pack/packer/start/octo.nvim/lua/octo.lua:268: in function 'check_login'
^I...share/nvim/site/pack/packer/start/octo.nvim/lua/octo.lua:27: in function 'setup'
^I[string "..."]: in function <[string "..."]:0>
^I[C]: in function 'pcall'
^I/Users/pwntester/.config/nvim/plugin/packer_compiled.lua:60: in function 'try_loadstring'
^I/Users/pwntester/.config/nvim/plugin/packer_compiled.lua:425: in function </Users/pwntester/.config/nvim/plugin/packer_compiled.lua:10>
^I[C]: in function 'pcall'
For example:
**/bin
!bin/asdf
both currently will result in unexpected behavior
i want to use plenary to do some unit test but i got a some issue with automatic feedkeys function.
describe('pair input test ', function()
it("test case 1",function()
local line=1
local pos =4;
vim.fn.setline(line , before)
vim.fn.setpos('.' ,{0 , line , pos , 0})
vim.fn.feedkeys("i(")
vim.fn.feedkeys("<ESC>")
vim.wait(5,function()
local result = vim.fn.getline(line)
-- text result still no change ?
print('result'..vim.inspect(result))
local pos = vim.fn.getpos('.')
return true
end)
end)
end)
how do i test the text result after i use feedkeys function?
Thank
@delphinus i wrote you in gitter private but you haven't answered so i might try this way.
I wanna move your truncate code from telescope into plenary so we can use it to truncate border titles. See nvim-telescope/telescope.nvim#528 (comment)
I just wanted to ask if you want to do it because you wrote most of that amazing code. :)
I would remove the code in telescope afterwards, in the #528 PR
Only one root describe
works because describe runs everything inside and then if a test failed does os.exit(1)
or os.exit(0)
.
search_pattern
opt captures unexpected results. Search pattern doesn't only apply to the last part but to the whole path.
e.g. search_pattern: filetype
captures data/plenary/filetypes/base.lua
which it shouldn't
The recommended way plenary has for running tests (e.g. nvim --headless --noplugin -u scripts/minimal_init.vim -c "PlenaryBustedDirectory lua/tests/ { minimal_init = './scripts/minimal_init.vim' }"
) makes it easy I think to run into neovim/neovim#12432 or neovim/neovim#11362 (which I ran into randomly just now after having used plenary for a day or two).
The fix in one of those two issues (to add set display=lastline
) helped stop the segfaulting and showed me my real error, but might be good to add a recommendation to include that in minimal vimrcs to the docs.
It'd be nice to have a way with plenary's busted support to specify dependencies that test cases have on active plugins.
E.g., imagine a spec file for a function foo
which does different things if the user has installed a dependency bar
or another dependency baz
-- then it'd be nice to have syntax or arguments or etc. which properly manage runtimepath
and clearing enough state (or running in enough isolation) such that tests which want to run with bar
loaded get that, and tests which want to run with baz
loaded get that.
I don't 100% know what a solution to this looks like (though I suppose I'll know that in a few hours after implementing one in a bespoke way for my plugin), but it seems possibly like a thing that'd be more widely useful.
#54 may be related here in a distant way.
The following code outputs nothing, as if I hadn't called job:start()
at all, which shouldn't be happening unless I'm missing something:
local Job = require('plenary.job')
local job = Job:new {
command = 'fzf';
-- Still doesn't work if you don't pass these args and just run `fzf`
args = {'--no-sort', '--filter', 'thing'};
on_stderr = print;
on_stdout = function(...)
print(vim.inspect(...))
end;
on_exit = function()
print('exit')
end;
}
job:start()
-- Blocks forever (at least for a really long time) if you call `job:sync()` instead
Now would be a great time to start a discussion on what people require in a standard lib and what's already out there.
The topic is quite closely related to standardising plugins themselves, and @norcalli has some work that would make a great starting point for that facet of the discussion.
To my knowledge, vital is the only vim standard-lib that gained any traction previously. It's quite mature and it's feature list would make a good checklist for what's needed or already provisioned for via lua, libuv or plenary.
I've already seen a few variations of wrapper functions for file reading/writing, http/socket request, etc - and reimplementation of things that plenary provides for windows. Consideration of what could/should be placed in core could also take place here.
Thoughts?
The way failed tests are notified makes it hard to load them into quickfixlist.
I use vim-dispatch to run tests, which runs a makefile and loads output to quickfixlist. The problem is that Plenary seems to prepend 3 dots (...
) to long paths creating a non-valid path for quickfixlist to follow.
As you can see in the following quickfixlist, it's filled with invalid paths and noise
|| ========================================
|| Testing: /home/eruizc/repos/eruizc-dev/rubberduck-nvim/lua/spec/rubberduck/utils/file_spec.lua
|| �[31mFail�[0m || file read returns file contents
.../rubberduck-nvim/lua/spec/rubberduck/utils/file_spec.lua|23| Expected objects to be equal.
|| Passed in:
|| (string) 'adsf'
|| Expected:
|| (string) ''
||
|| stack traceback:
.../rubberduck-nvim/lua/spec/rubberduck/utils/file_spec.lua|23| in function <.../rubberduck-nvim/lua/spec/rubberduck/utils/file_spec.lua:18>
||
|| �[32mSuccess�[0m || file read excepts on unexisting file
|| �[32mSuccess�[0m || file read excepts on unreadable file
|| �[32mSuccess�[0m || file read reads correctly when content is empty
|| �[32mSuccess�[0m || file read reads correctly when content is 'nil'
|| �[32mSuccess�[0m || file read reads correctly when content is 'null'
|| �[32mSuccess�[0m || file read reads correctly when content is '0'
||
|| �[32mSuccess: �[0m 6
|| �[31mFailed : �[0m 1
|| �[31mErrors : �[0m 0
|| ========================================
|| Tests Failed. Exit: 1
test:
nvim --headless -c "PlenaryBustedDirectory ."
It may be related to issue #73, but one is for human readability and this one is for parsing
:Make
command:copen
One useful addition to a nvim-lua standard library would be a profiler (since the vim prof func *
can't trace into lua). I've played a bit with the debug.sethook
based approach, either using https://stackoverflow.com/questions/15725744/easy-lua-profiling or https://github.com/charlesmallah/lua-profiler.
Both kinda work, but it'd be nice to have something more nvim-aware (and prettier) :)
Also, expand works without needing to create new object like Path:expand(Path:new(path))
> Path:expand(path)
or path.expand(path)
For example, one would expect running require'plenary.filetype'.detect('example.rst.txt')
to return rst
. Instead, it returns text
.
This is mainly problematic since some of the extensions in data/plenary/filetypes/base.lua
are supposed to match extension with a .
in them.
The emacs.desktop
, rest.txt
, rst.txt
, yaml.sed
, and yml.mysql
all return the wrong filetype.
The app.src
, cmake.in
, desktop.in
, dll.config
, haml.deface
, html.hl
, model.lkml
, rs.in
, sh.in
, tfstate.backup
, view.lkml
, xml.dist
, and xsp.metadata
all erroneously return no filetype.
local Job = require('plenary.job');
local _, code = Job:new({
command = 'gcloud',
env = vim.env,
}):sync()
if code ~= 0 then
error(string.format('failed to call (%d)', code))
end
It works on Arch, but does NOT work on macOS:
E5113: Error while calling lua chunk: .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:399: Failed to spawn process: {
_additional_on_exit_callbacks = {},
_shutdown_check = <userdata 1>,
_stderr_results = {},
_stdout_results = {},
command = "gcloud",
enable_handlers = true,
enable_recording = true,
env = {},
interactive = true,
pid = "ENOENT: no such file or directory",
stderr = <userdata 2>,
stdin = <userdata 3>,
stdout = <userdata 4>,
user_data = {},
<metatable> = <1>{
__index = <table 1>,
_create_uv_options = <function 1>,
_execute = <function 2>,
_pipes_are_closed = <function 3>,
_prepare_pipes = <function 4>,
_reset = <function 5>,
_shutdown = <function 6>,
_stop = <function 7>,
add_on_exit_callback = <function 8>,
after = <function 9>,
after_failure = <function 10>,
after_success = <function 11>,
and_then = <function 12>,
and_then_on_failure = <function 13>,
and_then_on_failure_wrap = <function 14>,
and_then_on_success = <function 15>,
and_then_on_success_wrap = <function 16>,
and_then_wrap = <function 17>,
chain = <function 18>,
chain_status = <function 19>,
co_wait = <function 20>,
is_job = <function 21>,
join = <function 22>,
new = <function 23>,
pid = <function 24>,
result = <function 25>,
send = <function 26>,
shutdown = <function 27>,
start = <function 28>,
stderr_result = <function 29>,
sync = <function 30>,
wait = <function 31>
}
}
stack traceback:
.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:399: in function '_execute'
.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:442: in function 'start'
.../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:446: in function 'sync'
foo.lua:6: in main chunk
gcloud is installed.
$ which gcloud
/usr/local/bin/gcloud
$ ls -la `which gcloud`
lrwxr-xr-x 1 yamada admin 71 3 25 2020 /usr/local/bin/gcloud -> /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/bin/gcloud
$ gcloud --version
Google Cloud SDK 286.0.0
bq 2.0.55
core 2020.03.24
gsutil 4.48
Updates are available for some Cloud SDK components. To install them,
please run:
$ gcloud components update%
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.