Skip to content

fix: skip shell-integration wait for shells without SI support (fixes #1391)#1501

Merged
anthonykim1 merged 1 commit intomicrosoft:mainfrom
StellaHuang95:nuShell
May 2, 2026
Merged

fix: skip shell-integration wait for shells without SI support (fixes #1391)#1501
anthonykim1 merged 1 commit intomicrosoft:mainfrom
StellaHuang95:nuShell

Conversation

@StellaHuang95
Copy link
Copy Markdown
Contributor

Summary

Fixes #1391 — terminal activation is slow on nushell (and any other shell VS Code doesn't provide shell integration for).

When a Python terminal opens in command activation mode, waitForShellIntegration() is awaited before sending the activation command. For shells VS Code does not provide shell integration for — nu, cmd, csh, tcsh, ksh, xonsh — the onDidChangeTerminalShellIntegration event never fires, the prompt-pattern heuristic is unreliable, and the wait runs out the full 5 s default timeout (per getShellIntegrationTimeout() when terminal.integrated.shellIntegration.enabled is true). Once the wait completes, activation falls back to terminal.sendText anyway — so the delay is pure overhead and visibly disrupts the user's typing in the new terminal.

Root cause

waitForShellIntegration() in src/features/terminal/utils.ts doesn't consult the codebase's existing source of truth for SI-capable shells (shellIntegrationSupportedShells in src/features/terminal/shells/common/shellUtils.ts). For nu, that means it always times out.

Fix

After the existing terminal.shellIntegration early-return in waitForShellIntegration, identify the shell via identifyTerminalShell() and return false immediately when the shell type is known and not in shellIntegrationSupportedShells. Wrapped in try/catch so any detection failure (or 'unknown' result) falls through to the existing Promise.race body — strictly additive: best case faster, worst case identical to today.

This:

  • Reuses the codebase's single source of truth (shellIntegrationSupportedShells), so adding a new SI-capable shell automatically benefits both this code and shouldUseProfileActivation.
  • Returns the same value (false) the function would have eventually returned — semantics unchanged for all callers, only latency differs.
  • Preserves all existing behavior for supported shells (pwsh, bash, gitbash, fish, zsh).
  • Defensive try/catch and explicit 'unknown' check make the change non-regressing even if shell detection fails.

For nu users, this turns the ~5 s freeze before overlay use ...activate.nu runs into an imperceptible delay.

Testing

Manual

On main with nu configured as default profile and python-envs.terminal.autoActivationType: "command":

  • Open new terminal → ~5 s gap between prompt appearing and activation command running.

On this branch, same setup:

  • Open new terminal → activation command runs immediately after the prompt.
  • Python Environments output channel logs: Shell 'nu' does not support shell integration; skipping wait.

Verified the fix does not alter behavior for pwsh / bash (they still wait for SI to come up, which they do quickly).

Automated

8 new unit tests in Terminal Utils - waitForShellIntegration cover:

  • undefined terminal → false immediately
  • terminal.shellIntegration already set → true immediately, no shell detection
  • nufalse immediately, no event listeners registered
  • cmdfalse immediately
  • csh / tcsh / ksh / xonsh → all false immediately
  • bash → falls through to event race, resolves true when SI event fires
  • unknown shell → falls through to race
  • identifyTerminalShell throws → falls through to race (defensive)
npm run lint           # clean
npm run compile-tests  # clean
npm run unittest       # 992 passing (including the 8 new tests), 2 pending

Related

Risk

Low. Fully covered by tests. The change is gated by try/catch and an explicit allow-list, so the worst case (detection fails or returns 'unknown') is identical to current behavior.

…soft#1391)

waitForShellIntegration() blocks for up to 5s waiting for an
onDidChangeTerminalShellIntegration event that never fires for shells
VS Code does not provide shell integration for (nu, cmd, csh, tcsh,
ksh, xonsh). The wait is followed by a fallback terminal.sendText()
activation that doesn't depend on shell integration anyway, so the
delay is pure overhead.

After the existing terminal.shellIntegration early-return, identify
the shell via identifyTerminalShell() and return false immediately
when the type is known and not in shellIntegrationSupportedShells.
The check is wrapped in try/catch so any detection failure (or an
'unknown' result) falls through to the existing race, preserving
prior behavior.

For nu users this turns a ~5s freeze before activation into an
imperceptible delay.

Tests:
- 8 new unit tests covering: nu/cmd/csh/tcsh/ksh/xonsh skip
  immediately, supported shells fall through to the race, unknown
  falls through, detection throwing falls through, undefined terminal
  and pre-existing shellIntegration early-returns.

Fixes microsoft#1391
@StellaHuang95
Copy link
Copy Markdown
Contributor Author

@anthonykim1 I made some changes around shell integration, would you mind taking a look as well? Thanks!

@anthonykim1
Copy link
Copy Markdown
Contributor

@StellaHuang95 This looks good, thank you

@anthonykim1 anthonykim1 merged commit da846f3 into microsoft:main May 2, 2026
45 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terminal activation is slow on nushell

4 participants