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
This commit is contained in:
Phạm Bình An
2025-03-18 05:41:07 +07:00
committed by GitHub
parent 063b69bab4
commit 08c328b8b0
4 changed files with 115 additions and 1 deletions

View File

@@ -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