From 9c79c92d0ef9d07687f2302a6b54b53d3c224203 Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Fri, 10 Mar 2017 16:31:52 +0100 Subject: [PATCH] support StoppedEvent's new 'description' attribute; fixes #133 --- npm-shrinkwrap.json | 8 ++-- package.json | 6 +-- src/node/nodeDebug.ts | 82 +++++++++++++++++++-------------- src/tests/adapter.test.ts | 2 +- src/tests/pathUtilities.test.ts | 2 +- 5 files changed, 56 insertions(+), 44 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 01457199..b23d228a 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -100,14 +100,14 @@ "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz" }, "vscode-debugadapter": { - "version": "1.18.0-pre.2", + "version": "1.18.0-pre.3", "from": "vscode-debugadapter@>=1.18.0 <2.0.0", - "resolved": "https://registry.npmjs.org/vscode-debugadapter/-/vscode-debugadapter-1.18.0-pre.2.tgz" + "resolved": "https://registry.npmjs.org/vscode-debugadapter/-/vscode-debugadapter-1.18.0-pre.3.tgz" }, "vscode-debugprotocol": { - "version": "1.18.0-pre.0", + "version": "1.18.0-pre.1", "from": "vscode-debugprotocol@>=1.18.0 <2.0.0", - "resolved": "https://registry.npmjs.org/vscode-debugprotocol/-/vscode-debugprotocol-1.18.0-pre.0.tgz" + "resolved": "https://registry.npmjs.org/vscode-debugprotocol/-/vscode-debugprotocol-1.18.0-pre.1.tgz" }, "vscode-nls": { "version": "2.0.1", diff --git a/package.json b/package.json index 8bdf3a0d..875a0eaf 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "node-debug", "displayName": "Node Debug", - "version": "1.11.3", + "version": "1.11.4", "publisher": "ms-vscode", "description": "%extension.description%", "icon": "images/node-debug-icon.svg", @@ -28,8 +28,8 @@ "ms-vscode.node-debug2" ], "dependencies": { - "vscode-debugprotocol": "^1.18.0-pre.0", - "vscode-debugadapter": "^1.18.0-pre.2", + "vscode-debugprotocol": "^1.18.0-pre.1", + "vscode-debugadapter": "^1.18.0-pre.3", "source-map": "0.5.6", "vscode-nls": "^2.0.1", "request-light": "^0.1.0", diff --git a/src/node/nodeDebug.ts b/src/node/nodeDebug.ts index 2b17988e..8e02300f 100644 --- a/src/node/nodeDebug.ts +++ b/src/node/nodeDebug.ts @@ -166,6 +166,39 @@ export class ScopeContainer implements VariableContainer { } } +type ReasonType = 'step' | 'breakpoint' | 'exception' | 'pause' | 'entry' | 'debugger_statement' | 'frame_entry'; + +class StoppedEvent2 extends StoppedEvent { + + constructor(reason: ReasonType, threadId: number, exception_text?: string) { + super(reason, threadId, exception_text); + + switch (reason) { + case 'step': + (this).body.description = localize('reason.description.step', "Paused on step"); + break; + case 'breakpoint': + (this).body.description = localize('reason.description.breakpoint', "Paused on breakpoint"); + break; + case 'exception': + (this).body.description = localize('reason.description.exception', "Paused on exception"); + break; + case 'pause': + (this).body.description = localize('reason.description.user_request', "Paused on user request"); + break; + case 'entry': + (this).body.description = localize('reason.description.entry', "Paused on entry"); + break; + case 'debugger_statement': + (this).body.description = localize('reason.description.debugger_statement', "Paused on debugger statement"); + break; + case 'frame_entry': + (this).body.description = localize('reason.description.restart', "Paused on frame entry"); + break; + } + } +} + class Script { contents: string; sourceMap: SourceMap; @@ -446,7 +479,7 @@ export class NodeDebugSession extends DebugSession { private _handleNodeBreakEvent(eventBody: V8EventBody) : void { let isEntry = false; - let reason: string | undefined; + let reason: ReasonType | undefined; // in order to identify reject calls and debugger statements extract source at current location let source: string | null = null; @@ -475,7 +508,7 @@ export class NodeDebugSession extends DebugSession { // remember exception this._exception = eventBody.exception; - this._handleNodeBreakEvent2(this._reasonText('exception'), isEntry, eventBody.exception.text); + this._handleNodeBreakEvent2('exception', isEntry, eventBody.exception.text); return; } @@ -491,7 +524,7 @@ export class NodeDebugSession extends DebugSession { if (!this._gotEntryEvent && id === 1) { // 'stop on entry point' is implemented as a breakpoint with id 1 isEntry = true; this.log('la', '_analyzeBreak: suppressed stop-on-entry event'); - reason = this._reasonText('entry'); + reason = 'entry'; this._rememberEntryLocation(eventBody.script.name, eventBody.sourceLine, eventBody.sourceColumn); } else { let ibp = this._hitCounts.get(id); @@ -503,7 +536,7 @@ export class NodeDebugSession extends DebugSession { } } - reason = this._reasonText('breakpoint'); + reason = 'breakpoint'; } } } @@ -511,7 +544,7 @@ export class NodeDebugSession extends DebugSession { // is debugger statement? if (!reason) { if (source && source.indexOf('debugger') === 0) { - reason = this._reasonText('debugger'); + reason = 'debugger_statement'; this._gotDebuggerEvent = true; } } @@ -521,9 +554,9 @@ export class NodeDebugSession extends DebugSession { if (this._restartFramePending) { this._restartFramePending = false; - reason = this._reasonText('frame_entry'); + reason = 'frame_entry'; } else { - reason = this._reasonText('step'); + reason = 'step'; } if (!this._disableSkipFiles) { @@ -534,7 +567,7 @@ export class NodeDebugSession extends DebugSession { this._node.command('continue', { stepaction: 'in' }); this._smartStepCount++; } else { - this._handleNodeBreakEvent2(reason, isEntry); + this._handleNodeBreakEvent2(reason, isEntry); } }); return; @@ -545,29 +578,8 @@ export class NodeDebugSession extends DebugSession { this._handleNodeBreakEvent2(reason, isEntry); } - private _reasonText(reason: string) { - switch (reason) { - case 'entry': - return localize({ key: 'reason.entry', comment: ['https://github.com/Microsoft/vscode/issues/4568'] }, "entry"); - case 'exception': - return localize({ key: 'reason.exception', comment: ['https://github.com/Microsoft/vscode/issues/4568'] }, "exception"); - case 'breakpoint': - return localize({ key: 'reason.breakpoint', comment: ['https://github.com/Microsoft/vscode/issues/4568'] }, "breakpoint"); - case 'debugger': - return localize({ key: 'reason.debugger_statement', comment: ['https://github.com/Microsoft/vscode/issues/4568'] }, "debugger statement"); - case 'frame_entry': - return localize({ key: 'reason.restart', comment: ['https://github.com/Microsoft/vscode/issues/4568'] }, "frame entry"); - case 'step': - return localize({ key: 'reason.step', comment: ['https://github.com/Microsoft/vscode/issues/4568'] }, "step"); - case 'user_request': - return localize({ key: 'reason.user_request', comment: ['https://github.com/Microsoft/vscode/issues/4568'] }, "user request"); - default: - return reason; - } - } - - private _handleNodeBreakEvent2(reason: string, isEntry: boolean, exception_text?: string) { - this._lastStoppedEvent = new StoppedEvent(reason, NodeDebugSession.DUMMY_THREAD_ID, exception_text); + private _handleNodeBreakEvent2(reason: ReasonType, isEntry: boolean, exception_text?: string) { + this._lastStoppedEvent = new StoppedEvent2(reason, NodeDebugSession.DUMMY_THREAD_ID, exception_text); if (!isEntry) { if (this._smartStepCount > 0) { @@ -1394,7 +1406,7 @@ export class NodeDebugSession extends DebugSession { if (this._stopOnEntry) { // user has requested 'stop on entry' so send out a stop-on-entry event this.log('la', '_startInitialize2: fire stop-on-entry event'); - this.sendEvent(new StoppedEvent(this._reasonText('entry'), NodeDebugSession.DUMMY_THREAD_ID)); + this.sendEvent(new StoppedEvent2('entry', NodeDebugSession.DUMMY_THREAD_ID)); } else { // since we are stopped but UI doesn't know about this, remember that we later do the right thing in configurationDoneRequest() @@ -1969,13 +1981,13 @@ export class NodeDebugSession extends DebugSession { if (this._needBreakpointEvent) { // we have to break on entry this._needBreakpointEvent = false; info = 'fire breakpoint event'; - this.sendEvent(new StoppedEvent(this._reasonText('breakpoint'), NodeDebugSession.DUMMY_THREAD_ID)); + this.sendEvent(new StoppedEvent2('breakpoint', NodeDebugSession.DUMMY_THREAD_ID)); } if (this._needDebuggerEvent) { // we have to break on entry this._needDebuggerEvent = false; info = 'fire debugger statement event'; - this.sendEvent(new StoppedEvent(this._reasonText('debugger'), NodeDebugSession.DUMMY_THREAD_ID)); + this.sendEvent(new StoppedEvent2('debugger_statement', NodeDebugSession.DUMMY_THREAD_ID)); } this.log('la', `configurationDoneRequest: ${info}`); @@ -3107,7 +3119,7 @@ export class NodeDebugSession extends DebugSession { this._node.command('suspend', null, (nodeResponse) => { if (nodeResponse.success) { this._stopped('pause'); - this._lastStoppedEvent = new StoppedEvent(this._reasonText('user_request'), NodeDebugSession.DUMMY_THREAD_ID); + this._lastStoppedEvent = new StoppedEvent2('pause', NodeDebugSession.DUMMY_THREAD_ID); this.sendResponse(response); this.sendEvent(this._lastStoppedEvent); } else { diff --git a/src/tests/adapter.test.ts b/src/tests/adapter.test.ts index 5c28ee7f..2a1d9098 100644 --- a/src/tests/adapter.test.ts +++ b/src/tests/adapter.test.ts @@ -93,7 +93,7 @@ suite('Node Debug Adapter', () => { return Promise.all([ dc.configurationSequence(), dc.launch({ program: PROGRAM }), - dc.assertStoppedLocation('debugger statement', { path: PROGRAM, line: DEBUGGER_LINE } ) + dc.assertStoppedLocation('debugger_statement', { path: PROGRAM, line: DEBUGGER_LINE } ) ]); }); diff --git a/src/tests/pathUtilities.test.ts b/src/tests/pathUtilities.test.ts index e3b1771a..874b5096 100644 --- a/src/tests/pathUtilities.test.ts +++ b/src/tests/pathUtilities.test.ts @@ -237,7 +237,7 @@ suite('pathUtilities', () => { }); - suite.only('extendObject', () => { + suite('extendObject', () => { test('extend', () => { assert.deepEqual(PathUtils.extendObject({ foo: "bar" }, { abc: 123 }), { foo: "bar", abc: 123 });