From 120f9b88cdeb8ae3e722e82c346e15589301fd6f Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Tue, 15 Jun 2021 04:34:42 -0700 Subject: [PATCH] Change createTerminal signature to use options object --- .../contrib/terminal/browser/terminal.ts | 35 ++++++++++++++----- .../terminal/browser/terminalActions.ts | 8 +++-- .../terminal/browser/terminalService.ts | 21 ++++++----- .../browser/testingOutputTerminalService.ts | 10 +++--- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/vs/workbench/contrib/terminal/browser/terminal.ts b/src/vs/workbench/contrib/terminal/browser/terminal.ts index d527ae75a51f9..39ca82e024ab0 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminal.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminal.ts @@ -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; @@ -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; /** diff --git a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts index e6ebe76e10aa5..7535415414f6d 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalActions.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalActions.ts @@ -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); } @@ -918,7 +918,9 @@ export function registerTerminalActions() { } const selected = await quickInputService.pick(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); } @@ -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}"`); diff --git a/src/vs/workbench/contrib/terminal/browser/terminalService.ts b/src/vs/workbench/contrib/terminal/browser/terminalService.ts index 7184cad2b88ab..651aff5712cbf 100644 --- a/src/vs/workbench/contrib/terminal/browser/terminalService.ts +++ b/src/vs/workbench/contrib/terminal/browser/terminalService.ts @@ -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'; @@ -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; @@ -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 }); } } @@ -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) { diff --git a/src/vs/workbench/contrib/testing/browser/testingOutputTerminalService.ts b/src/vs/workbench/contrib/testing/browser/testingOutputTerminalService.ts index e09599c30ebd4..3e2cbafbb0c63 100644 --- a/src/vs/workbench/contrib/testing/browser/testingOutputTerminalService.ts +++ b/src/vs/workbench/contrib/testing/browser/testingOutputTerminalService.ts @@ -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); }