Closed younger-1 closed 2 years ago
I try to fix the problem in https://github.com/younger-1/impatient.nvim/commit/08bb6cf9635d25b22dea3ac08f8dc378d2629f0d, I simply use vim.api.nvim_get_runtime_file
which may be faster (I guess) than origin vim.api.nvim__get_runtime
.
C function of vim.api.nvim_get_runtime_file
:
https://github.com/neovim/neovim/blob/ebad151a2a1943ca0d4e07485c416e0762f7f096/src/nvim/api/vim.c#L513-L539
C function of vim.api.nvim__get_runtime
:
https://github.com/neovim/neovim/blob/ebad151a2a1943ca0d4e07485c416e0762f7f096/src/nvim/api/vim.c#L560-L569
This is expected behaviour. If using Lua, you should not be reliant on rtp ordering.
And vim.api.nvim_get_runtime_file is much slower than nvim__get_runtime.
This is expected behaviour. If using Lua, you should not be reliant on rtp ordering.
Thanks for your reply! May I ask what are the chances this reliant would be guaranteed by neovim in the future, in your opinion?
In regards to Lua, I don't know. The core devs might decide that a fast resolution time is more valuable than guaranteed ordering.
I've added the ability to disable the module resolution cache. If you rely on the ordering, then there isn't any optimisation we can make around module resolution.
Thanks very much!
require
obtains module by searching path in a way that doesn't respect the order of paths inruntimepath
option.This behavior is caused by
get_runtime_file
function which may cache some path that would take precedence over other paths in rtp.https://github.com/lewis6991/impatient.nvim/blob/bcc22509bdf1c9d9e63e5e44ad00f5fcf581d651/lua/impatient.lua#L121-L148
Test case
Saying the
rtp
is like following:If I have these files in my
rtp
:First
require('foo')
and thenrequire('foo.bar')
, the intended behavior is thatfile 2
andfile 1
will be loaded.file 3
will not be used because it has lower priority thanfile 1
inrtp
.But
impatient
breaks this mechanism here, asfile 2
is cached first and would take precedence over other paths inrtp
.