Setup a terminal contributions system

This commit is contained in:
Daniel Imms 2023-03-01 16:22:21 -08:00
parent 862cb75a68
commit 62df9971f5
No known key found for this signature in database
GPG key ID: E5CF412B63651C69
5 changed files with 93 additions and 4 deletions

View file

@ -289,4 +289,4 @@ registerColors();
import '../contrib/accessibility/browser/terminal.accessibility.contribution';
import '../contrib/find/browser/terminal.find.contribution';
import '../contrib/link/browser/terminal.link.contribution';
import '../contrib/links/browser/terminal.links.contribution';

View file

@ -30,6 +30,13 @@ export const ITerminalEditorService = createDecorator<ITerminalEditorService>('t
export const ITerminalGroupService = createDecorator<ITerminalGroupService>('terminalGroupService');
export const ITerminalInstanceService = createDecorator<ITerminalInstanceService>('terminalInstanceService');
/**
* A terminal contribution that gets created whenever a terminal is created.
*/
export interface ITerminalContribution extends IDisposable {
xtermReady?(xterm: IXtermTerminal): void;
}
/**
* A service used to create instances or fetch backends, this services allows services that
* ITerminalService depends on to also create instances.

View file

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
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';
export type TerminalContributionCtor = IConstructorSignature<ITerminalContribution, [ITerminalInstance]>;
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 {
TerminalContributionRegistry.INSTANCE.registerTerminalContribution(id, ctor);
}
export namespace TerminalExtensionsRegistry {
export function getTerminalContributions(): ITerminalContributionDescription[] {
return TerminalContributionRegistry.INSTANCE.getTerminalContributions();
}
}
// Editor extension points
const Extensions = {
TerminalContributions: 'terminal.contributions'
};
class TerminalContributionRegistry {
public static readonly INSTANCE = new TerminalContributionRegistry();
private readonly _terminalContributions: ITerminalContributionDescription[] = [];
constructor() {
}
public registerTerminalContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: ITerminalInstance, ...services: Services): ITerminalContribution }): void {
this._terminalContributions.push({ id, ctor: ctor as TerminalContributionCtor });
}
public getTerminalContributions(): ITerminalContributionDescription[] {
return this._terminalContributions.slice(0);
}
}
Registry.add(Extensions.TerminalContributions, TerminalContributionRegistry.INSTANCE);

View file

@ -13,7 +13,7 @@ import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableEle
import { AutoOpenBarrier, Promises, timeout } from 'vs/base/common/async';
import { Codicon, getAllCodicons } from 'vs/base/common/codicons';
import { debounce } from 'vs/base/common/decorators';
import { ErrorNoTelemetry } from 'vs/base/common/errors';
import { ErrorNoTelemetry, onUnexpectedError } from 'vs/base/common/errors';
import { Emitter, Event } from 'vs/base/common/event';
import { KeyCode } from 'vs/base/common/keyCodes';
import { ISeparator, template } from 'vs/base/common/labels';
@ -55,7 +55,7 @@ import { IViewDescriptorService, IViewsService, ViewContainerLocation } from 'vs
import { TaskSettingId } from 'vs/workbench/contrib/tasks/common/tasks';
import { IDetectedLinks, TerminalLinkManager } from 'vs/workbench/contrib/terminal/contrib/links/browser/terminalLinkManager';
import { TerminalLinkQuickpick } from 'vs/workbench/contrib/terminal/contrib/links/browser/terminalLinkQuickpick';
import { IRequestAddInstanceToGroupEvent, ITerminalChildElement, ITerminalExternalLinkProvider, ITerminalInstance, TerminalDataTransfers } from 'vs/workbench/contrib/terminal/browser/terminal';
import { IRequestAddInstanceToGroupEvent, ITerminalChildElement, ITerminalContribution, ITerminalExternalLinkProvider, ITerminalInstance, TerminalDataTransfers } from 'vs/workbench/contrib/terminal/browser/terminal';
import { TerminalLaunchHelpAction } from 'vs/workbench/contrib/terminal/browser/terminalActions';
import { freePort, gitCreatePr, gitPushSetUpstream, gitSimilar, gitTwoDashes, pwshGeneralError as pwshGeneralError, pwshUnixCommandNotFoundError } from 'vs/workbench/contrib/terminal/browser/terminalQuickFixBuiltinActions';
import { TerminalConfigHelper } from 'vs/workbench/contrib/terminal/browser/terminalConfigHelper';
@ -92,6 +92,7 @@ import { ISimpleSelectedSuggestion } from 'vs/workbench/services/suggest/browser
import { TERMINAL_BACKGROUND_COLOR } from 'vs/workbench/contrib/terminal/common/terminalColorRegistry';
import { editorBackground } from 'vs/platform/theme/common/colorRegistry';
import { PANEL_BACKGROUND, SIDE_BAR_BACKGROUND } from 'vs/workbench/common/theme';
import { TerminalExtensionsRegistry } from 'vs/workbench/contrib/terminal/browser/terminalCommon';
const enum Constants {
/**
@ -148,6 +149,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private readonly _scopedInstantiationService: IInstantiationService;
readonly _processManager: ITerminalProcessManager;
private _contributions: ITerminalContribution[];
private readonly _resource: URI;
// Enables disposal of the xterm onKey
// event when the CwdDetection capability
@ -194,6 +196,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
private _icon: TerminalIcon | undefined;
private _messageTitleDisposable: IDisposable | undefined;
private _widgetManager: TerminalWidgetManager = new TerminalWidgetManager();
// TODO: Move this out of terminal instance
private _linkManager: TerminalLinkManager | undefined;
private _environmentInfo: { widget: EnvironmentVariableInfoWidget; disposable: IDisposable } | undefined;
private _dndObserver: IDisposable | undefined;
@ -577,6 +580,22 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
window.clearTimeout(initialDataEventsTimeout);
}
}));
// Initialize contributions
this._contributions = [];
const contributionDescs = TerminalExtensionsRegistry.getTerminalContributions();
for (const desc of contributionDescs) {
try {
this._contributions.push(this._scopedInstantiationService.createInstance(desc.ctor, this));
} catch (err) {
onUnexpectedError(err);
}
this._xtermReadyPromise.then(xterm => {
for (const contribution of this._contributions) {
contribution.xtermReady?.(xterm);
}
});
}
}
private _getIcon(): TerminalIcon | undefined {

View file

@ -10,14 +10,28 @@ import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
import { localize } from 'vs/nls';
import { registerAction2, Action2 } from 'vs/platform/actions/common/actions';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { ITerminalService } from 'vs/workbench/contrib/terminal/browser/terminal';
import { ITerminalContribution, ITerminalInstance, ITerminalService, IXtermTerminal } from 'vs/workbench/contrib/terminal/browser/terminal';
import { 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 } from 'vs/base/common/lifecycle';
import { registerTerminalContribution } from 'vs/workbench/contrib/terminal/browser/terminalCommon';
registerSingleton(ITerminalLinkResolverService, TerminalLinkResolverService, InstantiationType.Delayed);
class TerminalLinkContribution extends DisposableStore implements ITerminalContribution {
constructor(instance: ITerminalInstance) {
super();
console.log('ctor');
}
xtermReady(xterm: IXtermTerminal): void {
console.log('xtermReady');
// TODO: Init terminal link manager here
}
}
registerTerminalContribution('link', TerminalLinkContribution);
const category = terminalStrings.actionCategory;
// TODO: Move methods out of ITerminalInstance