Skip to content

Commit

Permalink
Merge pull request #132870 from microsoft/tyriar/r160_pty
Browse files Browse the repository at this point in the history
Fix launching Pseudoterminal-based and local terminals in remote workspaces before the connection is established
  • Loading branch information
Tyriar authored Sep 10, 2021
2 parents 5e2f963 + 3361f8d commit 83bd43b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/vs/workbench/api/browser/mainThreadTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
isExtensionOwnedTerminal: launchConfig.isExtensionOwnedTerminal,
useShellEnvironment: launchConfig.useShellEnvironment,
};
this._extHostTerminals.set(extHostTerminalId, new Promise(async r => {
const terminal = new Promise<ITerminalInstance>(async r => {
const terminal = await this._terminalService.createTerminal({
config: shellLaunchConfig,
location: await this._deserializeParentTerminal(launchConfig.location)
});
r(terminal);
}));
});
this._extHostTerminals.set(extHostTerminalId, terminal);
await terminal;
}

private async _deserializeParentTerminal(location?: TerminalLocation | TerminalEditorLocationOptions | { parentTerminal: ExtHostTerminalIdentifier } | { splitActiveTerminal: boolean, location?: TerminalLocation }): Promise<TerminalLocation | TerminalEditorLocationOptions | { parentTerminal: ITerminalInstance } | { splitActiveTerminal: boolean } | undefined> {
Expand Down
10 changes: 9 additions & 1 deletion src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,9 +1148,17 @@ export class TerminalService implements ITerminalService {


async createTerminal(options?: ICreateTerminalOptions): Promise<ITerminalInstance> {
// Await the initialization of available profiles as long as this is not a pty terminal or a
// local terminal in a remote workspace as profile won't be used in those cases and these
// terminals need to be launched before remote connections are established.
if (!this._availableProfiles) {
await this._refreshAvailableProfilesNow();
const isPtyTerminal = options?.config && 'customPtyImplementation' in options.config;
const isLocalInRemoteTerminal = this._remoteAgentService.getConnection() && URI.isUri(options?.cwd) && options?.cwd.scheme === Schemas.vscodeFileResource;
if (!isPtyTerminal && !isLocalInRemoteTerminal) {
await this._refreshAvailableProfilesNow();
}
}

const config = options?.config || this._availableProfiles?.find(p => p.profileName === this._defaultProfileName);
const shellLaunchConfig = config && 'extensionIdentifier' in config ? {} : this._convertProfileToShellLaunchConfig(config || {});

Expand Down

0 comments on commit 83bd43b

Please sign in to comment.