Skip to content

Commit 4af3e14

Browse files
committed
1 parent 9990fa9 commit 4af3e14

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/vs/platform/terminal/common/terminal.ts

+5
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ export interface IShellLaunchConfig {
503503
* Opt-out of the default terminal persistence on restart and reload
504504
*/
505505
disablePersistence?: boolean;
506+
507+
/**
508+
* This is a split terminal that inherited its parent's cwd
509+
*/
510+
splitInheritedCwd?: boolean;
506511
}
507512

508513
export interface ICreateContributedTerminalProfileOptions {

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
12321232
// Set the initial name based on the _resolved_ shell launch config, this will also
12331233
// ensure the resolved icon gets shown
12341234
if (!this._labelComputer) {
1235-
this._labelComputer = this._register(new TerminalLabelComputer(this._configHelper, this, this._workspaceContextService));
1235+
this._labelComputer = this._register(new TerminalLabelComputer(this._configHelper, this, this._workspaceContextService, this.shellLaunchConfig.splitInheritedCwd));
12361236
this._labelComputer.onDidChangeLabel(e => {
12371237
this._title = e.title;
12381238
this._description = e.description;
@@ -2257,7 +2257,8 @@ export class TerminalLabelComputer extends Disposable {
22572257
constructor(
22582258
private readonly _configHelper: TerminalConfigHelper,
22592259
private readonly _instance: Pick<ITerminalInstance, 'shellLaunchConfig' | 'cwd' | 'fixedCols' | 'fixedRows' | 'initialCwd' | 'processName' | 'sequence' | 'userHome' | 'workspaceFolder' | 'staticTitle' | 'capabilities' | 'title' | 'description'>,
2260-
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService
2260+
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService,
2261+
private readonly _splitInheritedCwd?: boolean
22612262
) {
22622263
super();
22632264
}
@@ -2298,7 +2299,7 @@ export class TerminalLabelComputer extends Disposable {
22982299
const detection = this._instance.capabilities.has(TerminalCapability.CwdDetection) || this._instance.capabilities.has(TerminalCapability.NaiveCwdDetection);
22992300
const zeroRootWorkspace = this._workspaceContextService.getWorkspace().folders.length === 0 && this.pathsEqual(templateProperties.cwd, this._instance.userHome || this._configHelper.config.cwd);
23002301
const singleRootWorkspace = this._workspaceContextService.getWorkspace().folders.length === 1 && this.pathsEqual(templateProperties.cwd, this._configHelper.config.cwd || this._workspaceContextService.getWorkspace().folders[0]?.uri.fsPath);
2301-
if (this._instance.cwd !== this._instance.initialCwd) {
2302+
if ((this._instance.cwd !== this._instance.initialCwd) || this._splitInheritedCwd) {
23022303
templateProperties.cwdFolder = (!templateProperties.cwd || !detection || zeroRootWorkspace || singleRootWorkspace) ? '' : path.basename(templateProperties.cwd);
23032304
}
23042305

src/vs/workbench/contrib/terminal/browser/terminalService.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ export class TerminalService implements ITerminalService {
929929

930930
const splitActiveTerminal = typeof options?.location === 'object' && 'splitActiveTerminal' in options.location ? options.location.splitActiveTerminal : typeof options?.location === 'object' ? 'parentTerminal' in options.location : false;
931931

932-
this._resolveCwd(shellLaunchConfig, splitActiveTerminal, options);
932+
shellLaunchConfig.splitInheritedCwd = await this._resolveCwd(shellLaunchConfig, splitActiveTerminal, options);
933933

934934
// Launch the contributed profile
935935
if (contributedProfile) {
@@ -975,7 +975,7 @@ export class TerminalService implements ITerminalService {
975975
return this._createTerminal(shellLaunchConfig, location, options);
976976
}
977977

978-
private async _resolveCwd(shellLaunchConfig: IShellLaunchConfig, splitActiveTerminal: boolean, options?: ICreateTerminalOptions): Promise<void> {
978+
private async _resolveCwd(shellLaunchConfig: IShellLaunchConfig, splitActiveTerminal: boolean, options?: ICreateTerminalOptions): Promise<boolean | undefined> {
979979
let cwd = shellLaunchConfig.cwd;
980980
if (!cwd) {
981981
if (options?.cwd) {
@@ -989,8 +989,10 @@ export class TerminalService implements ITerminalService {
989989
throw new Error('Cannot split without an active instance');
990990
}
991991
shellLaunchConfig.cwd = await getCwdForSplit(this.configHelper, parent, this._workspaceContextService.getWorkspace().folders, this._commandService);
992+
return !!shellLaunchConfig.cwd;
992993
}
993994
}
995+
return undefined;
994996
}
995997

996998
private _splitTerminal(shellLaunchConfig: IShellLaunchConfig, location: TerminalLocation, parent: ITerminalInstance): ITerminalInstance {

0 commit comments

Comments
 (0)