robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Phạm Bình Anfix(runtime): 'includeexpr' with non-Nvim-style Lua modules #33867db2b774a16

master
553 B22 linesraw
1local M = {}
2
3--- @param module string
4---@return string
5function M.includeexpr(module)
6  module = module:gsub('%.', '/')
7
8  local root = vim.fs.root(vim.api.nvim_buf_get_name(0), 'lua') or vim.fn.getcwd()
9  for _, fname in ipairs { module, vim.fs.joinpath(root, 'lua', module) } do
10    for _, suf in ipairs { '.lua', '/init.lua' } do
11      local path = fname .. suf
12      if vim.uv.fs_stat(path) then
13        return path
14      end
15    end
16  end
17
18  local modInfo = vim.loader.find(module)[1]
19  return modInfo and modInfo.modpath or module
20end
21
22return M