pass untyped terminal resource to editorService (#130113)
This commit is contained in:
parent
0b87133f5b
commit
4b6d224f63
4 changed files with 64 additions and 27 deletions
|
@ -18,8 +18,8 @@ import { ITerminalStatusList } from 'vs/workbench/contrib/terminal/browser/termi
|
|||
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';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
import { DeserializedTerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorSerializer';
|
||||
import { TerminalEditorInput } from 'vs/workbench/contrib/terminal/browser/terminalEditorInput';
|
||||
|
||||
export const ITerminalService = createDecorator<ITerminalService>('terminalService');
|
||||
export const ITerminalEditorService = createDecorator<ITerminalEditorService>('terminalEditorService');
|
||||
|
@ -198,11 +198,13 @@ export interface ITerminalEditorService extends ITerminalInstanceHost, ITerminal
|
|||
readonly instances: readonly ITerminalInstance[];
|
||||
|
||||
openEditor(instance: ITerminalInstance, sideGroup?: boolean): Promise<void>;
|
||||
getOrCreateEditorInput(instance: ITerminalInstance | DeserializedTerminalEditorInput | URI): TerminalEditorInput;
|
||||
detachActiveEditorInstance(): ITerminalInstance;
|
||||
detachInstance(instance: ITerminalInstance): void;
|
||||
splitInstance(instanceToSplit: ITerminalInstance, shellLaunchConfig?: IShellLaunchConfig): ITerminalInstance;
|
||||
revealActiveEditor(preserveFocus?: boolean): void
|
||||
revealActiveEditor(preserveFocus?: boolean): void;
|
||||
resolveResource(instance: ITerminalInstance | URI): URI;
|
||||
reviveInput(deserializedInput: DeserializedTerminalEditorInput): TerminalEditorInput;
|
||||
getInputFromResource(resource: URI): TerminalEditorInput;
|
||||
}
|
||||
|
||||
export interface ICreateTerminalOptions {
|
||||
|
|
|
@ -31,8 +31,7 @@ export class TerminalInputSerializer implements IEditorSerializer {
|
|||
public deserialize(instantiationService: IInstantiationService, serializedEditorInput: string): EditorInput | undefined {
|
||||
const terminalInstance = JSON.parse(serializedEditorInput);
|
||||
terminalInstance.resource = URI.parse(terminalInstance.resource);
|
||||
const editor = this._terminalEditorService.getOrCreateEditorInput(terminalInstance);
|
||||
return editor;
|
||||
return this._terminalEditorService.reviveInput(terminalInstance);
|
||||
}
|
||||
|
||||
private _toJson(instance: ITerminalInstance): SerializedTerminalEditorInput {
|
||||
|
|
|
@ -10,7 +10,7 @@ import { FindReplaceState } from 'vs/editor/contrib/find/findState';
|
|||
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';
|
||||
import { IEditorInput, IEditorPane } from 'vs/workbench/common/editor';
|
||||
import { IEditorInput } from 'vs/workbench/common/editor';
|
||||
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';
|
||||
|
@ -159,24 +159,27 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
|
|||
}
|
||||
|
||||
async openEditor(instance: ITerminalInstance, sideGroup: boolean = false): Promise<void> {
|
||||
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);
|
||||
const resource = this.resolveResource(instance);
|
||||
if (resource) {
|
||||
await this._editorService.openEditor({
|
||||
resource: URI.revive(resource),
|
||||
options:
|
||||
{
|
||||
pinned: true,
|
||||
forceReload: true
|
||||
}
|
||||
},
|
||||
sideGroup ? SIDE_GROUP : undefined);
|
||||
}
|
||||
}
|
||||
|
||||
getOrCreateEditorInput(instanceOrUri: ITerminalInstance | DeserializedTerminalEditorInput | URI, isFutureSplit: boolean = false): TerminalEditorInput {
|
||||
resolveResource(instanceOrUri: ITerminalInstance | URI, isFutureSplit: boolean = false): URI {
|
||||
const resource: URI = URI.isUri(instanceOrUri) ? instanceOrUri : instanceOrUri.resource;
|
||||
const inputKey = resource.path;
|
||||
const cachedEditor = this._editorInputs.get(inputKey);
|
||||
if (cachedEditor) {
|
||||
return cachedEditor;
|
||||
}
|
||||
|
||||
if ('pid' in instanceOrUri) {
|
||||
instanceOrUri = this._terminalInstanceService.createInstance({ attachPersistentProcess: instanceOrUri }, TerminalLocation.Editor);
|
||||
if (cachedEditor) {
|
||||
return cachedEditor.resource;
|
||||
}
|
||||
|
||||
// Terminal from a different window
|
||||
|
@ -185,9 +188,7 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
|
|||
if (terminalIdentifier.instanceId) {
|
||||
this._primaryOffProcessTerminalService.requestDetachInstance(terminalIdentifier.workspaceId, terminalIdentifier.instanceId).then(attachPersistentProcess => {
|
||||
const instance = this._terminalInstanceService.createInstance({ attachPersistentProcess }, TerminalLocation.Editor, resource);
|
||||
input.setTerminalInstance(instance);
|
||||
// trigger setInput on TerminalEditor setInput
|
||||
// which attaches to the element and updates the input
|
||||
input = this._instantiationService.createInstance(TerminalEditorInput, resource, instance);
|
||||
this._editorService.openEditor(input, {
|
||||
pinned: true,
|
||||
forceReload: true
|
||||
|
@ -195,6 +196,7 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
|
|||
input.group
|
||||
);
|
||||
this._registerInstance(inputKey, input, instance);
|
||||
return instanceOrUri;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -204,9 +206,16 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
|
|||
instanceOrUri.target = TerminalLocation.Editor;
|
||||
input = this._instantiationService.createInstance(TerminalEditorInput, resource, instanceOrUri);
|
||||
this._registerInstance(inputKey, input, instanceOrUri);
|
||||
return input.resource;
|
||||
} else {
|
||||
input = this._instantiationService.createInstance(TerminalEditorInput, instanceOrUri, undefined);
|
||||
this._editorInputs.set(inputKey, input);
|
||||
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}`);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
@ -234,10 +243,36 @@ export class TerminalEditorService extends Disposable implements ITerminalEditor
|
|||
}
|
||||
}
|
||||
const instance = this._terminalInstanceService.createInstance(shellLaunchConfig, TerminalLocation.Editor);
|
||||
this._editorService.openEditor(this.getOrCreateEditorInput(instance), undefined, SIDE_GROUP);
|
||||
const resource = this.resolveResource(instance);
|
||||
if (resource) {
|
||||
this._editorService.openEditor({
|
||||
resource: URI.revive(resource),
|
||||
options:
|
||||
{
|
||||
pinned: true,
|
||||
forceReload: true
|
||||
}
|
||||
},
|
||||
SIDE_GROUP);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
detachActiveEditorInstance(): ITerminalInstance {
|
||||
const activeEditor = this._editorService.activeEditor;
|
||||
if (!(activeEditor instanceof TerminalEditorInput)) {
|
||||
|
|
|
@ -198,16 +198,17 @@ export class TerminalService implements ITerminalService {
|
|||
sourceGroup.removeInstance(instance);
|
||||
}
|
||||
}
|
||||
const resolvedResource = this._terminalEditorService.resolveResource(instance || resource);
|
||||
const editor = this._terminalEditorService.getInputFromResource(resolvedResource) || { editor: URI.revive(resolvedResource) };
|
||||
return {
|
||||
editor: this._terminalEditorService.getOrCreateEditorInput(instance || resource),
|
||||
editor,
|
||||
options: {
|
||||
...options,
|
||||
pinned: true,
|
||||
forceReload: true
|
||||
}
|
||||
};
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
this._forwardInstanceHostEvents(this._terminalGroupService);
|
||||
this._forwardInstanceHostEvents(this._terminalEditorService);
|
||||
|
|
Loading…
Reference in a new issue