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

Commit

Permalink
Use 'deemphasize' UI for smartStep as well -
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Jan 11, 2017
1 parent a2aa347 commit 1715d82
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
18 changes: 10 additions & 8 deletions src/chrome/chromeDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,14 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
}).catch(err => logger.error('Problem while smart stepping: ' + (err && err.stack) ? err.stack : err));
}

private shouldSmartStep(frame: Crdp.Debugger.CallFrame): Promise<boolean> {
private async shouldSmartStep(frame: Crdp.Debugger.CallFrame): Promise<boolean> {
if (!this._launchAttachArgs.sourceMaps) return Promise.resolve(false);

const stackFrame = this.callFrameToStackFrame(frame);
const clientPath = this._pathTransformer.getClientPathFromTargetPath(stackFrame.source.path) || stackFrame.source.path;
return this._sourceMapTransformer.mapToAuthored(clientPath, frame.location.lineNumber, frame.location.columnNumber).then(mapping => {
return !mapping;
});
const mapping = await this._sourceMapTransformer.mapToAuthored(clientPath, frame.location.lineNumber, frame.location.columnNumber);

return !mapping;
}

private stopReasonText(reason: string): string {
Expand Down Expand Up @@ -986,7 +986,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
.then(() => { });
}

public stackTrace(args: DebugProtocol.StackTraceArguments): IStackTraceResponseBody {
public async stackTrace(args: DebugProtocol.StackTraceArguments): Promise<IStackTraceResponseBody> {
// Only process at the requested number of frames, if 'levels' is specified
let stack = this._currentStack;
if (args.levels) {
Expand All @@ -1000,13 +1000,15 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter {
this._sourceMapTransformer.stackTraceResponse(stackTraceResponse);
this._lineColTransformer.stackTraceResponse(stackTraceResponse);

stackTraceResponse.stackFrames.forEach(frame => {
await Promise.all(stackTraceResponse.stackFrames.map(async (frame, i) => {
if (frame.source.path && this.shouldSkipSource(frame.source.path)) {
// frame.name = frame.name + ' (skipped)';
frame.source.name = `(skipped) ${frame.source.name}`;
frame.source.presentationHint = 'deemphasize';
} else if (await this.shouldSmartStep(stack[i])) {
frame.source.name = `(smartStep) ${frame.source.name}`;
frame.source.presentationHint = 'deemphasize';
}
});
}));

return stackTraceResponse;
}
Expand Down
45 changes: 23 additions & 22 deletions test/chrome/chromeDebugAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,28 +442,29 @@ suite('ChromeDebugAdapter', () => {
});

suite('Debugger.pause', () => {
test('returns the same sourceReferences for the same scripts', () => {
return chromeDebugAdapter.attach(ATTACH_ARGS).then(() => {
const scriptId = 'script1';
const location: Crdp.Debugger.Location = { lineNumber: 0, columnNumber: 0, scriptId };
const callFrame = { callFrameId: 'id1', location };
emitScriptParsed('', scriptId);
mockEventEmitter.emit('Debugger.paused', <Crdp.Debugger.PausedEvent>{callFrames: [callFrame, callFrame]});

const stackFrames = chromeDebugAdapter.stackTrace({ threadId: THREAD_ID }).stackFrames;

// Should have two stack frames with the same sourceReferences
assert.equal(stackFrames.length, 2);
assert.equal(stackFrames[0].source.sourceReference, stackFrames[1].source.sourceReference);
const sourceReference = stackFrames[0].source.sourceReference;

// If it pauses a second time, and we request another stackTrace, should have the same result
mockEventEmitter.emit('Debugger.paused', <Crdp.Debugger.PausedEvent>{callFrames: [callFrame, callFrame]});
const stackFrames2 = chromeDebugAdapter.stackTrace({ threadId: THREAD_ID }).stackFrames;
assert.equal(stackFrames2.length, 2);
assert.equal(stackFrames2[0].source.sourceReference, sourceReference);
assert.equal(stackFrames2[1].source.sourceReference, sourceReference);
});
test('returns the same sourceReferences for the same scripts', async () => {
await chromeDebugAdapter.attach(ATTACH_ARGS);

const scriptId = 'script1';
const location: Crdp.Debugger.Location = { lineNumber: 0, columnNumber: 0, scriptId };
const callFrame = { callFrameId: 'id1', location };
emitScriptParsed('', scriptId);
mockEventEmitter.emit('Debugger.paused', <Crdp.Debugger.PausedEvent>{callFrames: [callFrame, callFrame]});

const { stackFrames } = await chromeDebugAdapter.stackTrace({ threadId: THREAD_ID });

// Should have two stack frames with the same sourceReferences
assert.equal(stackFrames.length, 2);
assert.equal(stackFrames[0].source.sourceReference, stackFrames[1].source.sourceReference);
const sourceReference = stackFrames[0].source.sourceReference;

// If it pauses a second time, and we request another stackTrace, should have the same result
mockEventEmitter.emit('Debugger.paused', <Crdp.Debugger.PausedEvent>{callFrames: [callFrame, callFrame]});
const { stackFrames: stackFrames2 } = await chromeDebugAdapter.stackTrace({ threadId: THREAD_ID });

assert.equal(stackFrames2.length, 2);
assert.equal(stackFrames2[0].source.sourceReference, sourceReference);
assert.equal(stackFrames2[1].source.sourceReference, sourceReference);
});
});

Expand Down
3 changes: 3 additions & 0 deletions test/mocks/transformerMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export function getMockSourceMapTransformer(): Mock<BaseSourceMapTransformer> {
mock.setup(m => m.getGeneratedPathFromAuthoredPath(It.isAnyString()))
.returns(somePath => Promise.resolve(somePath));

mock.setup(m => m.mapToAuthored(It.isAnyString(), It.isAnyNumber(), It.isAnyNumber()))
.returns(somePath => Promise.resolve(somePath));

return mock;
}

Expand Down

0 comments on commit 1715d82

Please sign in to comment.