diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index 246ccaf6a76..a0572cd37a2 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -928,6 +928,7 @@ export type ITerminalProfileObject = ITerminalExecutable | ITerminalProfileSourc export interface IShellIntegration { readonly capabilities: ITerminalCapabilityStore; readonly status: ShellIntegrationStatus; + updateCwd(newCwd: string): void; readonly onDidChangeStatus: Event; diff --git a/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts b/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts index 8221ad5c282..0833b41fb8c 100644 --- a/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts +++ b/src/vs/platform/terminal/common/xterm/shellIntegrationAddon.ts @@ -439,7 +439,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati return true; } case 'Cwd': { - this._updateCwd(value); + this.updateCwd(value); return true; } case 'IsWindows': { @@ -487,7 +487,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati } } - private _updateCwd(value: string) { + updateCwd(value: string) { value = sanitizeCwd(value); this._createOrGetCwdDetection().updateCwd(value); const commandDetection = this.capabilities.get(TerminalCapability.CommandDetection); @@ -518,7 +518,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati switch (key) { case ITermOscPt.CurrentDir: // Encountered: `OSC 1337 ; CurrentDir= ST` - this._updateCwd(value); + this.updateCwd(value); return true; } } @@ -538,7 +538,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati case '9': // Encountered `OSC 9 ; 9 ; ST` if (args.length) { - this._updateCwd(args[0]); + this.updateCwd(args[0]); } return true; } @@ -560,7 +560,7 @@ export class ShellIntegrationAddon extends Disposable implements IShellIntegrati if (command.match(/^file:\/\/.*\//)) { const uri = URI.parse(command); if (uri.path && uri.path.length > 0) { - this._updateCwd(uri.path); + this.updateCwd(uri.path); return true; } } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index df286dd974a..f90c28a0007 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -873,6 +873,12 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { return xterm; } + private _setCwdForShellIntegration(): void { + if (this.shellLaunchConfig.attachPersistentProcess?.cwd) { + this.xterm?.shellIntegration.updateCwd(this.shellLaunchConfig.attachPersistentProcess?.cwd); + } + } + async runCommand(commandLine: string, shouldExecute: boolean): Promise { let commandDetection = this.capabilities.get(TerminalCapability.CommandDetection); @@ -884,6 +890,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { store.add(this.capabilities.onDidAddCapabilityType(e => { if (e === TerminalCapability.CommandDetection) { commandDetection = this.capabilities.get(TerminalCapability.CommandDetection); + this._setCwdForShellIntegration(); r(); } })); @@ -892,6 +899,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { ]); store.dispose(); } + this._setCwdForShellIntegration(); // Determine whether to send ETX (ctrl+c) before running the command. This should always // happen unless command detection can reliably say that a command is being entered and @@ -980,6 +988,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { } this._register(xterm.shellIntegration.onDidChangeStatus(() => { + this._setCwdForShellIntegration(); if (this.hasFocus) { this._setShellIntegrationContextKey(); } else { @@ -1395,7 +1404,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { break; case ProcessPropertyType.InitialCwd: this._initialCwd = value; - this._cwd = this._initialCwd; + this._cwd = this._cwd ?? this._initialCwd; this._setTitle(this.title, TitleEventSource.Config); this._icon = this._shellLaunchConfig.attachPersistentProcess?.icon || this._shellLaunchConfig.icon; this._onIconChanged.fire({ instance: this, userInitiated: false });