My question is exactly as the heading. I can't find any good documentation explaining what it is and any usecase.
I found the code being used in many many lua.init files (the file where neovim configs are kept). I've included a snippet.
I know what it's doing. It is checking whether the path exists. But, why is it under loop
and why is it called fs_stat
? I'd greatly appreciate it if anyone could refer me to the documentation of vim or neovim that explains it.
First of all, vim.loop
is now called vim.uv
: https://github.com/neovim/neovim/pull/22846
But before that change, the documentation said this:
vim.loop
exposes all features of the Nvim event-loop.
Anyway, that's the luv
library for Lua (https://github.com/luvit/luv), which is a wrapper around the libuv
library for C (https://github.com/libuv/libuv). luv
calls it fs_stat
because the library it's wrapping calls it uv_fs_stat
. The fs
part of the name is because it's a file system operation. The stat
part of the name is because that's the name of the underlying syscall:
Equivalent to stat(2), fstat(2) and lstat(2) respectively.
And stat
is short for status
, and that syscall gets a file's status. (That might be one reason for your confusion: it can do a lot more than just check if a file exists.)