Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Support new StoppedEvent format -
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Mar 13, 2017
1 parent 6d402bb commit bf53059
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
39 changes: 9 additions & 30 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*--------------------------------------------------------*/

import {DebugProtocol} from 'vscode-debugprotocol';
import {StoppedEvent, InitializedEvent, TerminatedEvent, Handles, ContinuedEvent, BreakpointEvent, OutputEvent, Logger as logger} from 'vscode-debugadapter';
import {InitializedEvent, TerminatedEvent, Handles, ContinuedEvent, BreakpointEvent, OutputEvent, Logger as logger} from 'vscode-debugadapter';

import {ICommonRequestArgs, ILaunchRequestArgs, ISetBreakpointsArgs, ISetBreakpointsResponseBody, IStackTraceResponseBody,
IAttachRequestArgs, IScopesResponseBody, IVariablesResponseBody,
Expand All @@ -16,6 +16,7 @@ import Crdp from '../../crdp/crdp';
import {PropertyContainer, ScopeContainer, ExceptionContainer, isIndexedPropName} from './variables';
import * as Variables from './variables';
import {formatConsoleArguments, formatExceptionDetails} from './consoleHelper';
import {StoppedEvent2, ReasonType} from './stoppedEvent';

import * as errors from '../errors';
import * as utils from '../utils';
Expand Down Expand Up @@ -77,7 +78,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
private _exception: Crdp.Runtime.RemoteObject;
private _setBreakpointsRequestQ: Promise<any>;
private _expectingResumedEvent: boolean;
protected _expectingStopReason: string;
protected _expectingStopReason: ReasonType;
private _waitAfterStep = Promise.resolve();

private _frameHandles: Handles<Crdp.Debugger.CallFrame>;
Expand Down Expand Up @@ -110,7 +111,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {

private _initialSourceMapsP = Promise.resolve();

private _lastPauseState: { expecting: string; event: Crdp.Debugger.PausedEvent };
private _lastPauseState: { expecting: ReasonType; event: Crdp.Debugger.PausedEvent };

public constructor({ chromeConnection, lineColTransformer, sourceMapTransformer, pathTransformer }: IChromeDebugAdapterOpts, session: ChromeDebugSession) {
telemetry.setupEventHandler(e => session.sendEvent(e));
Expand Down Expand Up @@ -355,13 +356,13 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {

// We can tell when we've broken on an exception. Otherwise if hitBreakpoints is set, assume we hit a
// breakpoint. If not set, assume it was a step. We can't tell the difference between step and 'break on anything'.
let reason: string;
let reason: ReasonType;
let smartStepP = Promise.resolve(false);
if (notification.reason === 'exception') {
reason = 'exception';
this._exception = notification.data;
} else if (notification.reason === 'promiseRejection') {
reason = 'promise rejection';
reason = 'promise_rejection';
this._exception = notification.data;
} else if (notification.hitBreakpoints && notification.hitBreakpoints.length) {
reason = 'breakpoint';
Expand All @@ -384,7 +385,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
reason = expectingStopReason;
smartStepP = this.shouldSmartStep(this._currentPauseNotification.callFrames[0]);
} else {
reason = 'debugger';
reason = 'debugger_statement';
}

this._expectingStopReason = undefined;
Expand All @@ -403,7 +404,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
// Also with a timeout just to ensure things keep moving
const sendStoppedEvent = () => {
const exceptionText = this._exception && this._exception.description && utils.firstLine(this._exception.description);
return this._session.sendEvent(new StoppedEvent(this.stopReasonText(reason), /*threadId=*/ChromeDebugAdapter.THREAD_ID, exceptionText));
return this._session.sendEvent(new StoppedEvent2(reason, /*threadId=*/ChromeDebugAdapter.THREAD_ID, exceptionText));
};
return utils.promiseTimeout(this._currentStep, /*timeoutMs=*/300)
.then(sendStoppedEvent, sendStoppedEvent);
Expand All @@ -425,28 +426,6 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
return this._launchAttachArgs.sourceMaps && this._launchAttachArgs.smartStep;
}

private stopReasonText(reason: string): string {
const comment = ['https://github.com/Microsoft/vscode/issues/4568'];
switch (reason) {
case 'entry':
return utils.localize({ key: 'reason.entry', comment }, "entry");
case 'exception':
return utils.localize({ key: 'reason.exception', comment }, "exception");
case 'breakpoint':
return utils.localize({ key: 'reason.breakpoint', comment }, "breakpoint");
case 'debugger':
return utils.localize({ key: 'reason.debugger_statement', comment }, "debugger statement");
case 'frame_entry':
return utils.localize({ key: 'reason.restart', comment }, "frame entry");
case 'step':
return utils.localize({ key: 'reason.step', comment }, "step");
case 'user_request':
return utils.localize({ key: 'reason.user_request', comment }, "user request");
default:
return reason;
}
}

protected onResumed(): void {
this._currentPauseNotification = null;

Expand Down Expand Up @@ -1071,7 +1050,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {

public pause(): Promise<void> {
telemetry.reportEvent('pauseRequest');
this._expectingStopReason = 'user_request';
this._expectingStopReason = 'pause';
return this._currentStep = this.chrome.Debugger.pause()
.then(() => { });
}
Expand Down
43 changes: 43 additions & 0 deletions src/chrome/stoppedEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/

import {DebugProtocol} from 'vscode-debugprotocol';
import {StoppedEvent} from 'vscode-debugadapter';

import * as utils from '../utils';

export type ReasonType = 'step' | 'breakpoint' | 'exception' | 'pause' | 'entry' | 'debugger_statement' | 'frame_entry' | 'promise_rejection';

export class StoppedEvent2 extends StoppedEvent {
constructor(reason: ReasonType, threadId: number, exception_text?: string) {
super(reason, threadId, exception_text);

switch (reason) {
case 'step':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.step', "Paused on step");
break;
case 'breakpoint':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.breakpoint', "Paused on breakpoint");
break;
case 'exception':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.exception', "Paused on exception");
break;
case 'pause':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.user_request', "Paused on user request");
break;
case 'entry':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.entry', "Paused on entry");
break;
case 'debugger_statement':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.debugger_statement', "Paused on debugger statement");
break;
case 'frame_entry':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.restart', "Paused on frame entry");
break;
case 'promise_rejection':
(<DebugProtocol.StoppedEvent>this).body.description = utils.localize('reason.description.promiseRejection', "Paused on promise rejection");
break;
}
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {ChromeDebugAdapter} from './chrome/chromeDebugAdapter';
import {ChromeDebugSession, IChromeDebugSessionOpts} from './chrome/chromeDebugSession';
import * as chromeTargetDiscoveryStrategy from './chrome/chromeTargetDiscoveryStrategy';
import * as chromeUtils from './chrome/chromeUtils';
import * as stoppedEvent from './chrome/stoppedEvent';

import {BasePathTransformer} from './transformers/basePathTransformer';
import {UrlPathTransformer} from './transformers/urlPathTransformer';
Expand All @@ -29,6 +30,7 @@ export {
chromeTargetDiscoveryStrategy,
chromeUtils,
logger,
stoppedEvent,

UrlPathTransformer,
BasePathTransformer,
Expand Down

0 comments on commit bf53059

Please sign in to comment.