提交 4ada031b 编写于 作者: I isidor

debug: introduce explicit focusedThread

上级 e50a1f2d
......@@ -781,7 +781,7 @@ export class FocusProcessAction extends AbstractDebugAction {
public run(processName: string): TPromise<any> {
const isMultiRoot = this.debugService.getConfigurationManager().getLaunches().length > 1;
const process = this.debugService.getModel().getProcesses().filter(p => p.getName(isMultiRoot) === processName).pop();
this.debugService.focusStackFrame(null, process, true);
this.debugService.focusStackFrame(undefined, undefined, process, true);
const stackFrame = this.debugService.getViewModel().focusedStackFrame;
if (stackFrame) {
return stackFrame.openInEditor(this.editorService, true);
......
......@@ -512,7 +512,7 @@ export interface IDebugService {
/**
* Sets the focused stack frame and evaluates all expressions against the newly focused stack frame,
*/
focusStackFrame(focusedStackFrame: IStackFrame, process?: IProcess, explicit?: boolean): void;
focusStackFrame(focusedStackFrame: IStackFrame, thread?: IThread, process?: IProcess, explicit?: boolean): void;
/**
* Adds new breakpoints to the model for the file specified with the uri. Notifies debug adapter of breakpoint changes.
......
......@@ -10,6 +10,7 @@ export class ViewModel implements debug.IViewModel {
private _focusedStackFrame: debug.IStackFrame;
private _focusedProcess: debug.IProcess;
private _focusedThread: debug.IThread;
private selectedExpression: debug.IExpression;
private selectedFunctionBreakpoint: debug.IFunctionBreakpoint;
private _onDidFocusProcess: Emitter<debug.IProcess | undefined>;
......@@ -40,13 +41,19 @@ export class ViewModel implements debug.IViewModel {
return this._focusedStackFrame;
}
public setFocusedStackFrame(stackFrame: debug.IStackFrame, process: debug.IProcess, explicit: boolean): void {
this._focusedStackFrame = stackFrame;
if (process !== this._focusedProcess) {
public setFocus(stackFrame: debug.IStackFrame, thread: debug.IThread, process: debug.IProcess, explicit: boolean): void {
let shouldEmit = this._focusedProcess !== process || this._focusedThread !== thread || this._focusedStackFrame !== stackFrame;
if (this._focusedProcess !== process) {
this._focusedProcess = process;
this._onDidFocusProcess.fire(process);
}
this._onDidFocusStackFrame.fire({ stackFrame, explicit });
this._focusedThread = thread;
this._focusedStackFrame = stackFrame;
if (shouldEmit) {
this._onDidFocusStackFrame.fire({ stackFrame, explicit });
}
}
public get onDidFocusProcess(): Event<debug.IProcess> {
......
......@@ -222,7 +222,7 @@ class CallStackController extends BaseDebugController {
}
public focusStackFrame(stackFrame: IStackFrame, event: any, preserveFocus: boolean): void {
this.debugService.focusStackFrame(stackFrame, undefined, true);
this.debugService.focusStackFrame(stackFrame, stackFrame.thread, stackFrame.thread.process, true);
const sideBySide = (event && (event.ctrlKey || event.metaKey));
stackFrame.openInEditor(this.editorService, preserveFocus, sideBySide).done(undefined, errors.onUnexpectedError);
}
......
......@@ -320,7 +320,7 @@ export class DebugService implements debug.IDebugService {
const threadId = event.body.allThreadsContinued !== false ? undefined : event.body.threadId;
this.model.clearThreads(session.getId(), false, threadId);
if (this.viewModel.focusedProcess.getId() === session.getId()) {
this.focusStackFrame(null, this.viewModel.focusedProcess);
this.focusStackFrame(undefined, this.viewModel.focusedThread, this.viewModel.focusedProcess);
}
this.updateStateAndEmit(session.getId(), debug.State.Running);
}));
......@@ -534,18 +534,33 @@ export class DebugService implements debug.IDebugService {
}
}
public focusStackFrame(stackFrame: debug.IStackFrame, process?: debug.IProcess, explicit?: boolean): void {
public focusStackFrame(stackFrame: debug.IStackFrame, thread?: debug.IThread, process?: debug.IProcess, explicit?: boolean): void {
if (!process) {
const processes = this.model.getProcesses();
process = stackFrame ? stackFrame.thread.process : processes.length ? processes[0] : null;
if (stackFrame || thread) {
process = stackFrame ? stackFrame.thread.process : thread.process;
} else {
const processes = this.model.getProcesses();
process = processes.length ? processes[0] : undefined;
}
}
if (!thread) {
if (stackFrame) {
thread = stackFrame.thread;
} else {
const threads = process ? process.getAllThreads() : undefined;
thread = threads && threads.length ? threads[0] : undefined;
}
}
if (!stackFrame) {
const threads = process ? process.getAllThreads() : null;
const callStack = threads && threads.length === 1 ? threads[0].getCallStack() : null;
stackFrame = callStack && callStack.length ? callStack[0] : null;
if (thread) {
const callStack = thread.getCallStack();
stackFrame = callStack && callStack.length ? callStack[0] : null;
}
}
this.viewModel.setFocusedStackFrame(stackFrame, process, explicit);
this.viewModel.setFocus(stackFrame, thread, process, explicit);
this.updateStateAndEmit();
}
......@@ -610,7 +625,7 @@ export class DebugService implements debug.IDebugService {
public addReplExpression(name: string): TPromise<void> {
return this.model.addReplExpression(this.viewModel.focusedProcess, this.viewModel.focusedStackFrame, name)
// Evaluate all watch expressions and fetch variables again since repl evaluation might have changed some.
.then(() => this.focusStackFrame(this.viewModel.focusedStackFrame, this.viewModel.focusedProcess));
.then(() => this.focusStackFrame(this.viewModel.focusedStackFrame, this.viewModel.focusedThread, this.viewModel.focusedProcess));
}
public removeReplExpressions(): void {
......@@ -864,7 +879,7 @@ export class DebugService implements debug.IDebugService {
if (session.disconnected) {
return TPromise.as(null);
}
this.focusStackFrame(null, process);
this.focusStackFrame(undefined, undefined, process);
this._onDidNewProcess.fire(process);
const internalConsoleOptions = configuration.internalConsoleOptions || this.configurationService.getValue<debug.IDebugConfiguration>('debug').internalConsoleOptions;
......@@ -1041,7 +1056,7 @@ export class DebugService implements debug.IDebugService {
// Restart should preserve the focused process
const restartedProcess = this.model.getProcesses().filter(p => p.configuration.name === process.configuration.name).pop();
if (restartedProcess && restartedProcess !== this.viewModel.focusedProcess) {
this.focusStackFrame(null, restartedProcess);
this.focusStackFrame(undefined, undefined, restartedProcess);
}
}
});
......
......@@ -26,7 +26,7 @@ suite('Debug - View Model', () => {
const process = new Process({ name: 'mockProcess', type: 'node', request: 'launch' }, mockSession);
const thread = new Thread(process, 'myThread', 1);
const frame = new StackFrame(thread, 1, null, 'app.js', 'normal', { startColumn: 1, startLineNumber: 1, endColumn: undefined, endLineNumber: undefined }, 0);
model.setFocusedStackFrame(frame, process, false);
model.setFocus(frame, thread, process, false);
assert.equal(model.focusedStackFrame.getId(), frame.getId());
assert.equal(model.focusedThread.threadId, 1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册