diff --git a/src/vs/platform/terminal/common/terminal.ts b/src/vs/platform/terminal/common/terminal.ts index 8aadbcd03762c..67acbd29a3bfe 100644 --- a/src/vs/platform/terminal/common/terminal.ts +++ b/src/vs/platform/terminal/common/terminal.ts @@ -503,6 +503,11 @@ export interface IShellLaunchConfig { * Opt-out of the default terminal persistence on restart and reload */ disablePersistence?: boolean; + + /** + * This is a split terminal that inherited its parent's cwd + */ + splitInheritedCwd?: boolean; } export interface ICreateContributedTerminalProfileOptions { diff --git a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts index d8b6b5fd7301c..114970c25e6d0 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalInstance.ts @@ -1232,7 +1232,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance { // Set the initial name based on the _resolved_ shell launch config, this will also // ensure the resolved icon gets shown if (!this._labelComputer) { - this._labelComputer = this._register(new TerminalLabelComputer(this._configHelper, this, this._workspaceContextService)); + this._labelComputer = this._register(new TerminalLabelComputer(this._configHelper, this, this._workspaceContextService, this.shellLaunchConfig.splitInheritedCwd)); this._labelComputer.onDidChangeLabel(e => { this._title = e.title; this._description = e.description; @@ -2257,7 +2257,8 @@ export class TerminalLabelComputer extends Disposable { constructor( private readonly _configHelper: TerminalConfigHelper, private readonly _instance: Pick, - @IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService + @IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService, + private readonly _splitInheritedCwd?: boolean ) { super(); } @@ -2298,7 +2299,7 @@ export class TerminalLabelComputer extends Disposable { const detection = this._instance.capabilities.has(TerminalCapability.CwdDetection) || this._instance.capabilities.has(TerminalCapability.NaiveCwdDetection); const zeroRootWorkspace = this._workspaceContextService.getWorkspace().folders.length === 0 && this.pathsEqual(templateProperties.cwd, this._instance.userHome || this._configHelper.config.cwd); const singleRootWorkspace = this._workspaceContextService.getWorkspace().folders.length === 1 && this.pathsEqual(templateProperties.cwd, this._configHelper.config.cwd || this._workspaceContextService.getWorkspace().folders[0]?.uri.fsPath); - if (this._instance.cwd !== this._instance.initialCwd) { + if ((this._instance.cwd !== this._instance.initialCwd) || this._splitInheritedCwd) { templateProperties.cwdFolder = (!templateProperties.cwd || !detection || zeroRootWorkspace || singleRootWorkspace) ? '' : path.basename(templateProperties.cwd); } diff --git a/src/vs/workbench/contrib/terminal/browser/terminalService.ts b/src/vs/workbench/contrib/terminal/browser/terminalService.ts index 9a2186bec36ab..9496ea2e2d6fa 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalService.ts @@ -929,7 +929,7 @@ export class TerminalService implements ITerminalService { const splitActiveTerminal = typeof options?.location === 'object' && 'splitActiveTerminal' in options.location ? options.location.splitActiveTerminal : typeof options?.location === 'object' ? 'parentTerminal' in options.location : false; - this._resolveCwd(shellLaunchConfig, splitActiveTerminal, options); + shellLaunchConfig.splitInheritedCwd = await this._resolveCwd(shellLaunchConfig, splitActiveTerminal, options); // Launch the contributed profile if (contributedProfile) { @@ -975,7 +975,7 @@ export class TerminalService implements ITerminalService { return this._createTerminal(shellLaunchConfig, location, options); } - private async _resolveCwd(shellLaunchConfig: IShellLaunchConfig, splitActiveTerminal: boolean, options?: ICreateTerminalOptions): Promise { + private async _resolveCwd(shellLaunchConfig: IShellLaunchConfig, splitActiveTerminal: boolean, options?: ICreateTerminalOptions): Promise { let cwd = shellLaunchConfig.cwd; if (!cwd) { if (options?.cwd) { @@ -989,8 +989,10 @@ export class TerminalService implements ITerminalService { throw new Error('Cannot split without an active instance'); } shellLaunchConfig.cwd = await getCwdForSplit(this.configHelper, parent, this._workspaceContextService.getWorkspace().folders, this._commandService); + return !!shellLaunchConfig.cwd; } } + return undefined; } private _splitTerminal(shellLaunchConfig: IShellLaunchConfig, location: TerminalLocation, parent: ITerminalInstance): ITerminalInstance {