提交 db09b30c 编写于 作者: I isidor

debug: always have a focused process

fixes #14497
上级 a9f17ed0
......@@ -143,12 +143,7 @@ export class RestartAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
let process = this.debugService.getViewModel().focusedProcess;
if (!process) {
const processes = this.debugService.getModel().getProcesses();
process = processes.length > 0 ? processes[0] : null;
}
const process = this.debugService.getViewModel().focusedProcess;
return this.debugService.restartProcess(process);
}
......@@ -252,12 +247,7 @@ export class StopAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
let process = this.debugService.getViewModel().focusedProcess;
if (!process) {
const processes = this.debugService.getModel().getProcesses();
process = processes.length > 0 ? processes[0] : null;
}
const process = this.debugService.getViewModel().focusedProcess;
return process ? process.session.disconnect(false, true) : TPromise.as(null);
}
......@@ -275,11 +265,7 @@ export class DisconnectAction extends AbstractDebugAction {
}
public run(): TPromise<any> {
let process = this.debugService.getViewModel().focusedProcess;
if (!process) {
process = this.debugService.getModel().getProcesses().pop();
}
const process = this.debugService.getViewModel().focusedProcess;
return process ? process.session.disconnect(false, true) : TPromise.as(null);
}
......
......@@ -9,6 +9,7 @@ import debug = require('vs/workbench/parts/debug/common/debug');
export class ViewModel implements debug.IViewModel {
private _focusedStackFrame: debug.IStackFrame;
private _focusedProcess: debug.IProcess;
private selectedExpression: debug.IExpression;
private selectedFunctionBreakpoint: debug.IFunctionBreakpoint;
private _onDidFocusStackFrame: Emitter<debug.IStackFrame>;
......@@ -30,7 +31,7 @@ export class ViewModel implements debug.IViewModel {
}
public get focusedProcess(): debug.IProcess {
return this._focusedStackFrame ? this._focusedStackFrame.thread.process : null;
return this._focusedProcess;
}
public get focusedThread(): debug.IThread {
......@@ -41,9 +42,10 @@ export class ViewModel implements debug.IViewModel {
return this._focusedStackFrame;
}
public setFocusedStackFrame(focusedStackFrame: debug.IStackFrame): void {
this._focusedStackFrame = focusedStackFrame;
this._onDidFocusStackFrame.fire(focusedStackFrame);
public setFocusedStackFrame(stackFrame: debug.IStackFrame, process: debug.IProcess): void {
this._focusedStackFrame = stackFrame;
this._focusedProcess = process;
this._onDidFocusStackFrame.fire(stackFrame);
}
public get onDidFocusStackFrame(): Event<debug.IStackFrame> {
......
......@@ -440,7 +440,16 @@ export class DebugService implements debug.IDebugService {
}
public setFocusedStackFrameAndEvaluate(focusedStackFrame: debug.IStackFrame): TPromise<void> {
this.viewModel.setFocusedStackFrame(focusedStackFrame);
const processes = this.model.getProcesses();
const process = focusedStackFrame ? focusedStackFrame.thread.process : processes.length ? processes[0] : null;
if (process && !focusedStackFrame) {
const thread = process.getAllThreads().pop();
const callStack = thread ? thread.getCachedCallStack() : null;
focusedStackFrame = callStack && callStack.length ? callStack[0] : null;
}
this.viewModel.setFocusedStackFrame(focusedStackFrame, process);
this._onDidChangeState.fire();
if (focusedStackFrame) {
return this.model.evaluateWatchExpressions(focusedStackFrame);
} else {
......@@ -895,6 +904,7 @@ export class DebugService implements debug.IDebugService {
private transitionToRunningState(session: RawDebugSession, threadId?: number): void {
this.model.clearThreads(session.getId(), false, threadId);
// TODO@Isidor remove this mess
// Get a top stack frame of a stopped thread if there is any.
const process = this.model.getProcesses().filter(p => p.getId() === session.getId()).pop();
const stoppedThread = process && process.getAllThreads().filter(t => t.stopped).pop();
......
......@@ -26,7 +26,7 @@ suite('Debug - View Model', () => {
const process = new Process('mockProcess', mockSession);
const thread = new Thread(process, 'myThread', 1);
const frame = new StackFrame(thread, 1, null, 'app.js', 1, 1);
model.setFocusedStackFrame(frame);
model.setFocusedStackFrame(frame, process);
assert.equal(model.focusedStackFrame, frame);
assert.equal(model.focusedThread.threadId, 1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册