Skip to content

Commit

Permalink
Add type annotations for setBreakoints; fix tests on nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
mfussenegger committed Aug 9, 2024
1 parent dcc85d1 commit b84e304
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lua/dap/breakpoints.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ function M.update(breakpoint)
end


function M.set_state(bufnr, lnum, state)
local ok, placements = pcall(vim.fn.sign_getplaced, bufnr, { group = ns; lnum = lnum; })
---@param bufnr integer
---@param state dap.Breakpoint
function M.set_state(bufnr, state)
local ok, placements = pcall(vim.fn.sign_getplaced, bufnr, { group = ns; lnum = state.line; })
if not ok then
return
end
local signs = placements[1].signs
local signs = (placements[1] or {}).signs
if not signs or next(signs) == nil then
return
end
Expand All @@ -80,7 +82,7 @@ function M.set_state(bufnr, lnum, state)
ns,
'DapBreakpointRejected',
bufnr,
{ lnum = lnum; priority = 21; }
{ lnum = state.line; priority = 21; }
)
end
end
Expand Down
2 changes: 2 additions & 0 deletions lua/dap/protocol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@
---@field algorithm "MD5"|"SHA1"|"SHA256"|"timestamp"
---@field checksum string

---@class dap.SetBreakpointsResponse
---@field breakpoints dap.Breakpoint[]

---@class dap.Breakpoint
---@field id? number
Expand Down
9 changes: 6 additions & 3 deletions lua/dap/session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -894,12 +894,14 @@ do
),
lines = vim.tbl_map(function(x) return x.line end, buf_bps);
}
self:request('setBreakpoints', payload, function(err1, resp)
---@param err1 dap.ErrorResponse
---@param resp dap.SetBreakpointsResponse
local function on_response(err1, resp)
if err1 then
utils.notify('Error setting breakpoints: ' .. utils.fmt_error(err1), vim.log.levels.ERROR)
elseif resp then
for _, bp in pairs(resp.breakpoints) do
breakpoints.set_state(bufnr, bp.line, bp)
breakpoints.set_state(bufnr, bp)
if not bp.verified then
log.info('Breakpoint unverified', bp)
end
Expand All @@ -909,7 +911,8 @@ do
if num_requests == 0 and on_done then
on_done()
end
end)
end
self:request('setBreakpoints', payload, on_response)
end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/debugpy_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('dap with debugpy', function()
}
local bp_lnum = 8
local bufnr = vim.fn.bufadd(program)
vim.fn.bufload(bufnr)
breakpoints.set({}, bufnr, bp_lnum)
local events = {}
local dummy_payload = nil
Expand Down

0 comments on commit b84e304

Please sign in to comment.