Skip to content

Commit 7133939

Browse files
authored
Prevent enable si showing up when using pwsh from chat with accessibility mode (#309606)
* Prevent enable si showing up when using pwsh from chat * temporary commit msg to remove * try extra time for screen reader users * better comments * Remove verbose comment
1 parent 3ea09a0 commit 7133939

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/toolTerminalCreator.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { DisposableStore, MutableDisposable } from '../../../../../base/common/l
1212
import { OperatingSystem } from '../../../../../base/common/platform.js';
1313
import { ThemeIcon } from '../../../../../base/common/themables.js';
1414
import { hasKey, isNumber, isObject, isString } from '../../../../../base/common/types.js';
15+
import { IAccessibilityService } from '../../../../../platform/accessibility/common/accessibility.js';
1516
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
1617
import { TerminalCapability } from '../../../../../platform/terminal/common/capabilities/capabilities.js';
1718
import { PromptInputState } from '../../../../../platform/terminal/common/capabilities/commandDetection/promptInputModel.js';
@@ -48,6 +49,7 @@ export class ToolTerminalCreator {
4849
private static _lastSuccessfulShell: ShellLaunchType = ShellLaunchType.Unknown;
4950

5051
constructor(
52+
@IAccessibilityService private readonly _accessibilityService: IAccessibilityService,
5153
@IConfigurationService private readonly _configurationService: IConfigurationService,
5254
@ITerminalLogService private readonly _logService: ITerminalLogService,
5355
@ITerminalService private readonly _terminalService: ITerminalService,
@@ -199,11 +201,22 @@ export class ToolTerminalCreator {
199201
const store = new DisposableStore();
200202
const result = new DeferredPromise<ShellIntegrationQuality>();
201203

204+
// When screen reader mode is on, allow extra time before giving up on shell integration.
205+
// Cold-loading PSReadLine on Windows PowerShell 5.1 with accessibility mode enabled can
206+
// push the `HasRichCommandDetection` sequence past the default window, which otherwise
207+
// causes `shellIntegrationQuality` to be stuck at `None` and the "Enable shell integration"
208+
// banner to show up incorrectly. Only extend non-zero timeouts so tests using 0 remain 0.
209+
const isScreenReaderOptimized = this._accessibilityService.isScreenReaderOptimized();
210+
const effectiveTimeoutMs = timeoutMs > 0 && isScreenReaderOptimized
211+
? timeoutMs + 3000
212+
: timeoutMs;
213+
this._logService.info(`ToolTerminalCreator#_waitForShellIntegration: base ${timeoutMs}ms, effective ${effectiveTimeoutMs}ms, screenReaderOptimized=${isScreenReaderOptimized}`);
214+
202215
const siNoneTimer = store.add(new MutableDisposable());
203216
siNoneTimer.value = disposableTimeout(() => {
204-
this._logService.info(`ToolTerminalCreator#_waitForShellIntegration: Timed out ${timeoutMs}ms, using no SI`);
217+
this._logService.info(`ToolTerminalCreator#_waitForShellIntegration: Timed out ${effectiveTimeoutMs}ms, using no SI`);
205218
result.complete(ShellIntegrationQuality.None);
206-
}, timeoutMs);
219+
}, effectiveTimeoutMs);
207220

208221
if (instance.capabilities.get(TerminalCapability.CommandDetection)?.hasRichCommandDetection) {
209222
// Rich command detection is available immediately.

src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,6 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
13051305
commandDetection!,
13061306
executionOptions.persistentSession
13071307
);
1308-
if (toolTerminal.shellIntegrationQuality === ShellIntegrationQuality.None) {
1309-
toolResultMessage = '$(info) Enable [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) to improve command detection';
1310-
}
13111308
this._logService.info(`RunInTerminalTool: Using \`${execution.strategy.type}\` execute strategy for command \`${command}\``);
13121309
store.add(execution);
13131310
RunInTerminalTool._activeExecutions.set(termId, execution);
@@ -1682,6 +1679,14 @@ export class RunInTerminalTool extends Disposable implements IToolImpl {
16821679
}
16831680
}
16841681

1682+
// Re-check shell integration quality now that command execution has completed.
1683+
// Only set the banner if toolResultMessage hasn't already been set (e.g. by the alt-buffer path).
1684+
this._terminalToolCreator.refreshShellIntegrationQuality(toolTerminal);
1685+
this._logService.info(`RunInTerminalTool: shellIntegrationQuality=${toolTerminal.shellIntegrationQuality} at banner decision time`);
1686+
if (!toolResultMessage && toolTerminal.shellIntegrationQuality === ShellIntegrationQuality.None) {
1687+
toolResultMessage = '$(info) Enable [shell integration](https://code.visualstudio.com/docs/terminal/shell-integration) to improve command detection';
1688+
}
1689+
16851690
const resultText: string[] = [];
16861691
if (!didSandboxWrapCommand) {
16871692
if (didUserEditCommand) {

0 commit comments

Comments
 (0)