Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for shell type to be ready before preparing path for shell #170720

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/vs/platform/terminal/common/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const enum WindowsShellType {
Wsl = 'wsl',
GitBash = 'gitbash'
}
export type TerminalShellType = PosixShellType | WindowsShellType | undefined;
export type TerminalShellType = PosixShellType | WindowsShellType;

export interface IRawTerminalInstanceLayoutInfo<T> {
relativeSize: number;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/terminal/node/terminalProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class TerminalProcess extends Disposable implements ITerminalChildProcess
get exitMessage(): string | undefined { return this._exitMessage; }

get currentTitle(): string { return this._windowsShellHelper?.shellTitle || this._currentTitle; }
get shellType(): TerminalShellType { return isWindows ? this._windowsShellHelper?.shellType : posixShellTypeMap.get(this._currentTitle); }
get shellType(): TerminalShellType | undefined { return isWindows ? this._windowsShellHelper?.shellType : posixShellTypeMap.get(this._currentTitle); }
get hasChildProcesses(): boolean { return this._childProcessMonitor?.hasChildProcesses || false; }

private readonly _onProcessData = this._register(new Emitter<string>());
Expand Down
10 changes: 5 additions & 5 deletions src/vs/platform/terminal/node/windowsShellHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import type * as WindowsProcessTreeType from 'windows-process-tree';

export interface IWindowsShellHelper extends IDisposable {
readonly onShellNameChanged: Event<string>;
readonly onShellTypeChanged: Event<TerminalShellType>;
getShellType(title: string): TerminalShellType;
readonly onShellTypeChanged: Event<TerminalShellType | undefined>;
getShellType(title: string): TerminalShellType | undefined;
getShellName(): Promise<string>;
}

Expand Down Expand Up @@ -43,8 +43,8 @@ export class WindowsShellHelper extends Disposable implements IWindowsShellHelpe
get shellTitle(): string { return this._shellTitle; }
private readonly _onShellNameChanged = new Emitter<string>();
get onShellNameChanged(): Event<string> { return this._onShellNameChanged.event; }
private readonly _onShellTypeChanged = new Emitter<TerminalShellType>();
get onShellTypeChanged(): Event<TerminalShellType> { return this._onShellTypeChanged.event; }
private readonly _onShellTypeChanged = new Emitter<TerminalShellType | undefined>();
get onShellTypeChanged(): Event<TerminalShellType | undefined> { return this._onShellTypeChanged.event; }

constructor(
private _rootProcessId: number
Expand Down Expand Up @@ -141,7 +141,7 @@ export class WindowsShellHelper extends Disposable implements IWindowsShellHelpe
return this._currentRequest;
}

getShellType(executable: string): TerminalShellType {
getShellType(executable: string): TerminalShellType | undefined {
switch (executable.toLowerCase()) {
case 'cmd.exe':
return WindowsShellType.CommandPrompt;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ export interface ITerminalInstance {
/**
* The shell type of the terminal.
*/
readonly shellType: TerminalShellType;
readonly shellType: TerminalShellType | undefined;

/**
* The focus state of the terminal before exiting.
Expand Down
10 changes: 6 additions & 4 deletions src/vs/workbench/contrib/terminal/browser/terminalInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _exitReason: TerminalExitReason | undefined;
private _skipTerminalCommands: string[];
private _aliases: string[][] | undefined;
private _shellType: TerminalShellType;
private _shellType: TerminalShellType | undefined;
private _title: string = '';
private _titleSource: TitleEventSource = TitleEventSource.Process;
private _container: HTMLElement | undefined;
Expand Down Expand Up @@ -292,7 +292,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
get hadFocusOnExit(): boolean { return this._hadFocusOnExit; }
get isTitleSetByProcess(): boolean { return !!this._messageTitleDisposable; }
get shellLaunchConfig(): IShellLaunchConfig { return this._shellLaunchConfig; }
get shellType(): TerminalShellType { return this._shellType; }
get shellType(): TerminalShellType | undefined { return this._shellType; }
get os(): OperatingSystem | undefined { return this._processManager.os; }
get navigationMode(): INavigationMode | undefined { return this._navigationModeAddon; }
get isRemote(): boolean { return this._processManager.remoteAuthority !== undefined; }
Expand Down Expand Up @@ -1341,7 +1341,9 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
return this.sendText(await this.preparePathForShell(originalPath), addNewLine);
}

preparePathForShell(originalPath: string | URI): Promise<string> {
async preparePathForShell(originalPath: string | URI): Promise<string> {
// Wait for shell type to be ready
await this.processReady;
return preparePathForShell(originalPath, this.shellLaunchConfig.executable, this.title, this.shellType, this._processManager.backend, this._processManager.os);
}

Expand Down Expand Up @@ -1944,7 +1946,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
}
}

setShellType(shellType: TerminalShellType) {
setShellType(shellType: TerminalShellType | undefined) {
this._shellType = shellType;
if (shellType) {
this._terminalShellTypeContextKey.set(shellType?.toString());
Expand Down
6 changes: 3 additions & 3 deletions src/vs/workbench/contrib/terminal/common/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const enum StorageKeys {
}

let commandHistory: ITerminalPersistedHistory<{ shellType: TerminalShellType }> | undefined = undefined;
export function getCommandHistory(accessor: ServicesAccessor): ITerminalPersistedHistory<{ shellType: TerminalShellType }> {
export function getCommandHistory(accessor: ServicesAccessor): ITerminalPersistedHistory<{ shellType: TerminalShellType | undefined }> {
if (!commandHistory) {
commandHistory = accessor.get(IInstantiationService).createInstance(TerminalPersistedHistory, 'commands') as TerminalPersistedHistory<{ shellType: TerminalShellType }>;
}
Expand All @@ -69,8 +69,8 @@ export function getDirectoryHistory(accessor: ServicesAccessor): ITerminalPersis
}

// Shell file history loads once per shell per window
const shellFileHistory: Map<TerminalShellType, string[] | null> = new Map();
export async function getShellFileHistory(accessor: ServicesAccessor, shellType: TerminalShellType): Promise<string[]> {
const shellFileHistory: Map<TerminalShellType | undefined, string[] | null> = new Map();
export async function getShellFileHistory(accessor: ServicesAccessor, shellType: TerminalShellType | undefined): Promise<string[]> {
const cached = shellFileHistory.get(shellType);
if (cached === null) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ export async function createTerminalEnvironment(
* tests.
* @returns An escaped version of the path to be execuded in the terminal.
*/
export async function preparePathForShell(resource: string | URI, executable: string | undefined, title: string, shellType: TerminalShellType, backend: Pick<ITerminalBackend, 'getWslPath'> | undefined, os: OperatingSystem | undefined, isWindowsFrontend: boolean = isWindows): Promise<string> {
export async function preparePathForShell(resource: string | URI, executable: string | undefined, title: string, shellType: TerminalShellType | undefined, backend: Pick<ITerminalBackend, 'getWslPath'> | undefined, os: OperatingSystem | undefined, isWindowsFrontend: boolean = isWindows): Promise<string> {
let originalPath: string;
if (isString(resource)) {
originalPath = resource;
Expand Down