fix(runtime): 'includeexpr' with non-Nvim-style Lua modules #33867

Closes #33862
This commit is contained in:
Phạm Bình An
2025-05-06 19:15:31 +07:00
committed by GitHub
parent 8d75910ef9
commit db2b774a16
2 changed files with 23 additions and 9 deletions

View File

@@ -3,13 +3,15 @@ local M = {}
--- @param module string
---@return string
function M.includeexpr(module)
local fname = module:gsub('%.', '/')
module = 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 vim.uv.fs_stat(path) then
return path
for _, fname in ipairs { module, vim.fs.joinpath(root, 'lua', module) } do
for _, suf in ipairs { '.lua', '/init.lua' } do
local path = fname .. suf
if vim.uv.fs_stat(path) then
return path
end
end
end