diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/news.txt | 2 | ||||
-rw-r--r-- | runtime/ftplugin/lua.lua | 3 | ||||
-rw-r--r-- | runtime/lua/vim/_ftplugin/lua.lua | 26 |
3 files changed, 30 insertions, 1 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index f7f86237f6..9c3ae3706c 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -326,6 +326,8 @@ LUA `vim.o`, `vim.wo`, `vim.bo`, `vim.opt`, `vim.opt_local`, `vim.opt_global`, and `vim.fn`. • Documentation for |lua-bit|. +• |gf| in Lua buffers can go to module in same repo, |runtime-search-path| and + |package.path|. • |vim.fs.rm()| can delete files and directories. • |vim.validate()| now has a new signature which uses less tables, is more performant and easier to read. diff --git a/runtime/ftplugin/lua.lua b/runtime/ftplugin/lua.lua index e0f7e95cf6..ef8f126fab 100644 --- a/runtime/ftplugin/lua.lua +++ b/runtime/ftplugin/lua.lua @@ -1,9 +1,10 @@ -- use treesitter over syntax vim.treesitter.start() +vim.bo.includeexpr = 'v:lua.require"vim._ftplugin.lua".includeexpr()' vim.bo.omnifunc = 'v:lua.vim.lua_omnifunc' vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()' vim.b.undo_ftplugin = (vim.b.undo_ftplugin or '') .. '\n call v:lua.vim.treesitter.stop()' - .. '\n setl omnifunc< foldexpr<' + .. '\n setl omnifunc< foldexpr< includeexpr<' 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 |