summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim/loader.lua
AgeCommit message (Collapse)AuthorFiles
2026-03-12refactor: integer functions, optimize asserts #34112Lewis Russell1
refactor(lua): add integer coercion helpers Add vim._tointeger() and vim._ensure_integer(), including optional base support, and switch integer-only tonumber()/assert call sites in the Lua runtime to use them. This also cleans up related integer parsing in LSP, health, loader, URI, tohtml, and Treesitter code. supported by AI
2026-01-28refactor(lua): use vim.fs instead of fnamemodifyYochem van Rosmalen1
Although powerful -- especially with chained modifiers --, the readability (and therefore maintainability) of `fnamemodify()` and its modifiers is often worse than a function name, giving less context and having to rely on `:h filename-modifiers`. However, it is used plenty in the Lua stdlib: - 16x for the basename: `fnamemodify(path, ':t')` - 7x for the parents: `fnamemodify(path, ':h')` - 7x for the stem (filename w/o extension): `fnamemodify(path, ':r')` - 6x for the absolute path: `fnamemodify(path, ':p')` - 2x for the suffix: `fnamemodify(path, ':e')` - 2x relative to the home directory: `fnamemodify(path, ':~')` - 1x relative to the cwd: `fnamemodify(path, ':.')` The `fs` module in the stdlib provides a cleaner interface for most of these path operations: `vim.fs.basename` instead of `':t'`, `vim.fs.dirname` instead of `':h'`, `vim.fs.abspath` instead of `':p'`. This commit refactors the runtime to use these instead of fnamemodify. Not all fnamemodify calls are removed; some have intrinsic differences in behavior with the `vim.fs` replacement or do not yet have a replacement in the Lua module, i.e. `:~`, `:.`, `:e` and `:r`.
2025-12-18fix(lua): don't remove first char of non-file stacktrace source (#37008)zeertzjq1
2025-12-14fix(vim.loader): randomized AppImage path pollutes luac cache #36944Shmerl1
different approach to 78bbe53f7615e8b38d5289d9ce0579996109579b
2025-12-10fix(vim.loader): randomized AppImage path pollutes luac cache #35636Shmerl1
Problem: When using the Nvim appimage, `~/.cache/nvim/luac` directory can grow to 250,000+ files. Example of 2 identical files in `./luac/`: %2ftmp%2f.mount_nvim.a65Rja0%2fusr%2fshare%2fnvim%2fruntime%2flua%2fvim%2ftreesitter.luac %2ftmp%2f.mount_nvim.aNpxXgo%2fusr%2fshare%2fnvim%2fruntime%2flua%2fvim%2ftreesitter.luac Analysis: The `nvim.appimage` mounts nvim at a different temporary path each time it is invoked. The naming scheme of these cache files is random, which defats the purpose of the cache creates N new files on every launch of nvim. Steps to reproduce: 1. install `nvim.appimage` 2. `mv ~/.cache/nvim/luac ~/.cache/nvim/luac.backup` 3. `nvim` 4. Observe contents of `~/.cache/nvim/luac/` 5. Close nvim and run `nvim` again 6. Observe contents of `~/.cache/nvim/luac/` and see that new identical files have been added with a different mount prefix Solution: When running from an appimage, trim the random part of the filepaths.
2025-08-28refactor(lua): consistent use of local aliasesChristian Clason1
2025-06-06fix: type fixesLewis Russell1
Type fixes caught by emmylua
2024-12-04misc: keep deprecated vim.loader.disable stub (#31450)Gregory Anders1
Transitional stub to minimize breaking change pain, to be removed after 0.11 release.
2024-11-26fix(lua): remove vim.loader.disable() #31344Justin M. Keyes1
Problem: `vim.loader.disable` does not conform to `:help dev-name-common` and `:help dev-patterns`. Solution: - Add `enable` parameter to `vim.loader.enable` - Remove `vim.loader.disable` - Note the change in `:help news-breaking-dev` (HEAD changes). - This is not a breaking change (except to "HEAD") because `vim.loader` is marked "experimental". previous: 26765e8461c1ba1e9a351632212cf89900221781
2024-10-31refactor(loader): format annotationsLewis Russell1
2024-10-31refactor(loader): use the term stat instead of hashLewis Russell1
2024-10-31refactor(loader): remove Loader table and use localsLewis Russell1
2024-10-31refactor(loader): rename typesLewis Russell1
2024-10-31refactor(loader): inline Loader.load into Loader.loadfileLewis Russell1
2024-10-31refactor(loader): simplify Loader.loader_libLewis Russell1
2024-10-31refactor(loader): simplify Loader.write/readLewis Russell1
2024-10-31perf(loader): reduce calls to Loader.cache_fileLewis Russell1
2024-10-31refactor(loader): remove unused _topmodsLewis Russell1
2024-10-04docs: render `@since` versions, 0 means experimental #30649Justin M. Keyes1
An implication of this current approach is that `NVIM_API_LEVEL` should be bumped when a new Lua function is added. TODO(future): add a lint check which requires `@since` on all new functions. ref #25416
2024-09-23fix(vim.fs): dirname() returns "." on mingw/msys2 #30480Justin M. Keyes1
Problem: `vim.fs.dirname([[C:\User\XXX\AppData\Local]])` returns "." on mingw/msys2. Solution: - Check for "mingw" when deciding `iswin`. - Use `has("win32")` where possible, it works in "fast" contexts since b02eeb6a7281df0561a021d7ae595c84be9a01be.
2024-08-13fix(loader): follow the style of the error message for built-in loadersfutsuuu1
start the error message with '\n\t' instead of '\n' surround the module name by single quotes
2024-05-15perf(loader): use a quicker version of vim.fs.normalizeLewis Russell1
Problem: vim.fs.normalize() normalizes too much vim.loader and is slow. Solution: Make it faster by doing less. This reduces the times spent in vim.fs.normalize in vim.loader from ~13ms -> 1-2ms. Numbers from a relative benchmark: - Skipping `vim.validate()`: 285ms -> 230ms - Skipping `path_resolve_dot()`: 285ms -> 60ms - Skipping `double_slash`: 60ms -> 35ms
2024-03-06refactor(types): more fixesLewis Russell1
2024-03-01docs: improve/add documentation of Lua typesLewis Russell1
- Added `@inlinedoc` so single use Lua types can be inlined into the functions docs. E.g. ```lua --- @class myopts --- @inlinedoc --- --- Documentation for some field --- @field somefield integer --- @param opts myOpts function foo(opts) end ``` Will be rendered as ``` foo(opts) Parameters: - {opts} (table) Object with the fields: - somefield (integer) Documentation for some field ``` - Marked many classes with with `@nodoc` or `(private)`. We can eventually introduce these when we want to.
2024-02-27feat(docs): replace lua2dox.luaLewis Russell1
Problem: The documentation flow (`gen_vimdoc.py`) has several issues: - it's not very versatile - depends on doxygen - doesn't work well with Lua code as it requires an awkward filter script to convert it into pseudo-C. - The intermediate XML files and filters makes it too much like a rube goldberg machine. Solution: Re-implement the flow using Lua, LPEG and treesitter. - `gen_vimdoc.py` is now replaced with `gen_vimdoc.lua` and replicates a portion of the logic. - `lua2dox.lua` is gone! - No more XML files. - Doxygen is now longer used and instead we now use: - LPEG for comment parsing (see `scripts/luacats_grammar.lua` and `scripts/cdoc_grammar.lua`). - LPEG for C parsing (see `scripts/cdoc_parser.lua`) - Lua patterns for Lua parsing (see `scripts/luacats_parser.lua`). - Treesitter for Markdown parsing (see `scripts/text_utils.lua`). - The generated `runtime/doc/*.mpack` files have been removed. - `scripts/gen_eval_files.lua` now instead uses `scripts/cdoc_parser.lua` directly. - Text wrapping is implemented in `scripts/text_utils.lua` and appears to produce more consistent results (the main contributer to the diff of this change).
2024-02-13fix(loader): remove cyclic dependency on vim.fs (when --luamod-dev)Jongwook Choi1
Problem: Loading `vim.fs` via the `vim.loader` Lua package loader will result in a stack overflow due to a cyclic dependency. This may happen when the `vim.fs` module isn't byte-compiled, i.e. when `--luamod-dev` is used (#27413). Solution: `vim.loader` depends on `vim.fs`. Therefore `vim.fs` should be loaded in advance.
2023-12-30refactor: fix luals warningsdundargoc1
2023-08-09fix(lua): improve annotations for stricter luals diagnostics (#24609)Christian Clason1
Problem: luals returns stricter diagnostics with bundled luarc.json Solution: Improve some function and type annotations: * use recognized uv.* types * disable diagnostic for global `vim` in shared.lua * docs: don't start comment lines with taglink (otherwise LuaLS will interpret it as a type) * add type alias for lpeg pattern * fix return annotation for `vim.secure.trust` * rename local Range object in vim.version (shadows `Range` in vim.treesitter) * fix some "missing fields" warnings * add missing required fields for test functions in eval.lua * rename lsp meta files for consistency
2023-08-01fix(loader): cache path ambiguity #24491Tyler Miller1
Problem: cache paths are derived by replacing each reserved/filesystem- path-sensitive char with a `%` char in the original path. With this method, two different files at two different paths (each containing `%` chars) can erroneously resolve to the very same cache path in certain edge-cases. Solution: derive cache paths by url-encoding the original (path) instead using `vim.uri_encode()` with `"rfc2396"`. Increment `Loader.VERSION` to denote this change.
2023-07-18docs(lua): more improvements (#24387)Lewis Russell1
* docs(lua): teach lua2dox how to table * docs(lua): teach gen_vimdoc.py about local functions No more need to mark local functions with @private * docs(lua): mention @nodoc and @meta in dev-lua-doc * fixup! Co-authored-by: Justin M. Keyes <justinkz@gmail.com> --------- Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2023-06-22test: spellcheck :help (vimdoc) files #24109Justin M. Keyes1
Enforce consistent terminology (defined in `gen_help_html.lua:spell_dict`) for common misspellings. This does not spellcheck English in general (perhaps a future TODO, though it may be noisy).
2023-06-03feat(lua): rename vim.loop -> vim.uv (#22846)Lewis Russell1
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-13fix(loader): reset hashes when running the loaderLewis Russell1
2023-04-04docs: fix typosdundargoc1
Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: Raphael <glephunter@gmail.com> Co-authored-by: C.D. MacEachern <craig.daniel.maceachern@gmail.com> Co-authored-by: himanoa <matsunoappy@gmail.com>
2023-03-31refactor(loader): cache hash informationLewis Russell1
Whenever we run fs_stat() on a path, save this information in the loader so it can be re-used. - Loader.loadfile: Remove arguments `hash` as it is no longer needed. - Loader.loader: Use _G.loadstring instead of Loader.load This allows plugins to wrap loadstring to inspection and profiling - factor out read file logic
2023-03-31fix(loader): disable profiling by defaultLewis Russell1
2023-03-26refactor(loader): simplify tracking logicLewis Russell1
2023-03-26feat(vim.fs): improve normalizeLewis Russell1
- Add options argument with an option to expand env vars - Resolve '//' -> '/' - Use in vim.loader
2023-03-26refactor(loader): add typing for package.loadersLewis Russell1
2023-03-26refactor(loader): remove BufWritePost autocmdLewis Russell1
2023-03-26refactor(loader): use vim.fsLewis Russell1
2023-03-26feat(lua): add `vim.loader`Folke Lemaitre1
feat: new faster lua loader using byte-compilation