Skip to content

Commit

Permalink
fix #141686
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Jan 28, 2022
1 parent 9990fa9 commit 4af3e14
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2257,7 +2257,8 @@ export class TerminalLabelComputer extends Disposable {
constructor(
private readonly _configHelper: TerminalConfigHelper,
private readonly _instance: Pick<ITerminalInstance, 'shellLaunchConfig' | 'cwd' | 'fixedCols' | 'fixedRows' | 'initialCwd' | 'processName' | 'sequence' | 'userHome' | 'workspaceFolder' | 'staticTitle' | 'capabilities' | 'title' | 'description'>,
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService,
private readonly _splitInheritedCwd?: boolean
) {
super();
}
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<void> {
private async _resolveCwd(shellLaunchConfig: IShellLaunchConfig, splitActiveTerminal: boolean, options?: ICreateTerminalOptions): Promise<boolean | undefined> {
let cwd = shellLaunchConfig.cwd;
if (!cwd) {
if (options?.cwd) {
Expand All @@ -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 {
Expand Down

0 comments on commit 4af3e14

Please sign in to comment.