contentprovider.contribution.ts 2.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
'use strict';

import {ResourceEditorInput} from 'vs/workbench/common/editor/resourceEditorInput';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IModeService} from 'vs/editor/common/services/modeService';
import URI from 'vs/base/common/uri';
import {TPromise} from 'vs/base/common/winjs.base';
import {IModel} from 'vs/editor/common/editorCommon';
import JSONContributionRegistry = require('vs/platform/jsonschemas/common/jsonContributionRegistry');
import {Registry} from 'vs/platform/platform';
15 16
import {IWorkbenchContribution} from 'vs/workbench/common/contributions';
import {IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions} from 'vs/workbench/common/contributions';
17 18 19

let schemaRegistry = <JSONContributionRegistry.IJSONContributionRegistry>Registry.as(JSONContributionRegistry.Extensions.JSONContribution);

20
export class WorkbenchContentProvider implements IWorkbenchContribution {
21 22 23 24 25 26 27 28 29 30

	private modelService: IModelService;
	private modeService: IModeService;

	constructor(
		@IModelService modelService: IModelService,
		@IModeService modeService: IModeService
	) {
		this.modelService = modelService;
		this.modeService = modeService;
31 32 33 34 35 36

		this.start();
	}

	public getId(): string {
		return 'vs.contentprovider';
37 38
	}

39
	private start(): void {
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
		ResourceEditorInput.registerResourceContentProvider("vscode", {
			provideTextContent: (uri: URI): TPromise<IModel> => {
				if (uri.scheme !== 'vscode') {
					return null;
				}
				if (uri.authority === 'schemas') {
					let schemas = schemaRegistry.getSchemaContributions().schemas;
					let schema = schemas[uri.toString()];
					if (schema) {
						let modelContent = JSON.stringify(schema);
						let mode = this.modeService.getOrCreateMode('json');
						return TPromise.as(this.modelService.createModel(modelContent, mode, uri));
					}
				}
				return null;
			}
		});
	}
58 59 60
}

(<IWorkbenchContributionsRegistry>Registry.as(WorkbenchExtensions.Workbench)).registerWorkbenchContribution(WorkbenchContentProvider);