extensionPoint.ts 4.3 KB
Newer Older
R
rebornix 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IJSONSchema } from 'vs/base/common/jsonSchema';
import * as nls from 'vs/nls';
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { NotebookSelector } from 'vs/workbench/contrib/notebook/common/notebookProvider';

namespace NotebookEditorContribution {
	export const viewType = 'viewType';
	export const displayName = 'displayName';
	export const selector = 'selector';
}

interface INotebookEditorContribution {
	readonly [NotebookEditorContribution.viewType]: string;
	readonly [NotebookEditorContribution.displayName]: string;
	readonly [NotebookEditorContribution.selector]?: readonly NotebookSelector[];
}

R
rebornix 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
namespace NotebookRendererContribution {
	export const viewType = 'viewType';
	export const displayName = 'displayName';
	export const mimeTypes = 'mimeTypes';
}

interface INotebookRendererContribution {
	readonly [NotebookRendererContribution.viewType]: string;
	readonly [NotebookRendererContribution.displayName]: string;
	readonly [NotebookRendererContribution.mimeTypes]?: readonly string[];
}



const notebookProviderContribution: IJSONSchema = {
	description: nls.localize('contributes.notebook.provider', 'Contributes notebook document provider.'),
R
rebornix 已提交
39 40 41 42 43 44 45 46 47 48 49 50
	type: 'array',
	defaultSnippets: [{ body: [{ viewType: '', displayName: '' }] }],
	items: {
		type: 'object',
		required: [
			NotebookEditorContribution.viewType,
			NotebookEditorContribution.displayName,
			NotebookEditorContribution.selector,
		],
		properties: {
			[NotebookEditorContribution.viewType]: {
				type: 'string',
R
rebornix 已提交
51
				description: nls.localize('contributes.notebook.provider.viewType', 'Unique identifier of the notebook.'),
R
rebornix 已提交
52 53 54
			},
			[NotebookEditorContribution.displayName]: {
				type: 'string',
R
rebornix 已提交
55
				description: nls.localize('contributes.notebook.provider.displayName', 'Human readable name of the notebook.'),
R
rebornix 已提交
56 57 58
			},
			[NotebookEditorContribution.selector]: {
				type: 'array',
R
rebornix 已提交
59
				description: nls.localize('contributes.notebook.provider.selector', 'Set of globs that the notebook is for.'),
R
rebornix 已提交
60 61 62 63 64
				items: {
					type: 'object',
					properties: {
						filenamePattern: {
							type: 'string',
R
rebornix 已提交
65
							description: nls.localize('contributes.notebook.provider.selector.filenamePattern', 'Glob that the notebook is enabled for.'),
R
rebornix 已提交
66
						},
67 68
						excludeFileNamePattern: {
							type: 'string',
R
rebornix 已提交
69
							description: nls.localize('contributes.notebook.selector.provider.excludeFileNamePattern', 'Glob that the notebook is disabled for.')
70
						}
R
rebornix 已提交
71 72 73 74 75 76 77
					}
				}
			}
		}
	}
};

R
rebornix 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
const notebookRendererContribution: IJSONSchema = {
	description: nls.localize('contributes.notebook.renderer', 'Contributes notebook output renderer provider.'),
	type: 'array',
	defaultSnippets: [{ body: [{ viewType: '', displayName: '', mimeTypes: [''] }] }],
	items: {
		type: 'object',
		required: [
			NotebookRendererContribution.viewType,
			NotebookRendererContribution.displayName,
			NotebookRendererContribution.mimeTypes,
		],
		properties: {
			[NotebookRendererContribution.viewType]: {
				type: 'string',
				description: nls.localize('contributes.notebook.renderer.viewType', 'Unique identifier of the notebook output renderer.'),
			},
			[NotebookRendererContribution.displayName]: {
				type: 'string',
				description: nls.localize('contributes.notebook.renderer.displayName', 'Human readable name of the notebook output renderer.'),
			},
			[NotebookRendererContribution.mimeTypes]: {
				type: 'array',
				description: nls.localize('contributes.notebook.selector', 'Set of globs that the notebook is for.'),
				items: {
					type: 'string'
				}
			}
		}
	}
};

export const notebookProviderExtensionPoint = ExtensionsRegistry.registerExtensionPoint<INotebookEditorContribution[]>(
	{
		extensionPoint: 'notebookProvider',
		jsonSchema: notebookProviderContribution
	});

export const notebookRendererExtensionPoint = ExtensionsRegistry.registerExtensionPoint<INotebookRendererContribution[]>(
	{
		extensionPoint: 'notebookOutputRenderer',
		jsonSchema: notebookRendererContribution
	});