From c08139d790b783dc82f96869fdc14111495d1cd4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 18 Dec 2025 08:09:16 +0800 Subject: [PATCH] fix(lua): don't remove first char of non-file stacktrace source (#37008) --- runtime/doc/lua.txt | 2 +- runtime/lua/vim/_editor.lua | 2 +- runtime/lua/vim/loader.lua | 2 +- src/gen/gen_vimdoc.lua | 2 +- test/functional/core/startup_spec.lua | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 57c590cda1..b017650f2a 100644 --- 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 index ac88c32bc2..d84f80de3f 100644 --- 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 index 585f65617f..187d7076de 100644 --- 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 index a5767a961e..a278c18242 100755 --- 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 index b604b332c3..a336066296 100644 --- 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