summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/shared.lua
AgeCommit message (Collapse)AuthorFiles
2025-12-30build: move shared.lua to _core/Justin M. Keyes1
2025-12-15docs: misc, editorconfigJustin M. Keyes1
fix https://github.com/neovim/neovim/issues/36858
2025-10-24docs: types, news, lua-pluginJustin M. Keyes1
- mention "lua_ls", not "luals". https://github.com/neovim/neovim/discussions/36182 Co-authored-by: Maria Solano <majosolano99@gmail.com>
2025-09-13docs: manpage, keycodes, jsonJustin M. Keyes1
2025-08-03feat(lua): vim.list.bisect() #35108Yi Ming1
2025-07-28docs: lsp, ui events, dev guidance, osc7Justin M. Keyes1
fix #34981
2025-07-28feat(lua): add vim.list.unique()Lewis Russell1
Problem: No way to deduplicate values in a list in-place Solution: Add `vim.list.unique()`
2025-07-07docs: type fixes #34831phanium1
2025-06-06fix: type fixesLewis Russell1
Type fixes caught by emmylua
2025-05-26perf(runtime): vim.trim for long only whitespace stringsmonkoose1
2025-05-04fix(lua): vim.validate `message` param #33675Justin M. Keyes1
Problem: vim.validate does not handle `message` param. Solution: Add the missing logic.
2025-05-04refactor(lua): swap value params in `tbl_extend` behavior callback #33847Maria José Solano1
2025-05-03feat(lua): function `behavior` for tbl_extend, tbl_deep_extend #33819Maria José Solano1
2025-04-27docs: lsp, lua #33682Justin M. Keyes1
- sort fields alphabetically. - in the `vim.lsp.Client` docs, reference `vim.lsp.ClientConfig` instead of duplicating its docs. - cleanup lots of redundant-yet-drifted field docs.
2025-03-15docs: miscdundargoc1
Co-authored-by: Au. <acehinnnqru@gmail.com> Co-authored-by: Daniel Rainer <daniel.rainer@localhost> Co-authored-by: Evgeni Chasnovski <evgeni.chasnovski@gmail.com> Co-authored-by: Lewis Russell <lewis6991@gmail.com> Co-authored-by: Luuk van Baal <luukvbaal@gmail.com> Co-authored-by: Pierre Barbin <pierre@heitzsystem.com> Co-authored-by: Riley Bruins <ribru17@hotmail.com> Co-authored-by: Yinzuo Jiang <jiangyinzuo@foxmail.com> Co-authored-by: phanium <91544758+phanen@users.noreply.github.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2025-02-09build: add luals checkdundargoc1
This automatically downloads and uses the correct luals binary for the currently used system. `make luals` will run luals on all lua files in `runtime`. We download lua-language-server manually instead of relying on contributors downloading it on their own (like with stylua) as lua-language-server is updated frequently which may cause unnecessary friction. Therefore, we download a pinned version of luals which we then can manually bump when needed. This can be re-evaluated if luals becomes more stable in the future. Currently this is not run when using `make lint` since cmake style "file caching" doesn't seem possible at the moment. This is because checking a single file doesn't seem to work. Work on https://github.com/neovim/neovim/issues/24563.
2025-02-09fix(lua): vim.tbl_get({}, nil, 1) should return nil #32218phanium1
Problem: `vim.tbl_get(tbl, nil, 1)` returns `tbl` itself. In this case, `keys` is not empty, but `ipairs` skips the iteration: local keys = { nil, 1 } assert(#keys == 2) for i, k in ipairs(keys) do assert(false, 'unreachable') end Solution: Use `select("#", ...)` and `select(i, ...)` to ensure consistency for count and iteration.
2025-01-27fix: resolve all remaining LuaLS diagnosticsLewis Russell1
2025-01-09feat(docs): "yxx" runs Lua/Vimscript code examples #31904Riley Bruins1
`yxx` in Normal mode over a Lua or Vimscript code block section will execute the code. Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2024-12-10feat(lsp): add vim.lsp.config and vim.lsp.enableLewis Russell1
Design goals/requirements: - Default configuration of a server can be distributed across multiple sources. - And via RTP discovery. - Default configuration can be specified for all servers. - Configuration _can_ be project specific. Solution: - Two new API's: - `vim.lsp.config(name, cfg)`: - Used to define default configurations for servers of name. - Can be used like a table or called as a function. - Use `vim.lsp.confg('*', cfg)` to specify default config for all servers. - `vim.lsp.enable(name)` - Used to enable servers of name. Uses configuration defined via `vim.lsp.config()`.
2024-12-09docs: fix type of vim.validate valueMaria José Solano1
2024-12-07refactor: add vim._resolve_bufnrLewis Russell1
2024-11-29feat(lsp): support `textDocument/foldingRange` (#31311)Yi Ming1
* refactor(shared): extract `vim._list_insert` and `vim._list_remove` * feat(lsp): add `vim.lsp.foldexpr()` * docs(lsp): add a todo for state management * feat(lsp): add `vim.lsp.folding_range.foldclose()` * feat(lsp): schedule `foldclose()` if the buffer is not up-to-date * feat(lsp): add `vim.lsp.foldtext()` * feat(lsp): support multiple folding range providers * refactor(lsp): expose all folding related functions under `vim.lsp.*` * perf(lsp): add `lsp.MultiHandler` for do `foldupdate()` only once
2024-11-11perf(lsp): use faster version of str_byteindexLewis Russell1
2024-10-31fix: another round of type annotation fixesLewis Russell1
2024-10-21feat(vim.validate): improve fast form and deprecate spec formLewis Russell1
Problem: `vim.validate()` takes two forms when it only needs one. Solution: - Teach the fast form all the features of the spec form. - Deprecate the spec form. - General optimizations for both forms. - Add a `message` argument which can be used alongside or in place of the `optional` argument.
2024-10-21feat(deprecations): vim._defer_deprecated_module()Justin M. Keyes1
2024-10-18fix(types): add narrower vim.validate typesMaria José Solano1
2024-10-17perf(validate): use lighter versionLewis Russell1
- Also fix `vim.validate()` for PUC Lua when showing errors for values that aren't string or number.
2024-09-08fix(lua): revert vim.tbl_extend behavior change and document itChristian Clason1
Problem: vim.tbl_deep_extend had an undocumented feature where arrays (integer-indexed tables) were not merged but compared literally (used for merging default and user config, where one list should overwrite the other completely). Turns out this behavior was relied on in quite a number of plugins (even though it wasn't a robust solution even for that use case, since lists of tables (e.g., plugin specs) can be array-like as well). Solution: Revert the removal of this special feature. Check for list-like (contiguous integer indices) instead, as this is closer to the intent. Document this behavior.
2024-09-04fix(lua): allows tables with integer keys to be merged in tbl_deep_extendLewis Russell1
- The exclusion of lists was never justified in the commit history and is the wrong thing to do for a function that deals with tables. - Move the error checks out of the recursive path. Fixes #23654
2024-07-04fix(lua): use rawget() to get __call in vim.is_callable() (#29536)Tyler Miller1
Lua 5.1 uses a "raw get" to retrieve `__call` from a metatable to determine if a table is callable. Mirror this behavior in `vim.is_callable()`.
2024-06-28refactor: use `vim._with` where possibledundargoc1
This mostly means replacing `nvim_buf_call` and `nvim_win_call` with `vim._with`.
2024-06-24feat(lua): add `context.env` (environment variables) to `vim._with()`Evgeni Chasnovski1
2024-06-24feat(lua): update `vim._with` to allow more granular option contextsEvgeni Chasnovski1
Problem: with a single `context.options` there is no way for user to force which scope (local, global, both) is being temporarily set and later restored. Solution: replace single `options` context with `bo`, `go`, `wo`, and `o`. Naming and implementation follows how options can be set directly with `vim.*` (like `vim.bo`, etc.). Options are set for possible target `win` or `buf` context.
2024-06-24test(lua): cover `vim._with()` with testsEvgeni Chasnovski1
Problem: `vim._with()` has many different use cases which are not covered with tests. Solution: cover with tests. Some (many) test cases are intentionally marked as "pending" because they cover cases which don't work as expected at the moment (and fixing them requires specific knowledge of C codebase). Use them as a reference for future fixes. Also some of "can be nested" tests currently might pass only because the tested context doesn't work.
2024-06-08feat(lua): add `vim._with`dundargoc1
It's a function to perform operations in their own sealed context, similar to pythons `with`. This helps ease operations where you need to perform an operation in a specific context, and then restore the context. Marked as private for now as it's not ready for public use. The current plan is to start using this internally so we can discover and fix any problems. Once this is ready to be exposed it will be renamed to `vim.with`. Usage: ```lua local ret = vim._with({context = val}, function() return "hello" end) ``` , where `context` is any combination of: - `buf` - `emsg_silent` - `hide` - `horizontal` - `keepalt` - `keepjumps` - `keepmarks` - `keeppatterns` - `lockmarks` - `noautocmd` - `options` - `sandbox` - `silent` - `unsilent` - `win` (except for `win` and `buf` which can't be used at the same time). This list will most likely be expanded in the future. Work on https://github.com/neovim/neovim/issues/19832. Co-authored-by: Lewis Russell <lewis6991@gmail.com>
2024-06-04refactor(lua): use tuple syntax everywhere #29111Ilia Choly1
2024-05-28feat: add "jump" options to vim.diagnostic.config() (#29067)Gregory Anders1
Problem: There is no easy way to configure the behavior of the default diagnostic "jump" mappings. For example, some users way want to show the floating window, and some may not (likewise, some way want to only move between warnings/errors, or disable the "wrap" parameter). Solution: Add a "jump" table to vim.diagnostic.config() that sets default values for vim.diagnostic.jump(). Alternatives: Users can override the default mappings to use the exact options to vim.diagnostic.jump() that they want, but this has a couple issues: - While the default mappings are not complicated, they are also not trivial, so overriding them requires users to understand implementation details (specifically things like setting "count" properly). - If plugins want to change the default mappings, or configure the behavior in any way (e.g. floating window display), it becomes even harder for users to tweak specific behavior. vim.diagnostic.config() already works quite well as the "entry point" for tuning knobs with diagnostic UI elements, so this fits in nicely and composes well with existing mental models and idioms.
2024-05-27perf: add fast path to vim.validate (#28977)Gregory Anders1
For many small/simple functions (like those found in shared.lua), the runtime of vim.validate can far exceed the runtime of the function itself. Add an "overload" to vim.validate that uses a simple assertion pattern, rather than parsing a full "validation spec".
2024-05-16fix: extend the life of vim.tbl_flatten to 0.13Lewis Russell1
`vim.iter(t):flatten():totable()` doesn't handle nil so isn't a good enough replacement.
2024-05-15perf(lua): avoid spairs in vim.validate happy pathLewis Russell1
Problem: `vim.validate` is too slow, mainly because of `vim.spairs`. Solution: Collect all errors in via `pairs`, and sort the errors via `spairs`.
2024-05-13refactor(lua): remove deprecated features #28725Justin M. Keyes1
2024-04-22refactor(lua): deprecate tbl_flatten #28457Justin M. Keyes1
forgot some changes in 9912a4c81b0856200f44a38e99d38eae44cef5c9
2024-04-22refactor(lua): deprecate tbl_flattenJustin M. Keyes1
Problem: Besides being redundant with vim.iter():flatten(), `tbl_flatten` has these problems: - Has `tbl_` prefix but only accepts lists. - Discards some results! Compare the following: - iter.flatten(): ``` vim.iter({1, { { a = 2 } }, { 3 } }):flatten():totable() ``` - tbl_flatten: ``` vim.tbl_flatten({1, { { a = 2 } }, { 3 } }) ``` Solution: Deprecate tbl_flatten. Note: iter:flatten() currently fails ("flatten() requires a list-like table") on this code from gen_lsp.lua: local anonym = vim.iter({ -- remove nil anonymous_num > 1 and '' or nil, '---@class ' .. anonymous_classname, }):flatten():totable() Should we enhance :flatten() to work for arrays?
2024-04-21refactor(lua): rename tbl_isarray => isarrayJustin M. Keyes1
tbl_isarray was not released yet, so it will not go through a deprecation cycle. ref #24572
2024-04-21refactor(lua): rename tbl_islist => islistJustin M. Keyes1
ref #24572
2024-04-16fix: vim.validate() order is not deterministic #28377Justin M. Keyes1
Problem: The order of the validation performed by vim.validate() is unpredictable. - harder to write reliable tests. - confusing UX because validation result might return different errors randomly. Solution: Iterate the input using `vim.spairs()`. Future: Ideally, the caller could provide an "ordered dict".
2024-03-10docs: more accurate typing for vim.tbl_extendRiley Bruins1
2024-03-07feat(lua): deprecate vim.tbl_add_reverse_lookupMaria José Solano1