From 97f7bdd677804456e28bb1dd51d69bf724aafa41 Mon Sep 17 00:00:00 2001 From: isidor Date: Mon, 16 May 2016 16:01:35 +0200 Subject: [PATCH] debug: allow to set focussed thread with no call stack fixes #6214 --- .../debug/browser/debugEditorModelManager.ts | 5 +++-- .../parts/debug/common/debugViewModel.ts | 6 ++++-- .../parts/debug/electron-browser/debugService.ts | 15 ++++++++++----- .../debug/test/common/debugViewModel.test.ts | 4 ++-- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts index 9b163317f94..93407a49c27 100644 --- a/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts +++ b/src/vs/workbench/parts/debug/browser/debugEditorModelManager.ts @@ -134,13 +134,14 @@ export class DebugEditorModelManager implements IWorkbenchContribution { private createCallStackDecorations(modelUrlStr: string): editorcommon.IModelDeltaDecoration[] { const result: editorcommon.IModelDeltaDecoration[] = []; const focusedStackFrame = this.debugService.getViewModel().getFocusedStackFrame(); + const focusedThreadId = this.debugService.getViewModel().getFocusedThreadId(); const allThreads = this.debugService.getModel().getThreads(); - if (!focusedStackFrame || !allThreads[focusedStackFrame.threadId] || !allThreads[focusedStackFrame.threadId].getCachedCallStack()) { + if (!focusedStackFrame || !allThreads[focusedThreadId] || !allThreads[focusedThreadId].getCachedCallStack()) { return result; } // only show decorations for the currently focussed thread. - const thread = allThreads[focusedStackFrame.threadId]; + const thread = allThreads[focusedThreadId]; thread.getCachedCallStack().filter(sf => sf.source.uri.toString() === modelUrlStr).forEach(sf => { const wholeLineRange = createRange(sf.lineNumber, sf.column, sf.lineNumber, Number.MAX_VALUE); diff --git a/src/vs/workbench/parts/debug/common/debugViewModel.ts b/src/vs/workbench/parts/debug/common/debugViewModel.ts index 2701081a441..5de4b50287f 100644 --- a/src/vs/workbench/parts/debug/common/debugViewModel.ts +++ b/src/vs/workbench/parts/debug/common/debugViewModel.ts @@ -9,6 +9,7 @@ import debug = require('vs/workbench/parts/debug/common/debug'); export class ViewModel implements debug.IViewModel { private focusedStackFrame: debug.IStackFrame; + private focusedThread: debug.IThread; private selectedExpression: debug.IExpression; private selectedFunctionBreakpoint: debug.IFunctionBreakpoint; private _onDidFocusStackFrame: Emitter; @@ -31,8 +32,9 @@ export class ViewModel implements debug.IViewModel { return this.focusedStackFrame; } - public setFocusedStackFrame(focusedStackFrame: debug.IStackFrame): void { + public setFocusedStackFrame(focusedStackFrame: debug.IStackFrame, focusedThread: debug.IThread): void { this.focusedStackFrame = focusedStackFrame; + this.focusedThread = focusedThread; this._onDidFocusStackFrame.fire(focusedStackFrame); } @@ -41,7 +43,7 @@ export class ViewModel implements debug.IViewModel { } public getFocusedThreadId(): number { - return this.focusedStackFrame ? this.focusedStackFrame.threadId : 0; + return this.focusedThread ? this.focusedThread.threadId : 0; } public getSelectedExpression(): debug.IExpression { diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index 30c5fc809eb..0886a3850c3 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -251,17 +251,18 @@ export class DebugService implements debug.IDebugService { allThreadsStopped: event.body.allThreadsStopped }); - this.model.getThreads()[threadId].getCallStack(this).then(callStack => { + const thread = this.model.getThreads()[threadId]; + thread.getCallStack(this).then(callStack => { if (callStack.length > 0) { // focus first stack frame from top that has source location const stackFrameToFocus = arrays.first(callStack, sf => sf.source && sf.source.available, callStack[0]); - this.setFocusedStackFrameAndEvaluate(stackFrameToFocus).done(null, errors.onUnexpectedError); + this.setFocusedStackFrameAndEvaluate(stackFrameToFocus, thread).done(null, errors.onUnexpectedError); this.windowService.getWindow().focus(); aria.alert(nls.localize('debuggingPaused', "Debugging paused, reason {0}, {1} {2}", event.body.reason, stackFrameToFocus.source ? stackFrameToFocus.source.name : '', stackFrameToFocus.lineNumber)); return this.openOrRevealSource(stackFrameToFocus.source, stackFrameToFocus.lineNumber, false, false); } else { - this.setFocusedStackFrameAndEvaluate(null).done(null, errors.onUnexpectedError); + this.setFocusedStackFrameAndEvaluate(null, thread).done(null, errors.onUnexpectedError); } }); }, errors.onUnexpectedError); @@ -394,8 +395,12 @@ export class DebugService implements debug.IDebugService { return !!this.contextService.getWorkspace(); } - public setFocusedStackFrameAndEvaluate(focusedStackFrame: debug.IStackFrame): TPromise { - this.viewModel.setFocusedStackFrame(focusedStackFrame); + public setFocusedStackFrameAndEvaluate(focusedStackFrame: debug.IStackFrame, thread?: debug.IThread): TPromise { + if (!thread && focusedStackFrame) { + thread = this.model.getThreads()[focusedStackFrame.threadId]; + } + + this.viewModel.setFocusedStackFrame(focusedStackFrame, thread); if (focusedStackFrame) { return this.model.evaluateWatchExpressions(this.session, focusedStackFrame); } else { diff --git a/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts b/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts index a60ac72fd44..9f961b9db3e 100644 --- a/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts +++ b/src/vs/workbench/parts/debug/test/common/debugViewModel.test.ts @@ -5,7 +5,7 @@ import assert = require('assert'); import { ViewModel } from 'vs/workbench/parts/debug/common/debugViewModel'; -import { StackFrame, Expression } from 'vs/workbench/parts/debug/common/debugModel'; +import { StackFrame, Expression, Thread } from 'vs/workbench/parts/debug/common/debugModel'; suite('Debug - View Model', () => { var model: ViewModel; @@ -22,7 +22,7 @@ suite('Debug - View Model', () => { assert.equal(model.getFocusedStackFrame(), null); assert.equal(model.getFocusedThreadId(), 0); const frame = new StackFrame(1, 1, null, 'app.js', 1, 1); - model.setFocusedStackFrame(frame); + model.setFocusedStackFrame(frame, new Thread('myThread', 1)); assert.equal(model.getFocusedStackFrame(), frame); assert.equal(model.getFocusedThreadId(), 1); -- GitLab