Skip to content

Commit

Permalink
Change createTerminal signature to use options object
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Jun 15, 2021
1 parent 0baba5e commit 120f9b8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 25 deletions.
35 changes: 26 additions & 9 deletions src/vs/workbench/contrib/terminal/browser/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ export const enum TerminalConnectionState {
Connected
}

export const enum TerminalTarget {
TerminalView = 'view',
Editor = 'editor'
}

export interface ICreateTerminalOptions {
/**
* The shell launch config or profile to launch with, when not specified the default terminal
* profile will be used.
*/
config?: IShellLaunchConfig | ITerminalProfile;
// TODO: Ensure this is supported for profiles
/**
* The current working directory to start with, this will override IShellLaunchConfig.cwd if
* specified.
*/
cwd?: string | URI;
/**
* Where to create the terminal, when not specified the default target will be used.
*/
target?: TerminalTarget;
}

export interface ITerminalService {
readonly _serviceBrand: undefined;

Expand Down Expand Up @@ -131,16 +154,10 @@ export interface ITerminalService {

/**
* Creates a terminal.
* @param shell The shell launch configuration to use.
* @param options The options to create the terminal with, when not specified the default
* profile will be used at the default target.
*/
createTerminal(shell?: IShellLaunchConfig, cwd?: string | URI): ITerminalInstance;

/**
* Creates a terminal.
* @param profile The profile to launch the terminal with.
*/
createTerminal(profile: ITerminalProfile): ITerminalInstance;

createTerminal(options?: ICreateTerminalOptions): ITerminalInstance;
createContributedTerminalProfile(extensionIdentifier: string, id: string, isSplitTerminal: boolean): Promise<void>;

/**
Expand Down
8 changes: 5 additions & 3 deletions src/vs/workbench/contrib/terminal/browser/terminalActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function registerTerminalActions() {
}

if (profile) {
instance = terminalService.createTerminal(profile, cwd);
instance = terminalService.createTerminal({ config: profile, cwd });
} else {
instance = await terminalService.showProfileQuickPick('createInstance', cwd);
}
Expand Down Expand Up @@ -918,7 +918,9 @@ export function registerTerminalActions() {
}
const selected = await quickInputService.pick<IRemoteTerminalPick>(items, { canPickMany: false });
if (selected) {
const instance = terminalService.createTerminal({ attachPersistentProcess: selected.term });
const instance = terminalService.createTerminal({
config: { attachPersistentProcess: selected.term }
});
terminalService.setActiveInstance(instance);
terminalService.showPanel(true);
}
Expand Down Expand Up @@ -1799,7 +1801,7 @@ export function registerTerminalActions() {
if (quickSelectProfiles) {
const profile = quickSelectProfiles.find(profile => profile.profileName === profileSelection);
if (profile) {
const instance = terminalService.createTerminal(profile);
const instance = terminalService.createTerminal({ config: profile });
terminalService.setActiveInstance(instance);
} else {
console.warn(`No profile with name "${profileSelection}"`);
Expand Down
21 changes: 12 additions & 9 deletions src/vs/workbench/contrib/terminal/browser/terminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { IKeyMods, IPickOptions, IQuickInputButton, IQuickInputService, IQuickPi
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ILocalTerminalService, IOffProcessTerminalService, IShellLaunchConfig, ITerminalLaunchError, ITerminalProfile, ITerminalProfileObject, ITerminalsLayoutInfo, ITerminalsLayoutInfoById, TerminalSettingId, TerminalSettingPrefix } from 'vs/platform/terminal/common/terminal';
import { ThemeIcon } from 'vs/platform/theme/common/themeService';
import { IRemoteTerminalService, ITerminalExternalLinkProvider, ITerminalInstance, ITerminalService, ITerminalGroup, TerminalConnectionState, ITerminalProfileProvider } from 'vs/workbench/contrib/terminal/browser/terminal';
import { IRemoteTerminalService, ITerminalExternalLinkProvider, ITerminalInstance, ITerminalService, ITerminalGroup, TerminalConnectionState, ITerminalProfileProvider, ICreateTerminalOptions } from 'vs/workbench/contrib/terminal/browser/terminal';
import { IEditableData, IViewDescriptorService, IViewsService, ViewContainerLocation } from 'vs/workbench/common/views';
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/terminalConfigHelper';
import { TerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminalInstance';
Expand Down Expand Up @@ -277,7 +277,9 @@ export class TerminalService implements ITerminalService {
terminalLayouts.forEach((terminalLayout) => {
if (!terminalInstance) {
// create group and terminal
terminalInstance = this.createTerminal({ attachPersistentProcess: terminalLayout.terminal! });
terminalInstance = this.createTerminal({
config: { attachPersistentProcess: terminalLayout.terminal! }
});
group = this.getGroupForInstance(terminalInstance);
if (groupLayout.isActive) {
activeGroup = group;
Expand Down Expand Up @@ -988,7 +990,7 @@ export class TerminalService implements ITerminalService {
// create split, only valid if there's an active instance
instance = this.splitInstance(activeInstance, value.profile, cwd);
} else {
instance = this.createTerminal(value.profile, cwd);
instance = this.createTerminal({ config: value.profile, cwd });
}
}

Expand Down Expand Up @@ -1100,13 +1102,14 @@ export class TerminalService implements ITerminalService {
return {};
}

createTerminal(shellLaunchConfig?: IShellLaunchConfig): ITerminalInstance;
createTerminal(profile: ITerminalProfile, cwd?: string | URI): ITerminalInstance;
createTerminal(shellLaunchConfigOrProfile: IShellLaunchConfig | ITerminalProfile, cwd?: string | URI): ITerminalInstance {
const shellLaunchConfig = this._convertProfileToShellLaunchConfig(shellLaunchConfigOrProfile);
// createTerminal(shellLaunchConfig?: IShellLaunchConfig): ITerminalInstance;
// createTerminal(profile: ITerminalProfile, cwd?: string | URI): ITerminalInstance;
// createTerminal(shellLaunchConfigOrProfile: IShellLaunchConfig | ITerminalProfile, cwd?: string | URI): ITerminalInstance {
createTerminal(options?: ICreateTerminalOptions): ITerminalInstance {
const shellLaunchConfig = this._convertProfileToShellLaunchConfig(options?.config);

if (cwd) {
shellLaunchConfig.cwd = cwd;
if (options?.cwd) {
shellLaunchConfig.cwd = options.cwd;
}

if (!shellLaunchConfig.customPtyImplementation && !this.isProcessSupportRegistered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ export class TestingOutputTerminalService implements ITestingOutputTerminalServi

const output = new TestOutputProcess();
this.showResultsInTerminal(this.terminalService.createTerminal({
isFeatureTerminal: true,
icon: testingViewIcon,
customPtyImplementation: () => output,
name: getTitle(result),
config: {
isFeatureTerminal: true,
icon: testingViewIcon,
customPtyImplementation: () => output,
name: getTitle(result),
}
}), output, result);
}

Expand Down

0 comments on commit 120f9b8

Please sign in to comment.