Code Monkey home page Code Monkey logo

plenary.nvim's People

Contributors

akinsho avatar alejandrosuero avatar anott03 avatar chipsenkbeil avatar ckipp01 avatar conni2461 avatar delphinus avatar fdschmidt93 avatar filipdutescu avatar ipod825 avatar jamestrew avatar joakker avatar kkharji avatar l-kershaw avatar lewis6991 avatar linguini1 avatar matu3ba avatar meinside avatar mfussenegger avatar mnowotnik avatar mrcjkb avatar oberblastmeister avatar rianfuro avatar smolck avatar sunpodder avatar teto avatar theprimeagen avatar tjdevries avatar tris203 avatar williamboman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plenary.nvim's Issues

Feature: add lspconfig.util.root_pattern to plenary.path

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.

Wrong treatment of JSON body in curl wrapper

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:

Http helper

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

scandir.scan_dir_async is calling on_exit prematurely

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.

nvim --headless segfaults if you poke it

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.

Plenary.job:shutdown(code, signal) not terminating process

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

  1. Create the following file, 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()
  1. Start neovim with neovim -u config.lua
  2. Get the process PID with :lua print(MyJob.pid)
  3. Watch the process system calls with sudo strace -p <pid> where is the pid obtained in the previous step.
  4. Shutdown the process in neovim with :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.
  5. To verify that strace should output something when it receives a signal, run kill -n 3 <pid>
    image
    Alternatively, you could also use :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)
image

Both processes are in the process tree, bash and dart (the parent of zsh is my terminal)
image

Executing the stop lua function inside neovim executes the on_exit function, but the processes are still there (both of them actually, same tree)
image

After exiting the processes, instead of terminating, are detached and moved to the root (systemd):
image

plenary.curl - Authorization: Bearer token possible?

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?

Job: user `on_exit` callback is called twice

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.

"Neo rocks is not set up yet"

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?

plenary.job doesn't work with fzf

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

Plenary.job failed to call 'gcloud' on macOS Big Sur

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%

Plenary job fails with environment variables

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'

plenary.busted more compact output

@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:

  • Normalize path an put on the same line.
  • Print case if case is there requires changes in luassert which we bundle so we can do it but i am not so sure if we should do that :)
  • Put the Passed in and Expected output on one line. Requires changes in luassert

Thats a somewhat good issue for newcommers :)

how to use plenary to unit test

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

Issues with recent updates

Hey @tjdevries awesome work. I like the new commands very useful.

  • PlenaryBustedFile tests/plenary/curl_spec.lua exit neovim but ran tests okay
  • PlenaryBustedDirectory tests/plenary unlike the above, opens popup but has escape codes all over. that I'm sure requires external plugin in order to fix that, but that is annoying extra work for the user. Also it doesn't auto scroll when new results get printed.

For now PlenaryBustedDirectory to a file works okay and opens popup.

support changing border and other options

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

Broken on latest neovim?

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

Standard Lib, Core functionality and Plugin Standardisation

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?

native curl > plenary job curl

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:

  • lua -> plenary job -> uv.spawn -> cli interface -> c -> profit

I was thinking maybe we could just rewrite it with native c bindings (ffi) which would give us something like this:

  • lua -> (ffi) -> c -> mega profit

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?

Cannot mock vim.fn

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?

Calling an async'd method with a `nil` argument omits all further arguments

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

Filetype guesser

Use something like this and guess the filetype from the buffer name.

Truncate border titles

@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

Bug in make_relative

if you have the following paths

  • /home/user/repo
  • /home/user/repo-feat

then you call make_relative("/home/user/repo") will return "-feat" since it just does a sub

Extensions with a `.` in them aren't detected

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.

macOS E5108 attempt to redefine passwd

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.

test

No description provided.

Add a helper for testing with various plugin configurations

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.

Consider cleaning up the `.git` folder to reduce the large repo size

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:

  • To see the 10 biggest files:
git verify-pack -v .git/objects/pack/pack-26ca0b79e92d096b8ce4eb32e16238ca74461801.idx \
| sort -k 3 -n \
| tail -10
  • To see what each file is (the important and bigger one is 943f15):
git rev-list --objects --all | grep 'first few chars of the sha1 from previous output'
  • Clean up your git by removing all of those unnecessary files:
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
  • Verify your size-pack, should be a lot smaller now:
git count-objects -v

Swapping the order of got/expected

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?)?

Function to add it as dep for plugin

@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

Use stdpath('cache') instead of stdpath('data') for log file

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

plenary.curl fails on Windows

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.

Cannot load quickfixlist with tests results

TLDR:

The way failed tests are notified makes it hard to load them into quickfixlist.

Description

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

  • Resulting quickfixlist:
|| ========================================	
|| 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	
  • This is my makefile:
test:
	nvim --headless -c "PlenaryBustedDirectory ."

It may be related to issue #73, but one is for human readability and this one is for parsing

Repro steps

  1. Install plenary.nvim and vim-dispatch
  2. Create a lua project with a makefile like the previously mentioned (or you can also clone mine)
  3. Run :Make command
  4. See the resulting quickfixlist with :copen

pending shouldn't fail tests

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)

REQ: better api for bulk jobs

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

hererocks setup failed on macos 10.15

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

TODO checklist for git

I am unsure about the naming though. What do you think? Is there stuff for data retrieving missing, which has no user interaction?

checklist

  1. get_gitignore (in scandir.lua)
  2. interpret_gitignore (in scandir.lua)
  3. show pretty logs (WIP git module)
  4. run git tag: should be commented (WIP git module)
  5. git branch --all (WIP git module)
  6. git remote -v
  7. git status -s uses colors => instead use git --porcelain. Only porcellain has a stability guarantee. usage.
  8. is_git_repo naming? git uses is-in-work-tree (too long)
  9. get_git_root
  10. 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 commit

NONGOALS

  • for example is_submodule with this approach and related functionality is too brittle and depends on user setup => job of a plugin to try to process the information (might decide later to include, once "it simply works" for plugins)
  • things that break due to specific settings
  • complex parsing or data processing

Plenary.job crashes on Windows

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.