aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorPhạm Bình An <111893501+brianhuster@users.noreply.github.com>2025-03-18 05:41:07 +0700
committerGitHub <noreply@github.com>2025-03-17 15:41:07 -0700
commit08c328b8b079334e7fb38472339c4f8ba1a0df3b (patch)
treefc1fcbd553ad90486af0a016ca96739b7f09fbd7 /runtime/lua/vim
parent063b69bab4ab64b614e31ab0c93279fdbebb40b7 (diff)
downloadrneovim-08c328b8b079334e7fb38472339c4f8ba1a0df3b.tar.gz
rneovim-08c328b8b079334e7fb38472339c4f8ba1a0df3b.tar.bz2
rneovim-08c328b8b079334e7fb38472339c4f8ba1a0df3b.zip
feat(runtime): Lua ftplugin 'includeexpr' #32719
Problem: Current `'includeexpr'` in runtime/ftplugin/lua.vim doesn't work with Nvim Lua. Solution: Provide an improved 'includeexpr' for Lua in "ftplugin/lua.lua". Closes: https://github.com/neovim/neovim/issues/32490
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/_ftplugin/lua.lua26
1 files changed, 26 insertions, 0 deletions
diff --git a/runtime/lua/vim/_ftplugin/lua.lua b/runtime/lua/vim/_ftplugin/lua.lua
new file mode 100644
index 0000000000..588433409b
--- /dev/null
+++ b/runtime/lua/vim/_ftplugin/lua.lua
@@ -0,0 +1,26 @@
+local M = {}
+
+--- @param module string
+---@return string
+function M.includeexpr(module)
+ ---@param fname string
+ ---@return boolean
+ local function filereadable(fname)
+ return vim.fn.filereadable(fname) == 1
+ end
+
+ local fname = module:gsub('%.', '/')
+
+ local root = vim.fs.root(vim.api.nvim_buf_get_name(0), 'lua') or vim.fn.getcwd()
+ for _, suf in ipairs { '.lua', '/init.lua' } do
+ local path = vim.fs.joinpath(root, 'lua', fname .. suf)
+ if filereadable(path) then
+ return path
+ end
+ end
+
+ local modInfo = vim.loader.find(module)[1]
+ return modInfo and modInfo.modpath or module
+end
+
+return M