This caused segfaults when calling win_findbuf in an `on_detach`
callback, when the callback was triggered when closing the last window
containing the buffer.
Can be reproduced with a script like this:
-- in some lua file
vim.fn.timer_start(10, function() error("uh....") end)
-- will cause neovim to crash with the following error.
PANIC: unprotected error in call to Lua API
(nlua_CFunction_func_call failed.)
After this, it will instead print the error message
from the top of the stack, like so.
tmp/error_nvim.lua:10: uh...
Also added an example test. Previously this test
caused the embedded nvim to panic.
vim-patch:8.2.1054: not so easy to pass a lua function to Vim
vim-patch:8.2.1084: Lua: registering function has useless code
I think I have also opened up the possibility for people to use these
callbacks elsewhere, since I've added a new struct that we should be
able to use.
Also, this should allow us to determine what the state of a list is in
Lua or a dictionary in Lua, since we now can track the luaref as we go.
* Change uri_to_fname to not convert non-file URIs
A URI with a scheme other than file doesn't have a local file path.
* fixup! Change uri_to_fname to not convert non-file URIs
* fixup! fixup! Change uri_to_fname to not convert non-file URIs
* add lua function to highlight yanked region
* extract namespace, better naming, default values
* add default for event argument
* free timer
* factor out mark to position calculation
* d'oh
* make sure timer stops before callback (cf. luv example)
* factor out timer, more documentation
* fixup
* validate function argument for schedule
* fix block selection past eol
* correct handling of multibyte characters
* move arguments around, some cleanup
* move utility functions to vim.lua
* use anonymous namespaces, avoid local api
* rename function
* add test for schedule_fn
* fix indent
* turn hl-yank into proper (hightlight) module
* factor out position-to-region function
mark extraction now part of highlight.on_yank
* rename schedule_fn to defer_fn
* add test for vim.region
* todo: handle double-width characters
* remove debug printout
* do not shadow arguments
* defer also callable table
* whitespace change
* move highlight to vim/highlight.lua
* add documentation
* add @return documentation
* test: add check before vim.defer fires
* doc: fixup
Sloppy code inherited from Vim caused user scripts to be able
to observe the cursor line in an invalid intermediary state,
due to Neovim change callbacks being unbuffered unlike Vim listeners.
Manifested in Vimscript executed from the callback possibly erroring
when `:call`:ing any function,
due to the implicit range `curwin->w_cursor.lnum,curwin->w_cursor.lnum`
failing validation.
Fixed by deferring the call to `changed_lines()` until after
`curwin->w_cursor.lnum` gets its correct value.
- We already find ourselves renaming nvim_execute_lua in tests and
scripts, which suggests "exec" is the verb we actually want.
- Add "exec" verb to `:help dev-api`.
- Add vim variable meta accessors: vim.env, vim.{g,v,w,bo,wo}
- Redo gen_char_blob to generate multiple blobs instead of just one
so that multiple Lua modules can be inlined.
- Reorder vim.lua inclusion so that it can use previously defined C
functions and utility functions like vim.shared and vim.inspect things.
- Inline shared.lua into nvim, but also keep it available in runtime.
Mainly configuration and RPC infrastructure can be considered "done". Specific requests and their callbacks will be improved later (and also served by plugins). There are also some TODO:s for the client itself, like incremental updates.
Co-authored by at-tjdevries and at-h-michael, with many review/suggestion contributions.
We often want to do type checking of public function arguments.
- test: Rename utility_function_spec.lua to vim_spec.lua
- .luacov: Map lua module names
compared to vim.api.|nvim_call_function|, this fixes some typing issues
due to the indirect conversion via the API. float values are preserved
as such (fixes#9389) as well as empty dicts/arrays.
Ref https://github.com/norcalli/nvim.lua for the call syntax
- Rename `meth_pcall`.
- Make `pcall_err` raise an error if the function does not fail.
- Add `vim.pesc()` to treat a string as literal where a Lua pattern is
expected.
Flaky test (osx):
[ FAILED ] ...is/build/neovim/neovim/test/functional/lua/loop_spec.lua @ 23: vim.loop timer
...is/build/neovim/neovim/test/functional/lua/loop_spec.lua:56: Expected objects to be the same.
Passed in:
(number) 0
Expected:
(number) 2
stack traceback:
...is/build/neovim/neovim/test/functional/lua/loop_spec.lua:56: in function <...is/build/neovim/neovim/test/functional/lua/loop_spec.lua:23>
It was bumped from sleeping for 20ms to 50ms in d33aaa0f5f already.
Implement lazy loading for vim.submodule, this would be over-engineering
for inspect only, but we expect to use this solution also for more and
larger modules.
Instead of eager-loading during plugin/* sourcing, define runtime
modules such as `vim.inspect` as lazy builtins. Otherwise non-builtin
Lua modules such as `vim.inspect` would not be available during startup
(init.vim, `-c`, `--cmd`, …).
ref #6580
ref #8677
- Return VimL errors instead of generic errors for:
- nvim_call_function
- nvim_call_dict_function
- Fix tests which were silently broken before this change.
This violates #6150 where we agreed not to translate API errors. But
that can be fixed later.
Reasoning is majorly the same: check whether lua has bug or API function has
bug, but on the other side: previous commit is checking whether similar bug when
using API via msgpack RPC, this commit is checking whether another API function
used via lua bindings triggers the same bug. Should additionally give a hint
about which lua code contains a bug.
Fixes:
1. Allocate space for the NUL byte.
2. Do not exclude last line from range.
3. Remove code for sandbox: it is handled earlier.
4. Fix index in new_line_transformed when converting NULs to NLs.
5. Always allocate new_line_transformed, but save allocated value.