From 1715d82b9c6122ec12b8ab09e9a0b093650e889b Mon Sep 17 00:00:00 2001 From: roblou Date: Wed, 11 Jan 2017 15:49:54 -0800 Subject: [PATCH] Use 'deemphasize' UI for smartStep as well - Microsoft/vscode-chrome-debug-core#150 --- src/chrome/chromeDebugAdapter.ts | 18 ++++++----- test/chrome/chromeDebugAdapter.test.ts | 45 +++++++++++++------------- test/mocks/transformerMocks.ts | 3 ++ 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/chrome/chromeDebugAdapter.ts b/src/chrome/chromeDebugAdapter.ts index 57f3fd871..123a3fbc5 100644 --- a/src/chrome/chromeDebugAdapter.ts +++ b/src/chrome/chromeDebugAdapter.ts @@ -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 { + private async shouldSmartStep(frame: Crdp.Debugger.CallFrame): Promise { 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 { @@ -986,7 +986,7 @@ export abstract class ChromeDebugAdapter implements IDebugAdapter { .then(() => { }); } - public stackTrace(args: DebugProtocol.StackTraceArguments): IStackTraceResponseBody { + public async stackTrace(args: DebugProtocol.StackTraceArguments): Promise { // Only process at the requested number of frames, if 'levels' is specified let stack = this._currentStack; if (args.levels) { @@ -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; } diff --git a/test/chrome/chromeDebugAdapter.test.ts b/test/chrome/chromeDebugAdapter.test.ts index 457c697f6..fb0503c37 100644 --- a/test/chrome/chromeDebugAdapter.test.ts +++ b/test/chrome/chromeDebugAdapter.test.ts @@ -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', {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', {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', {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', {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); }); }); diff --git a/test/mocks/transformerMocks.ts b/test/mocks/transformerMocks.ts index 8a1ecfd50..371d01915 100644 --- a/test/mocks/transformerMocks.ts +++ b/test/mocks/transformerMocks.ts @@ -20,6 +20,9 @@ export function getMockSourceMapTransformer(): Mock { 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; }