|
18 | 18 |
|
19 | 19 | import {
|
20 | 20 | DebugSession, InitializedEvent, OutputEvent, Thread, Source,
|
21 |
| - StoppedEvent, ContinuedEvent, StackFrame, TerminatedEvent, Breakpoint as AdapterBreakpoint, Event, ErrorDestination |
| 21 | + StoppedEvent, ContinuedEvent, StackFrame, TerminatedEvent, Event, ErrorDestination |
22 | 22 | } from 'vscode-debugadapter';
|
23 | 23 | import { DebugProtocol } from 'vscode-debugprotocol';
|
24 | 24 | import * as Fs from 'fs';
|
25 | 25 | import * as Path from 'path';
|
26 |
| -import { IAttachRequestArguments, SourceSendingOptions } from './IotjsDebuggerInterfaces'; |
| 26 | +import { IAttachRequestArguments, SourceSendingOptions, TemporaryBreakpoint } from './IotjsDebuggerInterfaces'; |
27 | 27 | import { JerryDebuggerClient, JerryDebuggerOptions } from './JerryDebuggerClient';
|
28 | 28 | import {
|
29 | 29 | JerryDebugProtocolDelegate, JerryDebugProtocolHandler, JerryMessageScriptParsed, JerryEvalResult,
|
30 | 30 | JerryMessageExceptionHit
|
31 | 31 | } from './JerryProtocolHandler';
|
32 | 32 | import { EVAL_RESULT_SUBTYPE, CLIENT as CLIENT_PACKAGE } from './JerryProtocolConstants';
|
| 33 | +import { Breakpoint } from './JerryBreakpoints'; |
33 | 34 |
|
34 | 35 | enum SOURCE_SENDING_STATES {
|
35 | 36 | NOP = 0,
|
@@ -76,8 +77,6 @@ class IotjsDebugSession extends DebugSession {
|
76 | 77 | ): void {
|
77 | 78 | this.log('initializeRequest');
|
78 | 79 |
|
79 |
| - this.sendEvent(new InitializedEvent()); |
80 |
| - |
81 | 80 | // This debug adapter implements the configurationDoneRequest.
|
82 | 81 | response.body.supportsConfigurationDoneRequest = true;
|
83 | 82 | response.body.supportsFunctionBreakpoints = false;
|
@@ -189,9 +188,10 @@ class IotjsDebugSession extends DebugSession {
|
189 | 188 | .catch(error => {
|
190 | 189 | this.log(error);
|
191 | 190 | this.sendErrorResponse(response, 0, error.message);
|
| 191 | + }) |
| 192 | + .then(() => { |
| 193 | + this.sendEvent(new InitializedEvent()); |
192 | 194 | });
|
193 |
| - |
194 |
| - this.sendEvent(new InitializedEvent()); |
195 | 195 | }
|
196 | 196 |
|
197 | 197 | protected launchRequest(response: DebugProtocol.LaunchResponse, args: DebugProtocol.LaunchRequestArguments): void {
|
@@ -272,45 +272,51 @@ class IotjsDebugSession extends DebugSession {
|
272 | 272 | ): Promise<void> {
|
273 | 273 | this.log('setBreakPointsRequest');
|
274 | 274 |
|
275 |
| - const filename = args.source.name; |
276 |
| - const clientLines = args.lines || []; |
| 275 | + const filename: string = args.source.name; |
| 276 | + const vscodeBreakpoints: DebugProtocol.Breakpoint[] = args.breakpoints!.map(b => ({verified: false, line: b.line})); |
277 | 277 |
|
278 | 278 | try {
|
279 |
| - const scriptId = this._protocolhandler.getScriptIdByName(filename); |
280 |
| - const activeBp = this._protocolhandler.getActiveBreakpointsByScriptId(scriptId); |
281 |
| - const activeBpLines = activeBp.map(b => b.line); |
282 |
| - |
283 |
| - const newBp = clientLines.filter(b => activeBpLines.indexOf(b) === -1); |
284 |
| - const removeBp = activeBpLines.filter(b => clientLines.indexOf(b) === -1); |
285 |
| - const persistingBp = clientLines.filter(b => newBp.indexOf(b) === -1); |
286 |
| - |
287 |
| - let newBreakpoints: DebugProtocol.Breakpoint[] = []; |
288 |
| - await Promise.all(newBp.map(async b => { |
289 |
| - const breakpoint = this._protocolhandler.findBreakpoint(scriptId, b); |
290 |
| - return await this._protocolhandler.updateBreakpoint(breakpoint, true) |
291 |
| - .then(() => <DebugProtocol.Breakpoint> new AdapterBreakpoint(true, b)); |
292 |
| - })) |
293 |
| - .then(breakpoints => { |
294 |
| - newBreakpoints = breakpoints; |
295 |
| - }); |
| 279 | + const scriptId: number = this._protocolhandler.getScriptIdByName(filename); |
| 280 | + const activeBps: Breakpoint[] = this._protocolhandler.getActiveBreakpointsByScriptId(scriptId); |
| 281 | + |
| 282 | + // Get the new breakpoints. |
| 283 | + const activeBpsLines: number[] = activeBps.map(b => b.line); |
| 284 | + const newBps: DebugProtocol.Breakpoint[] = vscodeBreakpoints.filter(b => activeBpsLines.indexOf(b.line) === -1); |
| 285 | + |
| 286 | + const newBreakpoints: TemporaryBreakpoint[] = await Promise.all(newBps.map(async (breakpoint, index) => { |
| 287 | + try { |
| 288 | + const jerryBreakpoint: Breakpoint = this._protocolhandler.findBreakpoint(scriptId, breakpoint.line); |
| 289 | + await this._protocolhandler.updateBreakpoint(jerryBreakpoint, true); |
| 290 | + return <TemporaryBreakpoint>{verified: true, line: breakpoint.line}; |
| 291 | + } catch (error) { |
| 292 | + this.log(error); |
| 293 | + return <TemporaryBreakpoint>{verified: false, line: breakpoint.line, message: (<Error>error).message}; |
| 294 | + } |
| 295 | + })); |
296 | 296 |
|
297 |
| - removeBp.forEach(async b => { |
298 |
| - const breakpoint = this._protocolhandler.findBreakpoint(scriptId, b); |
299 |
| - await this._protocolhandler.updateBreakpoint(breakpoint, false); |
300 |
| - }); |
| 297 | + // Get the persists breakpoints. |
| 298 | + const newBreakpointsLines: number[] = newBreakpoints.map(b => b.line); |
| 299 | + const persistingBreakpoints: TemporaryBreakpoint[] = vscodeBreakpoints |
| 300 | + .filter(b => newBreakpointsLines.indexOf(b.line) === -1) |
| 301 | + .map(b => ({verified: true, line: b.line})); |
301 | 302 |
|
302 |
| - const persistingBreakpoints = persistingBp.map(b => { |
303 |
| - return <DebugProtocol.Breakpoint> new AdapterBreakpoint(true, b); |
304 |
| - }); |
| 303 | + // Get the removalbe breakpoints. |
| 304 | + const vscodeBreakpointsLines: number[] = vscodeBreakpoints.map(b => b.line); |
| 305 | + const removeBps: Breakpoint[] = activeBps.filter(b => vscodeBreakpointsLines.indexOf(b.line) === -1); |
305 | 306 |
|
306 |
| - response.body = { |
307 |
| - breakpoints: [...persistingBreakpoints, ...newBreakpoints] |
308 |
| - }; |
| 307 | + removeBps.forEach(async b => { |
| 308 | + const jerryBreakpoint = this._protocolhandler.findBreakpoint(scriptId, b.line); |
| 309 | + await this._protocolhandler.updateBreakpoint(jerryBreakpoint, false); |
| 310 | + }); |
309 | 311 |
|
310 |
| - this.sendResponse(response); |
| 312 | + response.body = { breakpoints: [...persistingBreakpoints, ...newBreakpoints] }; |
311 | 313 | } catch (error) {
|
312 | 314 | this.log(error.message);
|
| 315 | + this.sendErrorResponse(response, error.message); |
| 316 | + return; |
313 | 317 | }
|
| 318 | + |
| 319 | + this.sendResponse(response); |
314 | 320 | }
|
315 | 321 |
|
316 | 322 | protected evaluateRequest(response: DebugProtocol.EvaluateResponse, args: DebugProtocol.EvaluateArguments): void {
|
|
0 commit comments