Commit da846f3
authored
## 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`](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`](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
- `nu` → `false` immediately, no event listeners registered
- `cmd` → `false` 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
- #997 — original "Virtual environment activation is slow" tracking
issue, where the maintainer explicitly noted: *"In case shell does not
support dynamic evals like `nu`, it will fall back to command
activation."* This PR makes that command-activation fallback fast.
## 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.
1 parent 63bc2c2 commit da846f3
2 files changed
Lines changed: 189 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
31 | 50 | | |
32 | 51 | | |
33 | 52 | | |
| |||
37 | 56 | | |
38 | 57 | | |
39 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
40 | 70 | | |
41 | 71 | | |
42 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
| |||
545 | 549 | | |
546 | 550 | | |
547 | 551 | | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
0 commit comments