11local api = vim .api
22local non_empty = require (' dap.utils' ).non_empty
33
4- local bp_by_sign = {}
4+ --- @class dap.bp
5+ --- @field buf integer
6+ --- @field line integer
7+ --- @field condition string ?
8+ --- @field logMessage string ?
9+ --- @field hitCondition string ?
10+ --- @field state dap.Breakpoint ?
11+
12+ --- @type table<integer , table<integer , dap.bp>> buffer → sign id → bp
13+ local bp_by_sign_by_buf = {}
514local ns = ' dap_breakpoints'
615local M = {}
716
@@ -21,9 +30,9 @@ local function get_breakpoint_signs(bufexpr)
2130 return result
2231end
2332
24-
33+ --- @param bp dap.bp
2534local function get_sign_name (bp )
26- if bp .verified == false then
35+ if bp .state and bp . state . verified == false then
2736 return ' DapBreakpointRejected'
2837 elseif non_empty (bp .condition ) then
2938 return ' DapBreakpointCondition'
3847--- @param breakpoint dap.Breakpoint
3948function M .update (breakpoint )
4049 assert (breakpoint .id , " To update a breakpoint it must have an id property" )
41- for sign_id , bp in pairs (bp_by_sign ) do
42- if bp .state and bp .state .id == breakpoint .id then
43- local verified_changed =
44- bp .state .verified == false and breakpoint .verified
45- or breakpoint .verified == false and bp .state .verified
46- if verified_changed then
47- vim .fn .sign_place (
48- sign_id ,
49- ns ,
50- get_sign_name (bp ),
51- bp .buf ,
52- { lnum = bp .line ; priority = 21 ; }
53- )
50+ for _ , bp_by_sign in pairs (bp_by_sign_by_buf ) do
51+ for sign_id , bp in pairs (bp_by_sign ) do
52+ if bp .state and bp .state .id == breakpoint .id then
53+ local verified_changed = bp .state .verified ~= breakpoint .verified
54+ bp .state .verified = breakpoint .verified
55+ bp .state .message = breakpoint .message
56+ if verified_changed then
57+ vim .fn .sign_place (
58+ sign_id ,
59+ ns ,
60+ get_sign_name (bp ),
61+ bp .buf ,
62+ { lnum = bp .line ; priority = 21 ; }
63+ )
64+ end
65+ return
5466 end
55- bp .state .verified = breakpoint .verified
56- bp .state .message = breakpoint .message
57- return
5867 end
5968 end
6069end
@@ -72,7 +81,7 @@ function M.set_state(bufnr, state)
7281 return
7382 end
7483 for _ , sign in pairs (signs ) do
75- local bp = bp_by_sign [sign .id ]
84+ local bp = bp_by_sign_by_buf [ bufnr ] [sign .id ]
7685 if bp then
7786 bp .state = state
7887 end
@@ -95,7 +104,7 @@ function M.remove(bufnr, lnum)
95104 if signs and # signs > 0 then
96105 for _ , sign in pairs (signs ) do
97106 vim .fn .sign_unplace (ns , { buffer = bufnr ; id = sign .id ; })
98- bp_by_sign [sign .id ] = nil
107+ bp_by_sign_by_buf [ bufnr ] [sign .id ] = nil
99108 end
100109 return true
101110 else
@@ -104,11 +113,13 @@ function M.remove(bufnr, lnum)
104113end
105114
106115function M .remove_by_id (id )
107- for sign_id , bp in pairs (bp_by_sign ) do
108- if bp .state and bp .state .id == id then
109- vim .fn .sign_unplace (ns , { buffer = bp .buf , id = sign_id , })
110- bp_by_sign [sign_id ] = nil
111- return
116+ for _ , bp_by_sign in pairs (bp_by_sign_by_buf ) do
117+ for sign_id , bp in pairs (bp_by_sign ) do
118+ if bp .state and bp .state .id == id then
119+ vim .fn .sign_unplace (ns , { buffer = bp .buf , id = sign_id , })
120+ bp_by_sign_by_buf [bp .buf ][sign_id ] = nil
121+ return
122+ end
112123 end
113124 end
114125end
@@ -120,8 +131,9 @@ function M.toggle(opts, bufnr, lnum)
120131 if M .remove (bufnr , lnum ) and not opts .replace then
121132 return
122133 end
123- local bp = {
134+ local bp = { --- @type dap.bp
124135 buf = bufnr ,
136+ line = lnum ,
125137 condition = opts .condition ,
126138 logMessage = opts .log_message ,
127139 hitCondition = opts .hit_condition
@@ -135,7 +147,10 @@ function M.toggle(opts, bufnr, lnum)
135147 { lnum = lnum ; priority = 21 ; }
136148 )
137149 if sign_id ~= - 1 then
138- bp_by_sign [sign_id ] = bp
150+ if not bp_by_sign_by_buf [bufnr ] then
151+ bp_by_sign_by_buf [bufnr ] = {}
152+ end
153+ bp_by_sign_by_buf [bufnr ][sign_id ] = bp
139154 end
140155end
141156
@@ -159,7 +174,7 @@ function M.get(bufexpr)
159174 local bufnr = buf_bp_signs .bufnr
160175 result [bufnr ] = breakpoints
161176 for _ , bp in pairs (buf_bp_signs .signs ) do
162- local bp_entry = bp_by_sign [bp .id ] or {}
177+ local bp_entry = bp_by_sign_by_buf [ bufnr ] [bp .id ] or {}
163178 table.insert (breakpoints , {
164179 line = bp .lnum ;
165180 condition = bp_entry .condition ;
175190
176191function M .clear ()
177192 vim .fn .sign_unplace (ns )
178- bp_by_sign = {}
193+ bp_by_sign_by_buf = {}
179194end
180195
181196
0 commit comments