Change:
Context: Essentially instead of creating s we will assign URIs to the shell launch configs and only create the terminals when the input is created.
This should also include the fix for splitCwd support in terminal editors:

Discussion:
import { ICompleteTerminalConfiguration } from 'vs/workbench/contrib/terminal/common/remoteTerminalChannel'; import { Orientation } from 'vs/base/browser/ui/splitview/splitview'; import { IEditableData } from 'vs/workbench/common/views'; <del> import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput'; </del> import { DeserializedTerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorSerializer'; <ins> import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput'; </ins> export const ITerminalService = createDecorator<ITerminalService>('terminalService'); export const ITerminalEditorService = createDecorator<ITerminalEditorService>('terminalEditorService');

readonly instances: readonly ITerminalInstance[]; openEditor(instance: ITerminalInstance, sideGroup?: boolean): Promise<void>; <del> getOrCreateEditorInput(instance: ITerminalInstance | DeserializedTerminalEditorInput | URI): TerminalEditorInput; </del> detachActiveEditorInstance(): ITerminalInstance; detachInstance(instance: ITerminalInstance): void; splitInstance(instanceToSplit: ITerminalInstance, shellLaunchConfig?: IShellLaunchConfig): ITerminalInstance; <del> revealActiveEditor(preserveFocus?: boolean): void </del> <ins> revealActiveEditor(preserveFocus?: boolean): void; resolveResource(instance: ITerminalInstance | URI): URI; reviveInput(deserializedInput: DeserializedTerminalEditorInput): TerminalEditorInput; getInputFromResource(resource: URI): TerminalEditorInput; </ins> } export interface ICreateTerminalOptions {

public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput | undefined { const terminalInstance = JSON.parse(serializedEditorInput); terminalInstance.resource = URI.parse(terminalInstance.resource); <del> const editor = this._terminalEditorService.getOrCreateEditorInput(terminalInstance); return editor; </del> <ins> return this._terminalEditorService.reviveInput(terminalInstance); </ins> } private _toJson(instance: ITerminalInstance): SerializedTerminalEditorInput {

import { EditorActivation } from 'vs/platform/editor/common/editor'; import { IInstantiationService, optional } from 'vs/platform/instantiation/common/instantiation'; import { IShellLaunchConfig, TerminalLocation } from 'vs/platform/terminal/common/terminal'; <del> import { IEditorInput, IEditorPane } from 'vs/workbench/common/editor'; </del> <ins> import { IEditorInput } from 'vs/workbench/common/editor'; </ins> import { IRemoteTerminalService, ITerminalEditorService, ITerminalInstance, ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal'; import { TerminalEditor } from 'vs/workbench/contrib/terminal/browser/terminalEditor'; import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';

} async openEditor(instance: ITerminalInstance, sideGroup: boolean = false): Promise<void> { <del> const input = this.getOrCreateEditorInput(instance); const editorPane: IEditorPane | undefined = await this._editorService.openEditor(input, { pinned: true, forceReload: true }, sideGroup ? SIDE_GROUP : input.group); input.setGroup(editorPane?.group); </del> <ins> const resource = this.resolveResource(instance); if (resource) { await this._editorService.openEditor({ resource: URI.revive(resource), options: { pinned: true, forceReload: true } }, sideGroup ? SIDE_GROUP : undefined); } </ins> } <del> getOrCreateEditorInput(instanceOrUri: ITerminalInstance | DeserializedTerminalEditorInput | URI, isFutureSplit: boolean = false): TerminalEditorInput { </del> <ins> resolveResource(instanceOrUri: ITerminalInstance | URI, isFutureSplit: boolean = false): URI { </ins> const resource: URI = URI.isUri(instanceOrUri) ? instanceOrUri : instanceOrUri.resource; const inputKey = resource.path; const cachedEditor = this._editorInputs.get(inputKey); <del> if (cachedEditor) { return cachedEditor; } if ('pid' in instanceOrUri) { instanceOrUri = this._terminalInstanceService.createInstance({ attachPersistentProcess: instanceOrUri }, TerminalLocation.Editor); </del> <ins> if (cachedEditor) { return cachedEditor.resource; </ins> } // Terminal from a different window

if (terminalIdentifier.instanceId) { this._primaryOffProcessTerminalService.requestDetachInstance(terminalIdentifier.workspaceId, terminalIdentifier.instanceId).then(attachPersistentProcess => { const instance = this._terminalInstanceService.createInstance({ attachPersistentProcess }, TerminalLocation.Editor, resource); <del> input.setTerminalInstance(instance); // trigger setInput on TerminalEditor setInput // which attaches to the element and updates the input </del> <ins> input = this._instantiationService.createInstance(TerminalEditorInput, resource, instance); </ins> this._editorService.openEditor(input, { pinned: true, forceReload: true

input.group ); this._registerInstance(inputKey, input, instance); <ins> return instanceOrUri; </ins> }); } }

instanceOrUri.target = TerminalLocation.Editor; input = this._instantiationService.createInstance(TerminalEditorInput, resource, instanceOrUri); this._registerInstance(inputKey, input, instanceOrUri); <ins> return input.resource; </ins> } else { <del> input = this._instantiationService.createInstance(TerminalEditorInput, instanceOrUri, undefined); this._editorInputs.set(inputKey, input); </del> <ins> return instanceOrUri; } } getInputFromResource(resource: URI): TerminalEditorInput { const input = this._editorInputs.get(resource.path); if (!input) { throw new Error(`Could not get input from resource: ${resource.path}`); </ins> } return input; }

} } const instance = this._terminalInstanceService.createInstance(shellLaunchConfig, TerminalLocation.Editor); <del> this._editorService.openEditor(this.getOrCreateEditorInput(instance), undefined, SIDE_GROUP); </del> <ins> const resource = this.resolveResource(instance); if (resource) { this._editorService.openEditor({ resource: URI.revive(resource), options: { pinned: true, forceReload: true } }, SIDE_GROUP); } </ins> return instance; } <ins> reviveInput(deserializedInput: DeserializedTerminalEditorInput): TerminalEditorInput { const resource: URI = URI.isUri(deserializedInput) ? deserializedInput : deserializedInput.resource; const inputKey = resource.path; if ('pid' in deserializedInput) { const instance = this._terminalInstanceService.createInstance({ attachPersistentProcess: deserializedInput }, TerminalLocation.Editor); instance.target = TerminalLocation.Editor; const input = this._instantiationService.createInstance(TerminalEditorInput, resource, instance); this._registerInstance(inputKey, input, instance); return input; } else { throw new Error(`Could not revive terminal editor input, ${deserializedInput}`); } } </ins> detachActiveEditorInstance(): ITerminalInstance { const activeEditor = this._editorService.activeEditor; if (!(activeEditor instanceof TerminalEditorInput)) {

sourceGroup.removeInstance(instance); } } <ins> const resolvedResource = this._terminalEditorService.resolveResource(instance || resource); const editor = this._terminalEditorService.getInputFromResource(resolvedResource) || { editor: URI.revive(resolvedResource) }; </ins> return { <del> editor: this._terminalEditorService.getOrCreateEditorInput(instance || resource), </del> <ins> editor, </ins> options: { ...options, pinned: true, forceReload: true } }; <del> } ); </del> <ins> }); </ins> this._forwardInstanceHostEvents(this._terminalGroupService); this._forwardInstanceHostEvents(this._terminalEditorService);