Pass process manager through to contributions

This commit is contained in:
Daniel Imms 2023-03-01 16:31:11 -08:00
parent b2be676a6b
commit 22d33c40b4
No known key found for this signature in database
GPG key ID: E5CF412B63651C69
4 changed files with 20 additions and 7 deletions

View file

@ -31,7 +31,9 @@ export const ITerminalGroupService = createDecorator<ITerminalGroupService>('ter
export const ITerminalInstanceService = createDecorator<ITerminalInstanceService>('terminalInstanceService');
/**
* A terminal contribution that gets created whenever a terminal is created.
* A terminal contribution that gets created whenever a terminal is created. A contribution has
* access to the process manager through the constructor and provides a method for when xterm.js has
* been initialized.
*/
export interface ITerminalContribution extends IDisposable {
xtermReady?(xterm: IXtermTerminal): void;

View file

@ -6,15 +6,16 @@
import { BrandedService, IConstructorSignature } from 'vs/platform/instantiation/common/instantiation';
import { Registry } from 'vs/platform/registry/common/platform';
import { ITerminalContribution, ITerminalInstance } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ITerminalProcessManager } from 'vs/workbench/contrib/terminal/common/terminal';
export type TerminalContributionCtor = IConstructorSignature<ITerminalContribution, [ITerminalInstance]>;
export type TerminalContributionCtor = IConstructorSignature<ITerminalContribution, [ITerminalInstance, ITerminalProcessManager]>;
export interface ITerminalContributionDescription {
readonly id: string;
readonly ctor: TerminalContributionCtor;
}
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: ITerminalInstance, ...services: Services): ITerminalContribution }): void {
export function registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(instance: ITerminalInstance, processManager: ITerminalProcessManager, ...services: Services): ITerminalContribution }): void {
TerminalContributionRegistry.INSTANCE.registerTerminalContribution(id, ctor);
}
@ -37,7 +38,7 @@ class TerminalContributionRegistry {
constructor() {
}
public registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: ITerminalInstance, ...services: Services): ITerminalContribution }): void {
public registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(instance: ITerminalInstance, processManager: ITerminalProcessManager, ...services: Services): ITerminalContribution }): void {
this._terminalContributions.push({ id, ctor: ctor as TerminalContributionCtor });
}

View file

@ -586,7 +586,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
const contributionDescs = TerminalExtensionsRegistry.getTerminalContributions();
for (const desc of contributionDescs) {
try {
this._contributions.push(this._scopedInstantiationService.createInstance(desc.ctor, this));
this._contributions.push(this._scopedInstantiationService.createInstance(desc.ctor, this, this._processManager));
} catch (err) {
onUnexpectedError(err);
}

View file

@ -11,26 +11,36 @@ import { localize } from 'vs/nls';
import { registerAction2, Action2 } from 'vs/platform/actions/common/actions';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ITerminalContribution, ITerminalInstance, ITerminalService, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
import { ITerminalProcessManager, TerminalCommandId } from 'vs/workbench/contrib/terminal/common/terminal';
import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/terminalContextKey';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { terminalStrings } from 'vs/workbench/contrib/terminal/common/terminalStrings';
import { DisposableStore, toDisposable } from 'vs/base/common/lifecycle';
import { registerTerminalContribution } from 'vs/workbench/contrib/terminal/browser/terminalCommon';
import { TerminalLinkManager } from 'vs/workbench/contrib/terminal/contrib/links/browser/terminalLinkManager';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
registerSingleton(ITerminalLinkResolverService, TerminalLinkResolverService, InstantiationType.Delayed);
class TerminalLinkContribution extends DisposableStore implements ITerminalContribution {
constructor(instance: ITerminalInstance) {
constructor(
private readonly _instance: ITerminalInstance,
private readonly _processManager: ITerminalProcessManager,
@IInstantiationService private readonly _instantiationService: IInstantiationService
) {
super();
console.log('ctor');
this.add(toDisposable(() => console.log('dispose')));
}
xtermReady(xterm: IXtermTerminal): void {
console.log('xtermReady');
// TODO: Fix cast
const linkManager = this._instantiationService.createInstance(TerminalLinkManager, (xterm as any).raw, this._processManager, this._instance.capabilities);
console.log('linkManager', linkManager);
// TODO: Init terminal link manager here
}
}
// TODO: Use ID to prevent duplicate contributions?
registerTerminalContribution('link', TerminalLinkContribution);
const category = terminalStrings.actionCategory;