mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	fix(runtime): 'includeexpr' with non-Nvim-style Lua modules #33867
Closes #33862
This commit is contained in:
		| @@ -3,13 +3,15 @@ local M = {} | |||||||
| --- @param module string | --- @param module string | ||||||
| ---@return string | ---@return string | ||||||
| function M.includeexpr(module) | 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() |   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 |   for _, fname in ipairs { module, vim.fs.joinpath(root, 'lua', module) } do | ||||||
|     local path = vim.fs.joinpath(root, 'lua', fname .. suf) |     for _, suf in ipairs { '.lua', '/init.lua' } do | ||||||
|     if vim.uv.fs_stat(path) then |       local path = fname .. suf | ||||||
|       return path |       if vim.uv.fs_stat(path) then | ||||||
|  |         return path | ||||||
|  |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,18 +10,18 @@ local eq = t.eq | |||||||
| ---@param type string | ---@param type string | ||||||
| ---@return string | ---@return string | ||||||
| local function stdpath(type) | local function stdpath(type) | ||||||
|   return exec_lua([[return vim.fs.normalize(vim.fn.stdpath(...))]], type) |   return exec_lua([[return vim.fs.abspath(vim.fn.stdpath(...))]], type) | ||||||
| end | end | ||||||
|  |  | ||||||
| ---@return string | ---@return string | ||||||
| local function vimruntime() | local function vimruntime() | ||||||
|   return exec_lua [[ return vim.fs.normalize(vim.env.VIMRUNTIME) ]] |   return exec_lua [[ return vim.fs.abspath(vim.env.VIMRUNTIME) ]] | ||||||
| end | end | ||||||
|  |  | ||||||
| ---@param module string | ---@param module string | ||||||
| ---@return string | ---@return string | ||||||
| local function lua_includeexpr(module) | local function lua_includeexpr(module) | ||||||
|   return exec_lua([[return require('vim._ftplugin.lua').includeexpr(...)]], module) |   return exec_lua([[return vim.fs.abspath(require 'vim._ftplugin.lua'.includeexpr(...))]], module) | ||||||
| end | end | ||||||
|  |  | ||||||
| describe("ftplugin: Lua 'includeexpr'", function() | describe("ftplugin: Lua 'includeexpr'", function() | ||||||
| @@ -59,7 +59,12 @@ describe("ftplugin: Lua 'includeexpr'", function() | |||||||
|       write ++p |       write ++p | ||||||
|       edit %s/lua/runtime-foo/bar.lua |       edit %s/lua/runtime-foo/bar.lua | ||||||
|       write ++p |       write ++p | ||||||
|     ]]):format(temp_dir, temp_dir)) |  | ||||||
|  |       edit %s/general-foo/bar/init.lua | ||||||
|  |       write ++p | ||||||
|  |       edit %s/general-foo/bar/baz.lua | ||||||
|  |       write ++p | ||||||
|  |     ]]):format(temp_dir, temp_dir, temp_dir, temp_dir)) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|   it('finds module in current repo', function() |   it('finds module in current repo', function() | ||||||
| @@ -94,4 +99,11 @@ describe("ftplugin: Lua 'includeexpr'", function() | |||||||
|     eq(temp_dir .. '/lua/runtime-foo/init.lua', lua_includeexpr('runtime-foo')) |     eq(temp_dir .. '/lua/runtime-foo/init.lua', lua_includeexpr('runtime-foo')) | ||||||
|     eq(temp_dir .. '/lua/runtime-foo/bar.lua', lua_includeexpr('runtime-foo.bar')) |     eq(temp_dir .. '/lua/runtime-foo/bar.lua', lua_includeexpr('runtime-foo.bar')) | ||||||
|   end) |   end) | ||||||
|  |  | ||||||
|  |   it('non-Nvim-style Lua modules', function() | ||||||
|  |     command('cd ' .. temp_dir) | ||||||
|  |     eq(temp_dir .. '/general-foo/bar/init.lua', lua_includeexpr('general-foo.bar')) | ||||||
|  |     eq(temp_dir .. '/general-foo/bar/baz.lua', lua_includeexpr('general-foo.bar.baz')) | ||||||
|  |     command('cd -') | ||||||
|  |   end) | ||||||
| end) | end) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Phạm Bình An
					Phạm Bình An