Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/notebook/browser/notebookEditorExtensions.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { BrandedService } from '../../../../platform/instantiation/common/instantiation.js';
7
import { INotebookEditor, INotebookEditorContribution, INotebookEditorContributionCtor, INotebookEditorContributionDescription } from './notebookBrowser.js';
8
9
10
class EditorContributionRegistry {
11
public static readonly INSTANCE = new EditorContributionRegistry();
12
private readonly editorContributions: INotebookEditorContributionDescription[];
13
14
constructor() {
15
this.editorContributions = [];
16
}
17
18
public registerEditorContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: INotebookEditor, ...services: Services): INotebookEditorContribution }): void {
19
this.editorContributions.push({ id, ctor: ctor as INotebookEditorContributionCtor });
20
}
21
22
public getEditorContributions(): INotebookEditorContributionDescription[] {
23
return this.editorContributions.slice(0);
24
}
25
}
26
27
export function registerNotebookContribution<Services extends BrandedService[]>(id: string, ctor: { new(editor: INotebookEditor, ...services: Services): INotebookEditorContribution }): void {
28
EditorContributionRegistry.INSTANCE.registerEditorContribution(id, ctor);
29
}
30
31
export namespace NotebookEditorExtensionsRegistry {
32
33
export function getEditorContributions(): INotebookEditorContributionDescription[] {
34
return EditorContributionRegistry.INSTANCE.getEditorContributions();
35
}
36
37
export function getSomeEditorContributions(ids: string[]): INotebookEditorContributionDescription[] {
38
return EditorContributionRegistry.INSTANCE.getEditorContributions().filter(c => ids.indexOf(c.id) >= 0);
39
}
40
}
41
42