Skip to content

Commit

Permalink
debug: allow to set focussed thread with no call stack
Browse files Browse the repository at this point in the history
fixes #6214
  • Loading branch information
isidorn committed May 16, 2016
1 parent f2baddb commit 97f7bdd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/parts/debug/common/debugViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<debug.IStackFrame>;
Expand All @@ -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);
}

Expand All @@ -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 {
Expand Down
15 changes: 10 additions & 5 deletions src/vs/workbench/parts/debug/electron-browser/debugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -394,8 +395,12 @@ export class DebugService implements debug.IDebugService {
return !!this.contextService.getWorkspace();
}

public setFocusedStackFrameAndEvaluate(focusedStackFrame: debug.IStackFrame): TPromise<void> {
this.viewModel.setFocusedStackFrame(focusedStackFrame);
public setFocusedStackFrameAndEvaluate(focusedStackFrame: debug.IStackFrame, thread?: debug.IThread): TPromise<void> {
if (!thread && focusedStackFrame) {
thread = this.model.getThreads()[focusedStackFrame.threadId];
}

this.viewModel.setFocusedStackFrame(focusedStackFrame, thread);
if (focusedStackFrame) {
return this.model.evaluateWatchExpressions(this.session, focusedStackFrame);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 97f7bdd

Please sign in to comment.