From 674216cc8a541dd96ad00900f5760d389bd5e499 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 16 Jan 2025 14:08:03 +0800 Subject: [PATCH 1/2] reuse existing non-busy terminals --- src/integrations/terminal/TerminalManager.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/integrations/terminal/TerminalManager.ts b/src/integrations/terminal/TerminalManager.ts index 5234791..ecc555f 100644 --- a/src/integrations/terminal/TerminalManager.ts +++ b/src/integrations/terminal/TerminalManager.ts @@ -161,8 +161,10 @@ export class TerminalManager { } async getOrCreateTerminal(cwd: string): Promise { + const terminals = TerminalRegistry.getAllTerminals() + // Find available terminal from our pool first (created for this task) - const availableTerminal = TerminalRegistry.getAllTerminals().find((t) => { + const matchingTerminal = terminals.find((t) => { if (t.busy) { return false } @@ -173,11 +175,21 @@ export class TerminalManager { } return arePathsEqual(vscode.Uri.file(cwd).fsPath, terminalCwd.fsPath) }) + if (matchingTerminal) { + this.terminalIds.add(matchingTerminal.id) + return matchingTerminal + } + + // If no matching terminal exists, try to find any non-busy terminal + const availableTerminal = terminals.find((t) => !t.busy) if (availableTerminal) { + // Navigate back to the desired directory + await this.runCommand(availableTerminal, `cd "${cwd}"`) this.terminalIds.add(availableTerminal.id) return availableTerminal } + // If all terminals are busy, create a new one const newTerminalInfo = TerminalRegistry.createTerminal(cwd) this.terminalIds.add(newTerminalInfo.id) return newTerminalInfo From 68712ea0f6bffdaef353914e41587dc3c438fa99 Mon Sep 17 00:00:00 2001 From: Matt Rubens Date: Fri, 24 Jan 2025 23:40:49 -0500 Subject: [PATCH 2/2] Changeset --- .changeset/friendly-bottles-kneel.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/friendly-bottles-kneel.md diff --git a/.changeset/friendly-bottles-kneel.md b/.changeset/friendly-bottles-kneel.md new file mode 100644 index 0000000..6ac5e8a --- /dev/null +++ b/.changeset/friendly-bottles-kneel.md @@ -0,0 +1,5 @@ +--- +"roo-cline": patch +--- + +Fix issue where the terminal management system was creating unnecessary new terminals (thanks @evan-fannin!)