Skip to content

Fix parentTerminal being ignored for terminals that have already opened - #342420

Merged
Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
maxteneff:fix/terminal-parent-instance-id
Nov 5, 2026
Merged

Megan Rogge (meganrogge) merged 2 commits into
microsoft:mainfrom
maxteneff:fix/terminal-parent-instance-id

Conversation

@maxteneff

Copy link
Copy Markdown
Contributor

Fixes #205254

window.createTerminal({ location: { parentTerminal } }) only splits from the parent when the parent hasn't opened yet, e.g. when both terminals are created at the same moment. For a terminal that has already opened, such as one from window.terminals or one created earlier and kept around, the option is silently ignored and the new terminal opens on its own.

Before a terminal opens, the extension host identifies it by the string id it was created with. Once $acceptTerminalOpened runs, it switches to the terminal's numeric instance id (ExtHostTerminal._id). MainThreadTerminalService._deserializeParentTerminal only looked the parent up in _extHostTerminals, which is keyed by the creation id, so an instance id never matched. The fix uses the existing _getTerminalInstance, which handles both kinds of identifiers.

How to test

Unit tests in mainThreadTerminalService.test.ts:

  • splits from a parent terminal referenced by its instance id: the case from the issue. It fails without the fix and passes with it.
  • splits from a parent terminal referenced by its extension identifier: the case that already worked, to make sure it still does.
./scripts/test.sh --grep MainThreadTerminalService

Manual check with an extension:

const parent = vscode.window.createTerminal('parent');
parent.show();
await new Promise(resolve => setTimeout(resolve, 1000));
vscode.window.createTerminal({ name: 'child', location: { parentTerminal: parent } });

The child should open split next to the parent instead of in its own group.

…ened

Once a terminal has opened, the extension host refers to it by its instance id rather than the identifier it was created with. The main thread only looked the parent up by the creation identifier, so `parentTerminal` was ignored for any terminal that had already opened, e.g. one from `window.terminals`.

Fixes microsoft#205254
Copilot AI balanced review requested due to automatic review settings October 18, 2026 18:56
@maxteneff

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix includes regression coverage for both identifier forms, with no actionable issues identified.

No open issues 🎉

What changed in this PR

Fixes #205254 so parentTerminal correctly splits from terminals that have already opened.

Changes:

  • Uses the existing resolver for both creation identifiers and numeric instance IDs.
  • Adds regression tests covering both identifier forms.
File Description
src/​vs/​workbench/​api/​test/​browser/​mainThreadTerminalService.test.ts Tests parent-terminal splitting with both identifier types.
src/​vs/​workbench/​api/​browser/​mainThreadTerminalService.ts Resolves parents through _getTerminalInstance.

Review effort: Balanced

@meganrogge Megan Rogge (meganrogge) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@meganrogge
Megan Rogge (meganrogge) merged commit 3e5d7eb into microsoft:main Nov 5, 2026
59 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.146.0 milestone Nov 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An already-opened hideFromUser panel terminal can be selected as a split parent without a group, causing _splitTerminal to throw and preventing the child terminal from opening.

1 open issue

Review effort: Max

Dmitriy Vasyura (dmitrivMS) added a commit that referenced this pull request Nov 9, 2026
…346704)

* terminal: ignore background instances as API split parents

Follow up on #342420 and preserve the parentTerminal fix for #205254 while falling back to the default location for hidden or backgrounded parents.

Co-authored-by: Copilot <[email protected]>

* terminal: preserve hidden editor split parents

Keep editor-targeted API split parents even when hidden or backgrounded, while retaining foreground validation for panel parents. Cover both terminal identifier types with regression tests.

Co-authored-by: Copilot <[email protected]>

* terminal: preserve panel location for background children

Use an explicit panel location when a resolved background panel parent cannot be split. Preserve the parent location for visible and hidden children even with an editor default, with regression coverage for both terminal identifier types.

Co-authored-by: Copilot <[email protected]>

* terminal: preserve cwd inheritance for hidden children

Retain the resolved split parent for hidden-child requests so initial and inherited cwd settings keep working. Preserve explicit cwd overrides and keep the panel fallback for visible children of background parents.

Co-authored-by: Copilot <[email protected]>

* terminal: clarify split handling and harden regression tests

Clarify the hidden-child cwd path, explicitly type captured test results, and locate the child terminal by its extension identifier.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parentTerminal doesn't always work

5 participants