Add type annotations for setBreakoints; fix tests on nightly

This commit is contained in:
Mathias Fussenegger 2024-08-09 10:17:46 +02:00 committed by Mathias Fußenegger
parent dcc85d12d6
commit b84e30402f
4 changed files with 15 additions and 7 deletions

View file

@ -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
@ -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

View file

@ -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

View file

@ -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
@ -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

View file

@ -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