From 586b7e1a4511cfc920893dd64e0f28c3b0f1ccf2 Mon Sep 17 00:00:00 2001 From: seem Date: Mon, 25 Nov 2024 17:24:04 +0200 Subject: [PATCH] sort by createdTimestamp instead of insert order --- .../services/runtimeSession/common/runtimeSession.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/vs/workbench/services/runtimeSession/common/runtimeSession.ts b/src/vs/workbench/services/runtimeSession/common/runtimeSession.ts index 1778a35b1fa..3c03a970259 100644 --- a/src/vs/workbench/services/runtimeSession/common/runtimeSession.ts +++ b/src/vs/workbench/services/runtimeSession/common/runtimeSession.ts @@ -266,11 +266,13 @@ export class RuntimeSessionService extends Disposable implements IRuntimeSession getConsoleSessionForRuntime(runtimeId: string): ILanguageRuntimeSession | undefined { // It's possible that there are multiple consoles for the same runtime, // for example, if one failed to start and is uninitialized. In that case, - // we return the last. - const session = Array.from(this._activeSessionsBySessionId.values()).reverse().find(session => - session.session.runtimeMetadata.runtimeId === runtimeId && - session.session.metadata.sessionMode === LanguageRuntimeSessionMode.Console && - session.state !== RuntimeState.Exited); + // we return the most recently created. + const session = Array.from(this._activeSessionsBySessionId.values()) + .sort((a, b) => b.session.metadata.createdTimestamp - a.session.metadata.createdTimestamp) + .find(session => + session.session.runtimeMetadata.runtimeId === runtimeId && + session.session.metadata.sessionMode === LanguageRuntimeSessionMode.Console && + session.state !== RuntimeState.Exited); if (session) { return session.session; } else {