feat(builtin.autocommands): support jumping to lua callback src (#2916)

This commit is contained in:
Tyler Miller
2024-02-13 19:00:33 -08:00
committed by GitHub
parent 0f865f17af
commit eb88dc6434
2 changed files with 14 additions and 0 deletions

View File

@@ -1311,6 +1311,19 @@ internal.autocommands = function(opts)
return false
end
local val = selection.value
local cb = val.callback
if vim.is_callable(cb) then
if type(cb) ~= "string" then
local f = type(cb) == "function" and cb or rawget(getmetatable(cb), "__call")
local info = debug.getinfo(f, "S")
local file = info.source:match "^@(.+)"
local lnum = info.linedefined
if file and (lnum or 0) > 0 then
selection.filename, selection.lnum, selection.col = file, lnum, 1
return false
end
end
end
local group_name = val.group_name ~= "<anonymous>" and val.group_name or ""
local output =
vim.fn.execute("verb autocmd " .. group_name .. " " .. val.event .. " " .. val.pattern, "silent")