Path: blob/main/src/vs/workbench/contrib/notebook/browser/notebookEditorExtensions.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { BrandedService } from '../../../../platform/instantiation/common/instantiation.js';6import { INotebookEditor, INotebookEditorContribution, INotebookEditorContributionCtor, INotebookEditorContributionDescription } from './notebookBrowser.js';789class EditorContributionRegistry {10public static readonly INSTANCE = new EditorContributionRegistry();11private readonly editorContributions: INotebookEditorContributionDescription[];1213constructor() {14this.editorContributions = [];15}1617public registerEditorContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: INotebookEditor, ...services: Services): INotebookEditorContribution }): void {18this.editorContributions.push({ id, ctor: ctor as INotebookEditorContributionCtor });19}2021public getEditorContributions(): INotebookEditorContributionDescription[] {22return this.editorContributions.slice(0);23}24}2526export function registerNotebookContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: INotebookEditor, ...services: Services): INotebookEditorContribution }): void {27EditorContributionRegistry.INSTANCE.registerEditorContribution(id, ctor);28}2930export namespace NotebookEditorExtensionsRegistry {3132export function getEditorContributions(): INotebookEditorContributionDescription[] {33return EditorContributionRegistry.INSTANCE.getEditorContributions();34}3536export function getSomeEditorContributions(ids: string[]): INotebookEditorContributionDescription[] {37return EditorContributionRegistry.INSTANCE.getEditorContributions().filter(c => ids.indexOf(c.id) >= 0);38}39}404142