Move editor creation into new service
This commit is contained in:
parent
4475d8461e
commit
a215c798d5
4 changed files with 54 additions and 14 deletions
|
@ -23,7 +23,7 @@ import { registerColors } from 'vs/workbench/contrib/terminal/common/terminalCol
|
|||
import { setupTerminalCommands } from 'vs/workbench/contrib/terminal/browser/terminalCommands';
|
||||
import { TerminalService } from 'vs/workbench/contrib/terminal/browser/terminalService';
|
||||
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
|
||||
import { IRemoteTerminalService, ITerminalInstanceService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { IRemoteTerminalService, ITerminalEditorService, ITerminalInstanceService, ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
|
||||
import { IQuickAccessRegistry, Extensions as QuickAccessExtensions } from 'vs/platform/quickinput/common/quickAccess';
|
||||
|
@ -42,9 +42,11 @@ import { EditorDescriptor, IEditorRegistry } from 'vs/workbench/browser/editor';
|
|||
import { TerminalInputSerializer, TerminalEditor } from 'vs/workbench/contrib/terminal/browser/terminalEditor';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
|
||||
import { TerminalEditorService } from 'vs/workbench/contrib/terminal/browser/terminalEditorService';
|
||||
|
||||
// Register services
|
||||
registerSingleton(ITerminalService, TerminalService, true);
|
||||
registerSingleton(ITerminalEditorService, TerminalEditorService, true);
|
||||
registerSingleton(IRemoteTerminalService, RemoteTerminalService);
|
||||
registerSingleton(ITerminalInstanceService, TerminalInstanceService, true);
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import { Orientation } from 'vs/base/browser/ui/splitview/splitview';
|
|||
import { IEditableData } from 'vs/workbench/common/views';
|
||||
|
||||
export const ITerminalService = createDecorator<ITerminalService>('terminalService');
|
||||
export const ITerminalEditorService = createDecorator<ITerminalEditorService>('terminalEditorService');
|
||||
export const ITerminalInstanceService = createDecorator<ITerminalInstanceService>('terminalInstanceService');
|
||||
export const IRemoteTerminalService = createDecorator<IRemoteTerminalService>('remoteTerminalService');
|
||||
|
||||
|
@ -234,6 +235,18 @@ export interface ITerminalService {
|
|||
safeDisposeTerminal(instance: ITerminalInstance): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* This service is responsible for integrating with the editor service and managing terminal
|
||||
* editors.
|
||||
*/
|
||||
export interface ITerminalEditorService {
|
||||
readonly _serviceBrand: undefined;
|
||||
|
||||
readonly terminalEditorInstances: ITerminalInstance[];
|
||||
|
||||
createEditor(instance: ITerminalInstance): Promise<void>;
|
||||
}
|
||||
|
||||
export interface IRemoteTerminalService extends IOffProcessTerminalService {
|
||||
createProcess(shellLaunchConfig: IShellLaunchConfig, configuration: ICompleteTerminalConfiguration, activeWorkspaceRootUri: URI | undefined, cols: number, rows: number, shouldPersist: boolean, configHelper: ITerminalConfigHelper): Promise<ITerminalChildProcess>;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { ITerminalEditorService, ITerminalInstance, TerminalTarget } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
|
||||
export class TerminalEditorService implements ITerminalEditorService {
|
||||
declare _serviceBrand: undefined;
|
||||
|
||||
terminalEditorInstances: ITerminalInstance[] = [];
|
||||
|
||||
private _editorInputs: Map</*instanceId*/number, TerminalEditorInput> = new Map();
|
||||
|
||||
constructor(
|
||||
@IEditorService private readonly _editorService: IEditorService
|
||||
) {
|
||||
// TODO: Multiplex instance events
|
||||
}
|
||||
|
||||
async createEditor(instance: ITerminalInstance): Promise<void> {
|
||||
instance.target = TerminalTarget.Editor;
|
||||
const input = new TerminalEditorInput(instance);
|
||||
this._editorInputs.set(instance.instanceId, input);
|
||||
await this._editorService.openEditor(input, {
|
||||
pinned: true,
|
||||
forceReload: true
|
||||
});
|
||||
this.terminalEditorInstances.push(instance);
|
||||
}
|
||||
}
|
|
@ -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, ICreateTerminalOptions, TerminalTarget } from 'vs/workbench/contrib/terminal/browser/terminal';
|
||||
import { IRemoteTerminalService, ITerminalExternalLinkProvider, ITerminalInstance, ITerminalService, ITerminalGroup, TerminalConnectionState, ITerminalProfileProvider, ICreateTerminalOptions, TerminalTarget, ITerminalEditorService } 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';
|
||||
|
@ -42,8 +42,6 @@ import { Orientation } from 'vs/base/browser/ui/sash/sash';
|
|||
import { registerTerminalDefaultProfileConfiguration } from 'vs/platform/terminal/common/terminalPlatformConfiguration';
|
||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
|
||||
export class TerminalService implements ITerminalService {
|
||||
declare _serviceBrand: undefined;
|
||||
|
@ -136,7 +134,6 @@ export class TerminalService implements ITerminalService {
|
|||
constructor(
|
||||
@IContextKeyService private _contextKeyService: IContextKeyService,
|
||||
@IWorkbenchLayoutService private _layoutService: IWorkbenchLayoutService,
|
||||
@IEditorService private readonly _editorService: IEditorService,
|
||||
@ILabelService labelService: ILabelService,
|
||||
@ILifecycleService lifecycleService: ILifecycleService,
|
||||
@IDialogService private _dialogService: IDialogService,
|
||||
|
@ -150,6 +147,7 @@ export class TerminalService implements ITerminalService {
|
|||
@IRemoteTerminalService private readonly _remoteTerminalService: IRemoteTerminalService,
|
||||
@ITelemetryService private readonly _telemetryService: ITelemetryService,
|
||||
@ITerminalContributionService private readonly _terminalContributionService: ITerminalContributionService,
|
||||
@ITerminalEditorService private readonly _terminalEditorService: ITerminalEditorService,
|
||||
@IExtensionService private readonly _extensionService: IExtensionService,
|
||||
@INotificationService private readonly _notificationService: INotificationService,
|
||||
@optional(ILocalTerminalService) localTerminalService: ILocalTerminalService
|
||||
|
@ -1139,15 +1137,8 @@ export class TerminalService implements ITerminalService {
|
|||
|
||||
let instance: ITerminalInstance;
|
||||
if (options?.target === TerminalTarget.Editor) {
|
||||
const input = TerminalEditorInput.copy(this, this._instantiationService);
|
||||
instance = input.terminalInstance;
|
||||
instance.target = TerminalTarget.Editor;
|
||||
// TODO: This is a promise - handle errors
|
||||
this._editorService.openEditor(input, {
|
||||
pinned: true,
|
||||
forceReload: true
|
||||
});
|
||||
// TODO: Push to terminal editors
|
||||
instance = this.createInstance(shellLaunchConfig);
|
||||
this._terminalEditorService.createEditor(instance);
|
||||
this._initInstanceListeners(instance);
|
||||
this._onInstancesChanged.fire();
|
||||
} else {
|
||||
|
@ -1163,6 +1154,7 @@ export class TerminalService implements ITerminalService {
|
|||
this._onInstancesChanged.fire();
|
||||
this._onGroupsChanged.fire();
|
||||
}
|
||||
|
||||
if (this.terminalInstances.length === 1) {
|
||||
// It's the first instance so it should be made active automatically, this must fire
|
||||
// after onInstancesChanged so consumers can react to the instance being added first
|
||||
|
|
Loading…
Reference in a new issue