Skip to content

Commit

Permalink
attempt no 2 to avoid osv breaking inside
Browse files Browse the repository at this point in the history
Ref #21
  • Loading branch information
jbyuki committed Jul 5, 2024
1 parent 3f73e0b commit 8d89d84
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 53 deletions.
87 changes: 50 additions & 37 deletions lua/osv/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -636,56 +636,69 @@ function M.wait_attach()

local stack_frames = {}
local levels = 1
local skip_firsts = true
while levels <= max_levels or max_levels == -1 do
local info = debug.getinfo(levels+start_frame)
local skip = 0

local inside_osv = false
while true do
local info = debug.getinfo(skip+levels+start_frame)
if not info then
break
end

local inside_osv = false
if skip_firsts then
if info.source:sub(1, 1) == '@' then
local source = info.source:sub(2)
local path = vim.fn.resolve(vim.fn.fnamemodify(source, ":p"))
if vim.fs.basename(path) == 'init.lua' then
local parent = vim.fs.dirname(path)
if parent and vim.fs.basename(parent) == "osv" then
inside_osv = true
end
local current_inside_osv = false
if info.source:sub(1, 1) == '@' then
local source = info.source:sub(2)
local path = vim.fn.resolve(vim.fn.fnamemodify(source, ":p"))
if vim.fs.basename(path) == 'init.lua' then
local parent = vim.fs.dirname(path)
if parent and vim.fs.basename(parent) == "osv" then
current_inside_osv = true
end
end
end

if not skip_firsts or not inside_osv then
local stack_frame = {}
stack_frame.id = frame_id
stack_frame.name = info.name or info.what
if info.source:sub(1, 1) == '@' then
local source = info.source:sub(2)
if #info.source >= 4 and info.source:sub(1,4) == "@vim" then
source = os.getenv("VIMRUNTIME") .. "/lua/" .. info.source:sub(2)
end
if inside_osv and not current_inside_osv then
break
end

inside_osv = current_inside_osv
skip = skip + 1
end


stack_frame.source = {
name = info.source,
path = vim.fn.resolve(vim.fn.fnamemodify(source, ":p")),
}
stack_frame.line = info.currentline
stack_frame.column = 0
else
-- Should be ignored by the client
stack_frame.line = 0
stack_frame.column = 0
end
while levels <= max_levels or max_levels == -1 do
local info = debug.getinfo(skip+levels+start_frame)
if not info then
break
end

local stack_frame = {}
stack_frame.id = frame_id
stack_frame.name = info.name or info.what
if info.source:sub(1, 1) == '@' then
local source = info.source:sub(2)
if #info.source >= 4 and info.source:sub(1,4) == "@vim" then
source = os.getenv("VIMRUNTIME") .. "/lua/" .. info.source:sub(2)
end


table.insert(stack_frames, stack_frame)
frames[frame_id] = levels+start_frame
frame_id = frame_id + 1
skip_firsts = false
stack_frame.source = {
name = info.source,
path = vim.fn.resolve(vim.fn.fnamemodify(source, ":p")),
}
stack_frame.line = info.currentline
stack_frame.column = 0
else
-- Should be ignored by the client
stack_frame.line = 0
stack_frame.column = 0
end

table.insert(stack_frames, stack_frame)
frames[frame_id] = skip+levels+start_frame
frame_id = frame_id + 1
skip_firsts = false

levels = levels + 1
end

Expand Down
47 changes: 31 additions & 16 deletions src/handlers/stack_trace.lua.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,21 @@ local frames = {}

@parse_debug_traces+=
local levels = 1
local skip_firsts = true
local skip = 0

@skip_internal_frames

while levels <= max_levels or max_levels == -1 do
local info = debug.getinfo(levels+start_frame)
local info = debug.getinfo(skip+levels+start_frame)
if not info then
break
end

local inside_osv = false
if skip_firsts then
@check_if_stack_frame_is_inside_osv
end

if not skip_firsts or not inside_osv then
@fill_stack_frame_with_info
table.insert(stack_frames, stack_frame)
frames[frame_id] = levels+start_frame
frame_id = frame_id + 1
skip_firsts = false
end
@fill_stack_frame_with_info
table.insert(stack_frames, stack_frame)
frames[frame_id] = skip+levels+start_frame
frame_id = frame_id + 1
skip_firsts = false

levels = levels + 1
end
Expand Down Expand Up @@ -73,14 +69,33 @@ if #info.source >= 4 and info.source:sub(1,4) == "@vim" then
end


@check_if_stack_frame_is_inside_osv+=
@skip_internal_frames+=
local inside_osv = false
while true do
local info = debug.getinfo(skip+levels+start_frame)
if not info then
break
end

local current_inside_osv = false
@check_if_inside_osv

if inside_osv and not current_inside_osv then
break
end

inside_osv = current_inside_osv
skip = skip + 1
end

@check_if_inside_osv+=
if info.source:sub(1, 1) == '@' then
local source = info.source:sub(2)
local path = vim.fn.resolve(vim.fn.fnamemodify(source, ":p"))
if vim.fs.basename(path) == 'init.lua' then
local parent = vim.fs.dirname(path)
if parent and vim.fs.basename(parent) == "osv" then
inside_osv = true
current_inside_osv = true
end
end
end

0 comments on commit 8d89d84

Please sign in to comment.