From 1a2d340d73cc766e2bcc0fa01cf7769d0f15a1ef Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Tue, 26 Nov 2024 10:40:56 -0500 Subject: [PATCH 1/2] fix #234670 --- .../api/common/extHostTerminalShellIntegration.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts b/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts index 7a1c24029d6a3..57113bd03e4ab 100644 --- a/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts +++ b/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts @@ -29,6 +29,8 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH protected _proxy: MainThreadTerminalShellIntegrationShape; + private _initialCwd: URI | undefined; + private _activeShellIntegrations: Map = new Map(); protected readonly _onDidChangeTerminalShellIntegration = new Emitter(); @@ -92,6 +94,9 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH if (!shellIntegration) { shellIntegration = new InternalTerminalShellIntegration(terminal.value, this._onDidStartTerminalShellExecution); this._activeShellIntegrations.set(instanceId, shellIntegration); + if (this._initialCwd) { + this._activeShellIntegrations.get(instanceId)?.setCwd(this._initialCwd); + } shellIntegration.store.add(terminal.onWillDispose(() => this._activeShellIntegrations.get(instanceId)?.dispose())); shellIntegration.store.add(shellIntegration.onDidRequestShellExecution(commandLine => this._proxy.$executeCommand(instanceId, commandLine))); shellIntegration.store.add(shellIntegration.onDidRequestEndExecution(e => this._onDidEndTerminalShellExecution.fire(e))); @@ -132,7 +137,13 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH } public $cwdChange(instanceId: number, cwd: UriComponents | undefined): void { - this._activeShellIntegrations.get(instanceId)?.setCwd(URI.revive(cwd)); + const activeShellIntegration = this._activeShellIntegrations.get(instanceId); + const revivedCwd = URI.revive(cwd); + if (!activeShellIntegration) { + this._initialCwd = revivedCwd; + } else { + this._activeShellIntegrations.get(instanceId)?.setCwd(revivedCwd); + } } public $closeTerminal(instanceId: number): void { From d7e34a7c8dab66edb16ed25b2a3b3b3876f1df38 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Tue, 26 Nov 2024 10:51:48 -0500 Subject: [PATCH 2/2] better fix --- .../browser/mainThreadTerminalShellIntegration.ts | 2 +- .../api/common/extHostTerminalShellIntegration.ts | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/api/browser/mainThreadTerminalShellIntegration.ts b/src/vs/workbench/api/browser/mainThreadTerminalShellIntegration.ts index de804627bafc9..6181cd4c63794 100644 --- a/src/vs/workbench/api/browser/mainThreadTerminalShellIntegration.ts +++ b/src/vs/workbench/api/browser/mainThreadTerminalShellIntegration.ts @@ -37,7 +37,7 @@ export class MainThreadTerminalShellIntegration extends Disposable implements Ma const onDidAddCommandDetection = this._store.add(this._terminalService.createOnInstanceEvent(instance => { return Event.map( Event.filter(instance.capabilities.onDidAddCapabilityType, e => { - return e === TerminalCapability.CommandDetection; + return e === TerminalCapability.CommandDetection || e === TerminalCapability.CwdDetection; }), () => instance ); })).event; diff --git a/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts b/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts index 57113bd03e4ab..7a1c24029d6a3 100644 --- a/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts +++ b/src/vs/workbench/api/common/extHostTerminalShellIntegration.ts @@ -29,8 +29,6 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH protected _proxy: MainThreadTerminalShellIntegrationShape; - private _initialCwd: URI | undefined; - private _activeShellIntegrations: Map = new Map(); protected readonly _onDidChangeTerminalShellIntegration = new Emitter(); @@ -94,9 +92,6 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH if (!shellIntegration) { shellIntegration = new InternalTerminalShellIntegration(terminal.value, this._onDidStartTerminalShellExecution); this._activeShellIntegrations.set(instanceId, shellIntegration); - if (this._initialCwd) { - this._activeShellIntegrations.get(instanceId)?.setCwd(this._initialCwd); - } shellIntegration.store.add(terminal.onWillDispose(() => this._activeShellIntegrations.get(instanceId)?.dispose())); shellIntegration.store.add(shellIntegration.onDidRequestShellExecution(commandLine => this._proxy.$executeCommand(instanceId, commandLine))); shellIntegration.store.add(shellIntegration.onDidRequestEndExecution(e => this._onDidEndTerminalShellExecution.fire(e))); @@ -137,13 +132,7 @@ export class ExtHostTerminalShellIntegration extends Disposable implements IExtH } public $cwdChange(instanceId: number, cwd: UriComponents | undefined): void { - const activeShellIntegration = this._activeShellIntegrations.get(instanceId); - const revivedCwd = URI.revive(cwd); - if (!activeShellIntegration) { - this._initialCwd = revivedCwd; - } else { - this._activeShellIntegrations.get(instanceId)?.setCwd(revivedCwd); - } + this._activeShellIntegrations.get(instanceId)?.setCwd(URI.revive(cwd)); } public $closeTerminal(instanceId: number): void {