commit c08139d790b783dc82f96869fdc14111495d1cd4
parent c172fd9f464d5766eab9071e8f4770504c920c05
Author: zeertzjq <zeertzjq@outlook.com>
Date: Thu, 18 Dec 2025 08:09:16 +0800
fix(lua): don't remove first char of non-file stacktrace source (#37008)
Diffstat:
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
@@ -236,7 +236,7 @@ Note:
*lua-script-location*
To get its own location, Lua scripts/modules can use |debug.getinfo()|: >
- debug.getinfo(1, 'S').source:sub(2)
+ debug.getinfo(1, 'S').source:gsub('^@', '')
<
==============================================================================
diff --git a/runtime/lua/vim/_editor.lua b/runtime/lua/vim/_editor.lua
@@ -1252,7 +1252,7 @@ local function traceback()
if not info then
break
end
- local msg = (' %s:%s'):format(info.source:sub(2), info.currentline)
+ local msg = (' %s:%s'):format(info.source:gsub('^@', ''), info.currentline)
table.insert(backtrace, msg)
level = level + 1
end
diff --git a/runtime/lua/vim/loader.lua b/runtime/lua/vim/loader.lua
@@ -492,7 +492,7 @@ function M._profile(opts)
if opts and opts.loaders then
for l, loader in pairs(loaders) do
- local loc = debug.getinfo(loader, 'Sn').source:sub(2)
+ local loc = debug.getinfo(loader, 'Sn').source:gsub('^@', '')
loaders[l] = track('loader ' .. l .. ': ' .. loc, loader)
end
end
diff --git a/src/gen/gen_vimdoc.lua b/src/gen/gen_vimdoc.lua
@@ -895,7 +895,7 @@ end
--- @return string
local function get_script_path()
- local str = debug.getinfo(2, 'S').source:sub(2)
+ local str = debug.getinfo(2, 'S').source:gsub('^@', '')
return str:match('(.*[/\\])') or './'
end
diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua
@@ -1243,7 +1243,7 @@ describe('user config init', function()
string.format(
[[
vim.g.exrc_file = "%s"
- vim.g.exrc_path = debug.getinfo(1, 'S').source:sub(2)
+ vim.g.exrc_path = debug.getinfo(1, 'S').source:gsub('^@', '')
vim.g.exrc_count = (vim.g.exrc_count or 0) + 1
]],
exrc_path