Skip to content

Commit

Permalink
Prevent creation of terminals when processes aren't supported
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Sep 1, 2020
1 parent 6d22bbd commit c3c933a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
54 changes: 30 additions & 24 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ToggleTerminalAction extends ToggleViewAction {
}

async run() {
if (this.terminalService.terminalInstances.length === 0) {
if (this.terminalService.isProcessSupportRegistered && this.terminalService.terminalInstances.length === 0) {
// If there is not yet an instance attempt to create it here so that we can suggest a
// new shell on Windows (and not do so when the panel is restored on reload).
const newTerminalInstance = this.terminalService.createTerminal(undefined);
Expand Down Expand Up @@ -201,23 +201,25 @@ export class CreateNewTerminalAction extends Action {
}
}

let instance: ITerminalInstance | undefined;
if (folders.length <= 1) {
// Allow terminal service to handle the path when there is only a
// single root
instance = this._terminalService.createTerminal(undefined);
} else {
const options: IPickOptions<IQuickPickItem> = {
placeHolder: localize('workbench.action.terminal.newWorkspacePlaceholder', "Select current working directory for new terminal")
};
const workspace = await this._commandService.executeCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, [options]);
if (!workspace) {
// Don't create the instance if the workspace picker was canceled
return;
if (this._terminalService.isProcessSupportRegistered) {
let instance: ITerminalInstance | undefined;
if (folders.length <= 1) {
// Allow terminal service to handle the path when there is only a
// single root
instance = this._terminalService.createTerminal(undefined);
} else {
const options: IPickOptions<IQuickPickItem> = {
placeHolder: localize('workbench.action.terminal.newWorkspacePlaceholder', "Select current working directory for new terminal")
};
const workspace = await this._commandService.executeCommand(PICK_WORKSPACE_FOLDER_COMMAND_ID, [options]);
if (!workspace) {
// Don't create the instance if the workspace picker was canceled
return;
}
instance = this._terminalService.createTerminal({ cwd: workspace.uri });
}
instance = this._terminalService.createTerminal({ cwd: workspace.uri });
this._terminalService.setActiveInstance(instance);
}
this._terminalService.setActiveInstance(instance);
await this._terminalService.showPanel(true);
}
}
Expand Down Expand Up @@ -442,11 +444,13 @@ export function registerTerminalActions() {
}
async run(accessor: ServicesAccessor) {
const terminalService = accessor.get(ITerminalService);
const instance = terminalService.createTerminal(undefined);
if (!instance) {
return;
if (terminalService.isProcessSupportRegistered) {
const instance = terminalService.createTerminal(undefined);
if (!instance) {
return;
}
terminalService.setActiveInstance(instance);
}
terminalService.setActiveInstance(instance);
await terminalService.showPanel(true);
}
});
Expand Down Expand Up @@ -1183,11 +1187,13 @@ export function registerTerminalActions() {
}
async run(accessor: ServicesAccessor, args?: { cwd?: string }) {
const terminalService = accessor.get(ITerminalService);
const instance = terminalService.createTerminal({ cwd: args?.cwd });
if (!instance) {
return;
if (terminalService.isProcessSupportRegistered) {
const instance = terminalService.createTerminal({ cwd: args?.cwd });
if (!instance) {
return;
}
terminalService.setActiveInstance(instance);
}
terminalService.setActiveInstance(instance);
return terminalService.showPanel(true);
}
});
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ export class TerminalService implements ITerminalService {
}

public createTerminal(shell: IShellLaunchConfig = {}): ITerminalInstance {
if (!this.isProcessSupportRegistered) {
throw new Error('Could not create terminal when process support is not registered');
}
if (shell.hideFromUser) {
const instance = this.createInstance(undefined, shell);
this._backgroundedTerminalInstances.push(instance);
Expand Down

0 comments on commit c3c933a

Please sign in to comment.