@@ -9,7 +9,8 @@ import * as sb from "smart-buffer";
99import {
1010 LuaAttachMessage , DMReqInitialize , DebugMessageId , DMMessage , DMLoadScript ,
1111 DMAddBreakpoint , DMBreak , StackNodeContainer , StackRootNode , IStackNode ,
12- DMReqEvaluate , DMRespEvaluate , ExprEvaluator , LoadedScript , LoadedScriptManager
12+ DMReqEvaluate , DMRespEvaluate , ExprEvaluator , LoadedScript , LoadedScriptManager ,
13+ DMDelBreakpoint
1314} from './AttachProtol' ;
1415import { ByteArray } from './ByteArray' ;
1516import * as path from 'path' ;
@@ -37,6 +38,7 @@ interface EmmyLaunchRequesetArguments extends DebugProtocol.LaunchRequestArgumen
3738
3839interface EmmyBreakpoint {
3940 id : number ;
41+ scriptIndex : number ;
4042 line : number ;
4143}
4244
@@ -215,8 +217,9 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
215217 const bpList = this . breakpoints . get ( filePath ) ;
216218 if ( bpList ) {
217219 for ( let index = 0 ; index < bpList . length ; index ++ ) {
218- const bp = bpList [ index ] ;
219- this . send ( new DMAddBreakpoint ( script . index , this . convertClientLineToDebugger ( bp . line ) ) ) ;
220+ const ebp = bpList [ index ] ;
221+ ebp . scriptIndex = script . index ;
222+ this . send ( new DMAddBreakpoint ( script . index , this . convertClientLineToDebugger ( ebp . line ) ) ) ;
220223 }
221224 }
222225 } else {
@@ -272,30 +275,45 @@ export class AttachDebugSession extends LoggingDebugSession implements ExprEvalu
272275 let lines = args . breakpoints || [ ] ;
273276 const path = this . normalize ( < string > args . source . path ) ;
274277
275- let bpList = this . breakpoints . get ( path ) ;
276- if ( ! bpList ) {
277- bpList = new Array < EmmyBreakpoint > ( ) ;
278- this . breakpoints . set ( path , bpList ) ;
278+ let existBps = this . breakpoints . get ( path ) ;
279+ const existMap = new Map < number , EmmyBreakpoint > ( ) ;
280+ if ( existBps ) {
281+ existBps . forEach ( bp => existMap . set ( bp . line , bp ) ) ;
279282 }
280- const bps = bpList ;
283+ const bps = < EmmyBreakpoint [ ] > [ ] ;
281284
282285 const breakpoints = new Array < DebugProtocol . Breakpoint > ( ) ;
283286 lines . forEach ( bp => {
284287 const bpk = < DebugProtocol . Breakpoint > new Breakpoint ( true , bp . line ) ;
285288 bpk . id = ++ breakpointId ;
286289 breakpoints . push ( bpk ) ;
287-
288- bps . push ( { id : breakpointId , line : bp . line } ) ;
289290
290- //send
291- const script = this . findScript ( path ) ;
292- if ( script ) {
293- this . send ( new DMAddBreakpoint ( script . index , this . convertClientLineToDebugger ( bp . line ) ) ) ;
291+ const exist = existMap . get ( bp . line ) ;
292+ if ( exist ) {
293+ bps . push ( exist ) ;
294+ existMap . delete ( bp . line ) ;
295+ } else {
296+ const ebp : EmmyBreakpoint = { id : breakpointId , line : bp . line , scriptIndex : - 1 } ;
297+
298+ //send
299+ const script = this . findScript ( path ) ;
300+ if ( script ) {
301+ this . send ( new DMAddBreakpoint ( script . index , this . convertClientLineToDebugger ( bp . line ) ) ) ;
302+ ebp . scriptIndex = script . index ;
303+ }
304+ bps . push ( ebp ) ;
294305 }
295306 } ) ;
296307 response . body = {
297308 breakpoints : breakpoints
298309 } ;
310+
311+ this . breakpoints . set ( path , bps ) ;
312+ existMap . forEach ( ( v , k ) => {
313+ if ( v . scriptIndex > 0 ) {
314+ this . send ( new DMDelBreakpoint ( v . scriptIndex , this . convertClientLineToDebugger ( v . line ) ) ) ;
315+ }
316+ } ) ;
299317 this . sendResponse ( response ) ;
300318 }
301319
0 commit comments