summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/lua/vim_spec.lua
AgeCommit message (Collapse)AuthorFiles
2023-04-19fix(iter): remove special case totable for map-like tablesGregory Anders1
This was originally meant as a convenience but prevents possible functionality. For example: -- Get the keys of the table with even values local t = { a = 1, b = 2, c = 3, d = 4 } vim.iter(t):map(function(k, v) if v % 2 == 0 then return k end end):totable() The example above would not work, because the map() function returns only a single value, and cannot be converted back into a table (there are many such examples like this). Instead, to convert an iterator into a map-like table, users can use fold(): vim.iter(t):fold({}, function(t, k, v) t[k] = v return t end)
2023-04-19fix(iter): add tag to packed tableGregory Anders1
If pack() is called with a single value, it does not create a table; it simply returns the value it is passed. When unpack is called with a table argument, it interprets that table as a list of values that were packed together into a table. This causes a problem when the single value being packed is _itself_ a table. pack() will not place it into another table, but unpack() sees the table argument and tries to unpack it. To fix this, we add a simple "tag" to packed table values so that unpack() only attempts to unpack tables that have this tag. Other tables are left alone. The tag is simply the length of the table.
2023-04-17feat(lua): add vim.iter (#23029)Gregory Anders1
vim.iter wraps a table or iterator function into an `Iter` object with methods such as `filter`, `map`, and `fold` which can be chained to produce iterator pipelines that do not create new tables at each step.
2023-04-14feat(lua)!: add stricter vim.tbl_islist() and rename old one to ↵NAKAI Tsuyoshi1
vim.tbl_isarray() (#16440) feat(lua)!: add stricter vim.tbl_islist(), rename vim.tbl_isarray() Problem: `vim.tbl_islist` allows gaps in tables with integer keys ("arrays"). Solution: Rename `vim.tbl_islist` to `vim.tbl_isarray`, add new `vim.tbl.islist` that checks for consecutive integer keys that start from 1.
2023-04-14feat(lua): vim.tbl_contains supports general tables and predicates (#23040)Christian Clason1
* feat(lua): vim.tbl_contains supports general tables and predicates Problem: `vim.tbl_contains` only works for list-like tables (integer keys without gaps) and primitive values (in particular, not for nested tables). Solution: Rename `vim.tbl_contains` to `vim.list_contains` and add new `vim.tbl_contains` that works for general tables and optionally allows `value` to be a predicate function that is checked for every key.
2023-04-11feat(lua): vim.region accepts getpos() arg (#22635)NAKAI Tsuyoshi1
2023-04-07feat(lua): allow vim.F.if_nil to take multiple arguments (#22903)Gregory Anders1
The first argument which is non-nil is returned. This is useful when using nested default values (e.g. in the EditorConfig plugin). Before: local enable = vim.F.if_nil(vim.b.editorconfig, vim.F.if_nil(vim.g.editorconfig, true)) After: local enable = vim.F.if_nil(vim.b.editorconfig, vim.g.editorconfig, true)
2023-04-05refactor: rename local API alias from a to apiLewis Russell1
Problem: Codebase inconsistently binds vim.api onto a or api. Solution: Use api everywhere. a as an identifier is too short to have at the module level.
2023-04-01feat: allow function passed to defaulttable to take an argument (#22839)Gregory Anders1
Pass the value of the key being accessed to the create function, to allow users to dynamically generate default values.
2023-03-22refactor(vim.gsplit): remove "keepsep"Justin M. Keyes1
string.gmatch() is superior, use that instead.
2023-03-22feat(vim.gsplit): gain features of vim.splitJustin M. Keyes1
Problem: - vim.split has more features than vim.gsplit. - Cannot inspect the "separator" segments of vim.split or vim.gsplit. Solution: - Move common implementation from vim.split into vim.gsplit. - TODO: deprecate vim.split in favor of vim.totable(vim.gsplit())? - Introduce `keepsep` parameter. Related: 84f66909e4008a57da947f1640bfc24da5e41a72
2023-03-15fix(lua): vim.deprecate() shows ":help deprecated" #22677Justin M. Keyes1
Problem: vim.deprecate() shows ":help deprecated" for third-party plugins. ":help deprecated" only describes deprecations in Nvim, and is unrelated to any 3rd party deprecations. Solution: If `plugin` is specified, don't show ":help deprecated". fix #22235
2023-03-13refactor!: rename vim.pretty_print => vim.printJustin M. Keyes1
Problem: The function name `vim.pretty_print`: 1. is verbose, which partially defeats its purpose as sugar 2. does not draw from existing precedent or any sort of convention (except external projects like penlight or python?), which reduces discoverability, and degrades signaling about best practices. Solution: - Rename to `vim.print`. - Change the behavior so that 1. strings are printed without quotes 2. each arg is printed on its own line 3. tables are indented with 2 instead of 4 spaces - Example: :lua ='a', 'b', 42, {a=3} a b 42 { a = 3 } Comparison of alternatives: - `vim.print`: - pro: consistent with Lua's `print()` - pro: aligns with potential `nvim_print` API function which will replace nvim_echo, nvim_notify, etc. - con: behaves differently than Lua's `print()`, slightly misleading? - `vim.echo`: - pro: `:echo` has similar "pretty print" behavior. - con: inconsistent with Lua idioms. - `vim.p`: - pro: very short, fits with `vim.o`, etc. - con: not as discoverable as "echo" - con: less opportunity for `local p = vim.p` because of potential shadowing.
2023-03-06feat(lua): omnifunc for builting lua interpreterBjörn Linse1
also make implicit submodules "uri" and "_inspector" work with completion this is needed for `:lua=vim.uri_<tab>` wildmenu completion to work even before uri or _inspector functions are used.
2023-02-14refactor(api): VALIDATE macros #22187Justin M. Keyes1
Problem: - API validation involves too much boilerplate. - API validation errors are not consistently worded. Solution: Introduce some macros. Currently these are clumsy, but they at least help with consistency and avoid some nesting.
2023-01-23build: make generated source files reproducible #21586Arnout Engelen1
Problem: Build is not reproducible, because generated source files (.c/.h/) are not deterministic, mostly because Lua pairs() is unordered by design (for security). https://github.com/LuaJIT/LuaJIT/issues/626#issuecomment-707005671 https://www.lua.org/manual/5.1/manual.html#pdf-next > The order in which the indices are enumerated is not specified [...] > >> The hardening of the VM deliberately randomizes string hashes. This in >> turn randomizes the iteration order of tables with string keys. Solution: - Update the code generation scripts to be deterministic. - That is only a partial solution: the exported function (funcs_metadata.generated.h) and ui event (ui_events_metadata.generated.h) metadata have some mpack'ed tables, which are not serialized deterministically. - As a workaround, introduce `PRG_GEN_LUA` cmake setting, so you can inject a modified build of luajit (with LUAJIT_SECURITY_PRN=0) that preserves table order. - Longer-term we should change the mpack'ed data structure so it no longer uses tables keyed by strings. Closes #20124 Co-Authored-By: dundargoc <gocdundar@gmail.com> Co-Authored-By: Arnout Engelen <arnout@bzzt.net>
2023-01-16test: avoid noise in NVIM_LOG_FILEJustin M. Keyes1
Problem: Tests that _intentionally_ fail certain conditions cause noise in $NVIM_LOG_FILE: $NVIM_LOG_FILE: /home/runner/work/neovim/neovim/build/.nvimlog (last 100 lines) WRN 2023-01-16T18:26:27.673 T599.7799.0 unsubscribe:519: RPC: ch 1: tried to unsubscribe unknown event 'doesnotexist' WRN 2023-01-16T18:29:00.557 ?.11151 server_start:163: Failed to start server: no such file or directory: /X/X/X/... WRN 2023-01-16T18:33:07.269 127.0.0.1:12345 server_start:163: Failed to start server: address already in use: 127.0.0.1 ... -- Output to stderr: module 'vim.shared' not found: no field package.preload['vim.shared'] no file './vim/shared.lua' no file '/home/runner/nvim-deps/usr/share/lua/5.1/vim/shared.lua' no file '/home/runner/nvim-deps/usr/share/lua/5.1/vim/shared/init.lua' no file '/home/runner/nvim-deps/usr/lib/lua/5.1/vim/shared.lua' no file '/home/runner/nvim-deps/usr/lib/lua/5.1/vim/shared/init.lua' no file './vim/shared.so' ... E970: Failed to initialize builtin lua modules Solution: - Log to a private $NVIM_LOG_FILE in tests that intentionally fail and cause ERR log messages. - Assert that the expected messages are actually logged.
2022-12-15fix(lua): always return nil values in vim.tbl_get when no resultsWilliam Boman1
While `return` and `return nil` are for most intents and purposes identical, there are situations where they're not. For example, calculating the amount of values via the `select()` function will yield varying results: ```lua local function nothing() return end local function null() return nil end select('#', nothing()) -- 0 select('#', null()) -- 1 ``` `vim.tbl_get` currently returns both nil and no results, which makes it unreliable to use in certain situations without manually accounting for these discrepancies.
2022-12-12fix: vim.opt_local:append ignoring global option value (#21382)Phelipe Teles1
Closes https://github.com/neovim/neovim/issues/18225
2022-12-02feat(aucmd_win): allow crazy things with hidden buffers (#21250)zeertzjq1
Problem: Crash when doing crazy things with hidden buffers. Solution: Dynamically allocate the list of autocommand windows.
2022-11-29docs: fix typos (#21196)dundargoc1
Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: Raphael <glephunter@gmail.com> Co-authored-by: Gregory Anders <greg@gpanders.com>
2022-11-14fix(lua): make `vim.deepcopy` work with `vim.NIL`Max1
style: changed double quotes to single quotes feat: add tests fix tests
2022-11-14feat(test): add Lua forms for API methods (#20152)Lewis Russell1
2022-10-24fix(lua): pesc, tbl_islist result types #20751NAKAI Tsuyoshi1
Problem: - pesc() returns multiple results, it should return a single result. - tbl_islist() returns non-boolean in some branches. - Docstring: @generic must be declared first Solution: Constrain docstring annotations. Fix return types. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2022-10-23docs: fix typos (#20724)dundargoc1
Co-authored-by: Marco Lehmann <m99@posteo.de>
2022-10-14fix(lua): on_yank error with blockwise multibyte region #20162Daniel Zhang1
Prevent out of range error when calling `str_byteindex`. Use `vim.str_byteindex(bufline, #bufline)` to cacluate utf length of `bufline`. fix #20161
2022-10-10fix(lua): assert failure with vim.regex() error inside :silent! (#20555)RZia1
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2022-09-30docs: fix typos (#20394)dundargoc1
Co-authored-by: Raphael <glephunter@gmail.com> Co-authored-by: smjonas <jonas.strittmatter@gmx.de> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2022-09-29test: add a Lua test for #17501 (#20392)zeertzjq1
2022-09-22Merge pull request #20103 from lewis6991/refactor/vim_optLewis Russell1
2022-09-16fix(eval)!: make Lua Funcref work as method and in substitute() (#20217)zeertzjq1
BREAKING CHANGE: When using a Funcref converted from a Lua function as a method in Vim script, the result of the base expression is now passed as the first argument instead of being ignored. vim-patch:8.2.5117: crash when calling a Lua callback from a :def function Problem: Crash when calling a Lua callback from a :def function. (Bohdan Makohin) Solution: Handle FC_CFUNC in call_user_func_check(). (closes vim/vim#10587) https://github.com/vim/vim/commit/7d149f899d423b7bf2b90d7b11ebe3e560c462b9
2022-09-13fix(lua): make vim.str_utfindex and vim.str_byteindex handle NUL bytesbfredl1
fixes #16290
2022-09-09refactor(vim.opt): unify vim.bo/wo buildingLewis Russell1
2022-09-07Use weak tables in tree-sitter code (#17117)Thomas Vigouroux1
feat(treesitter): use weak tables when possible Also add the defaulttable function to create a table whose values are created when a key is missing.
2022-08-24feat(lua): add vim.iconv (#18286)Lewis Russell1
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2022-08-02test: improve mapping tests and docs (#19619)zeertzjq1
2022-07-20feat(lua): allow vim.cmd to be indexed (#19238)Lewis Russell1
2022-07-19fix(lua): make it possible to cancel vim.wait() with Ctrl-C (#19217)JP1
2022-06-25Merge pull request #19041 from lewis6991/globallocalbfredl1
fix(api): nvim_set_option_value for global-local options
2022-06-22fix(api): check error after getting win/buf handle (#19052)Gregory Anders1
2022-06-22fix(api): nvim_set_option_value for global-local optionsLewis Russell1
global-local window options need to be handled specially. When `win` is given but `scope` is not, then we want to set the local version of the option but not the global one, therefore we need to force `scope='local'`. Note this does not apply to window-local only options (e.g. 'number') Example: nvim_set_option_value('scrolloff', 10, {}) -- global-local window option; set global value nvim_set_option_value('scrolloff', 20, {win=0}) -- global-local window option; set local value nvim_set_option_value('number', true, {}) -- local window option is now equivalent to: nvim_set_option_value('scrolloff', 10, {}) nvim_set_option_value('scrolloff', 20, {win=0, scope='local'}) -- changed from before nvim_set_option_value('number', true, {win=0}) -- unchanged from before Only the global-local option with a `win` provided gets forced to local scope.
2022-06-20refactor: use nvim_{get,set}_option_value for vim.{b,w}oGregory Anders1
`nvim_get_option_value` and `nvim_set_option_value` better handle unsetting local options. For instance, this is currently not possible: vim.bo.tagfunc = nil This does not work because 'tagfunc' is marked as "local to buffer" and does not have a fallback global option. However, using :setlocal *does* work as expected :setlocal tagfunc= `nvim_set_option_value` behaves more like :set and :setlocal (by design), so using these as the underlying API functions beneath vim.bo and vim.wo makes those two tables act more like :setlocal. Note that vim.o *already* uses `nvim_set_option_value` under the hood, so that vim.o behaves like :set.
2022-06-16fix(lua): clear got_int when calling vim.on_key() callback (#18979)zeertzjq1
2022-06-13fix(tests): check for EOF on exit of nvim properlybfredl1
2022-05-17fixup: update test/functional/lua/vim_spec.luaLewis Russell1
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2022-05-17feat(lua): allow some viml functions to run in fastLewis Russell1
This change adds the necessary plumbing to annotate functions in funcs.c as being allowed in run in luv fast events.
2022-05-01fix(shared): avoid indexing unindexable values in vim.tbl_get() (#18337)William Boman1
2022-04-26test: correct order of arguments to eq() and neq()zeertzjq1
2022-04-23fix(lua): don't mutate opts parameter of vim.keymap.del (#18227)Andrey Mishchenko1
`vim.keymap.del` takes an `opts` parameter that lets caller refer to and delete buffer-local mappings. For some reason the implementation of `vim.keymap.del` mutates the table that is passed in, setting `opts.buffer` to `nil`. This is wrong and also undocumented.
2022-03-24feat: add vim.tbl_get (#17831)Michael Lingelbach1
vim.tbl_get takes a table with subsequent string arguments (variadic) that index into the table. If the value pointed to by the set of keys exists, the function returns the value. If the set of keys does not exist, the function returns nil.