lightspeed.nvim icon indicating copy to clipboard operation
lightspeed.nvim copied to clipboard

Error in `set_editor_opts` in `LightspeedLeave` autocommand

Open Gelio opened this issue 3 years ago • 3 comments

Hey! Thanks for this great plugin!

Today after updating my neovim build to the latest nightly (https://github.com/neovim/neovim/commit/6d52a29c3b8714804facdc7705e57e7f0511c85a), I started seeing errors originating from the set_editor_opts function executed by the LightspeedLeave autocommand.

Error detected while processing User Autocommands for "LightspeedLeave":
Error executing lua callback: ...ite/pack/packer/start/lightspeed.nvim/lua/lightspeed.lua:2764: E487: Argument must be positive
stack traceback:
        [C]: in function '__newindex'
        ...ite/pack/packer/start/lightspeed.nvim/lua/lightspeed.lua:2764: in function <...ite/pack/packer/start/lightspeed.nvim/lua/lightsp
eed.lua:2757>
        [C]: in function 'exec_user_autocmds'
        ...ite/pack/packer/start/lightspeed.nvim/lua/lightspeed.lua:2047: in function '_396_'
        ...ite/pack/packer/start/lightspeed.nvim/lua/lightspeed.lua:2050: in function 'get_first_input'
        ...ite/pack/packer/start/lightspeed.nvim/lua/lightspeed.lua:2369: in function 'go'
        ...m/site/pack/packer/start/lightspeed.nvim/plugin/init.lua:3: in function <...m/site/pack/packer/start/lightspeed.nvim/plugin/init
.lua:3>

The line that fails is https://github.com/ggandor/lightspeed.nvim/blob/8fb5ebb2c18db13bc17556376526068dce0803b5/lua/lightspeed.lua#L2762. The line number does not match because I added some print statements to debug it.

Investigation

I added a print to see which option cannot be set.

    print({ scope = scope, name = name, val = val })

It turns out, this code tries to set vim.wo.scrolloff = -1, which fails with that error.

{
  name = "scrolloff",
  scope = "wo",
  val = -1
}

I checked the results of the following neovim commands:

:lua print(vim.wo.scrolloff)
0

:echo &scrolloff
0

:echo &l:scrolloff
-1

:setlocal scrolloff?
-1

I believe the result of &l:scrolloff may be a problem. After all, this is the value that is requested in https://github.com/ggandor/lightspeed.nvim/blob/8fb5ebb2c18db13bc17556376526068dce0803b5/lua/lightspeed.lua#L2741-L2742

Possibly related to https://github.com/neovim/neovim/pull/18743

Possible solution

If &l:scrolloff is -1, then looks like setlocal scrolloff is not set, so there is no need to restore it, unless I am mistaken.

Gelio avatar Jun 21 '22 07:06 Gelio

Thanks for the thorough report! I had no mental energy to further investigate and really grok what causes this issue, but it seems we don't need that offending part in the code anymore (neovim/neovim#13964), so I just inserted a conditional check as a temporary fix.

ggandor avatar Jun 22 '22 09:06 ggandor

Let's keep this open for a while for discoverability.

ggandor avatar Jun 22 '22 09:06 ggandor

FYI, this is due to a regression in core which I'm planning to fix with https://github.com/neovim/neovim/pull/19041

Testing is welcomed 😄

lewis6991 avatar Jun 22 '22 10:06 lewis6991