From f0cce2369b15a5a769c64294b5c0057c4cbf89ca Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Wed, 14 Jul 2021 13:58:21 -0400 Subject: [PATCH 1/2] Sort threads in response order Return the threads in getAllThreads in the same order as they were received in the threads response. This handles the case where the thread order changes, or new threads are added that are not just appended to the list. Fixes #128546 --- .../contrib/debug/browser/debugSession.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/vs/workbench/contrib/debug/browser/debugSession.ts b/src/vs/workbench/contrib/debug/browser/debugSession.ts index 058ab97e711..05c6a308148 100644 --- a/src/vs/workbench/contrib/debug/browser/debugSession.ts +++ b/src/vs/workbench/contrib/debug/browser/debugSession.ts @@ -46,6 +46,7 @@ export class DebugSession implements IDebugSession { private sources = new Map(); private threads = new Map(); + private threadIds: number[] = []; private cancellationMap = new Map(); private rawListeners: IDisposable[] = []; private fetchThreadsScheduler: RunOnceScheduler | undefined; @@ -694,7 +695,12 @@ export class DebugSession implements IDebugSession { getAllThreads(): IThread[] { const result: IThread[] = []; - this.threads.forEach(t => result.push(t)); + this.threadIds.forEach((threadId) => { + const thread = this.threads.get(threadId); + if (thread) { + result.push(thread); + } + }); return result; } @@ -729,9 +735,9 @@ export class DebugSession implements IDebugSession { } rawUpdate(data: IRawModelUpdate): void { - const threadIds: number[] = []; + this.threadIds = []; data.threads.forEach(thread => { - threadIds.push(thread.id); + this.threadIds.push(thread.id); if (!this.threads.has(thread.id)) { // A new thread came in, initialize it. this.threads.set(thread.id, new Thread(this, thread.name, thread.id)); @@ -745,7 +751,7 @@ export class DebugSession implements IDebugSession { }); this.threads.forEach(t => { // Remove all old threads which are no longer part of the update #75980 - if (threadIds.indexOf(t.threadId) === -1) { + if (this.threadIds.indexOf(t.threadId) === -1) { this.threads.delete(t.threadId); } }); From 7b67e477d8588baaca4eb570a71c1d93146919c1 Mon Sep 17 00:00:00 2001 From: Suzy Mueller Date: Wed, 28 Jul 2021 14:57:24 -0600 Subject: [PATCH 2/2] clear this.threadIds on clearThreads --- src/vs/workbench/contrib/debug/browser/debugSession.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/vs/workbench/contrib/debug/browser/debugSession.ts b/src/vs/workbench/contrib/debug/browser/debugSession.ts index 05c6a308148..c8146e3cd4d 100644 --- a/src/vs/workbench/contrib/debug/browser/debugSession.ts +++ b/src/vs/workbench/contrib/debug/browser/debugSession.ts @@ -725,6 +725,7 @@ export class DebugSession implements IDebugSession { if (removeThreads) { this.threads.clear(); + this.threadIds = []; ExpressionContainer.allValues.clear(); } }