From b2b465bb140b6321923f826780c1ab24c9deaf3b Mon Sep 17 00:00:00 2001 From: isidor Date: Thu, 20 Oct 2016 16:25:46 +0200 Subject: [PATCH] debug: add a process to model as soon as created --- src/vs/workbench/parts/debug/common/debug.ts | 2 +- .../parts/debug/common/debugModel.ts | 19 ++++++++++--------- .../debug/electron-browser/debugService.ts | 5 +++-- .../parts/debug/test/node/debugModel.test.ts | 18 ++++++++++-------- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/vs/workbench/parts/debug/common/debug.ts b/src/vs/workbench/parts/debug/common/debug.ts index d6bdc8ee31d..8c1b7131640 100644 --- a/src/vs/workbench/parts/debug/common/debug.ts +++ b/src/vs/workbench/parts/debug/common/debug.ts @@ -31,7 +31,7 @@ export const DEBUG_SCHEME = 'debug'; export interface IRawModelUpdate { threadId: number; - rawSession: ISession & ITreeElement; + sessionId: string; thread?: DebugProtocol.Thread; callStack?: DebugProtocol.StackFrame[]; stoppedDetails?: IRawStoppedDetails; diff --git a/src/vs/workbench/parts/debug/common/debugModel.ts b/src/vs/workbench/parts/debug/common/debugModel.ts index 1d7e337df74..87821a75d35 100644 --- a/src/vs/workbench/parts/debug/common/debugModel.ts +++ b/src/vs/workbench/parts/debug/common/debugModel.ts @@ -644,6 +644,10 @@ export class Model implements debug.IModel { return this.processes; } + public addProcess(session: debug.ISession & debug.ITreeElement): void { + this.processes.push(new Process(session)); + } + public removeProcess(id: string): void { this.processes = this.processes.filter(p => p.getId() !== id); this._onDidChangeCallStack.fire(); @@ -666,18 +670,15 @@ export class Model implements debug.IModel { } public rawUpdate(data: debug.IRawModelUpdate): void { - let process = this.processes.filter(p => p.getId() === data.rawSession.getId()).pop(); - if (!process) { - process = new Process(data.rawSession); - this.processes.push(process); + let process = this.processes.filter(p => p.getId() === data.sessionId).pop(); + if (process) { + process.rawUpdate(data); + this._onDidChangeCallStack.fire(); } - process.rawUpdate(data); - - this._onDidChangeCallStack.fire(); } - public clearThreads(processId: string, removeThreads: boolean, reference: number = undefined): void { - const process = this.processes.filter(p => p.getId() === processId).pop(); + public clearThreads(id: string, removeThreads: boolean, reference: number = undefined): void { + const process = this.processes.filter(p => p.getId() === id).pop(); if (process) { process.clearThreads(removeThreads, reference); this._onDidChangeCallStack.fire(); diff --git a/src/vs/workbench/parts/debug/electron-browser/debugService.ts b/src/vs/workbench/parts/debug/electron-browser/debugService.ts index c604c026264..4f82dab396a 100644 --- a/src/vs/workbench/parts/debug/electron-browser/debugService.ts +++ b/src/vs/workbench/parts/debug/electron-browser/debugService.ts @@ -260,7 +260,7 @@ export class DebugService implements debug.IDebugService { this.getThreadData(session).done(() => { this.model.rawUpdate({ - rawSession: session, + sessionId: session.getId(), threadId, stoppedDetails: event.body, allThreadsStopped: event.body.allThreadsStopped @@ -351,7 +351,7 @@ export class DebugService implements debug.IDebugService { private getThreadData(session: RawDebugSession): TPromise { return session.threads().then(response => { if (response && response.body && response.body.threads) { - response.body.threads.forEach(thread => this.model.rawUpdate({ rawSession: session, threadId: thread.id, thread })); + response.body.threads.forEach(thread => this.model.rawUpdate({ sessionId: session.getId(), threadId: thread.id, thread })); } }); } @@ -605,6 +605,7 @@ export class DebugService implements debug.IDebugService { } const session = this.instantiationService.createInstance(RawDebugSession, configuration.debugServer, this.configurationManager.adapter, this.customTelemetryService); + this.model.addProcess(session); this.toDisposeOnSessionEnd[session.getId()] = []; if (client) { this.toDisposeOnSessionEnd[session.getId()].push(client); diff --git a/src/vs/workbench/parts/debug/test/node/debugModel.test.ts b/src/vs/workbench/parts/debug/test/node/debugModel.test.ts index 919e04fbe22..ff95febfbb7 100644 --- a/src/vs/workbench/parts/debug/test/node/debugModel.test.ts +++ b/src/vs/workbench/parts/debug/test/node/debugModel.test.ts @@ -81,8 +81,9 @@ suite('Debug - Model', () => { var threadId = 1; var threadName = 'firstThread'; + model.addProcess(rawSession); model.rawUpdate({ - rawSession, + sessionId: rawSession.getId(), threadId: threadId, thread: { id: threadId, @@ -107,8 +108,9 @@ suite('Debug - Model', () => { const stoppedReason = 'breakpoint'; // Add the threads + model.addProcess(rawSession); model.rawUpdate({ - rawSession, + sessionId: rawSession.getId(), threadId: threadId1, thread: { id: threadId1, @@ -117,7 +119,7 @@ suite('Debug - Model', () => { }); model.rawUpdate({ - rawSession, + sessionId: rawSession.getId(), threadId: threadId2, thread: { id: threadId2, @@ -127,7 +129,7 @@ suite('Debug - Model', () => { // Stopped event with all threads stopped model.rawUpdate({ - rawSession, + sessionId: rawSession.getId(), threadId: threadId1, stoppedDetails: { reason: stoppedReason, @@ -196,10 +198,10 @@ suite('Debug - Model', () => { const runningThreadId = 2; const runningThreadName = 'runningThread'; const stoppedReason = 'breakpoint'; - + model.addProcess(rawSession); // Add the threads model.rawUpdate({ - rawSession, + sessionId: rawSession.getId(), threadId: stoppedThreadId, thread: { id: stoppedThreadId, @@ -208,7 +210,7 @@ suite('Debug - Model', () => { }); model.rawUpdate({ - rawSession, + sessionId: rawSession.getId(), threadId: runningThreadId, thread: { id: runningThreadId, @@ -218,7 +220,7 @@ suite('Debug - Model', () => { // Stopped event with only one thread stopped model.rawUpdate({ - rawSession, + sessionId: rawSession.getId(), threadId: stoppedThreadId, stoppedDetails: { reason: stoppedReason, -- GitLab