diff --git a/src/vs/platform/jsonschemas/common/jsonContributionRegistry.ts b/src/vs/platform/jsonschemas/common/jsonContributionRegistry.ts index 5d4f91c0dff10502bd2cbd821a50d3cc87f467ec..b9c921d4505c7788bd06a46eb2bd056c68660eac 100644 --- a/src/vs/platform/jsonschemas/common/jsonContributionRegistry.ts +++ b/src/vs/platform/jsonschemas/common/jsonContributionRegistry.ts @@ -5,9 +5,8 @@ 'use strict'; import { IJSONSchema } from 'vs/base/common/jsonSchema'; -import platform = require('vs/platform/registry/common/platform'); -import { EventEmitter } from 'vs/base/common/eventEmitter'; -import { IDisposable } from 'vs/base/common/lifecycle'; +import * as platform from 'vs/platform/registry/common/platform'; +import Event, { Emitter } from 'vs/base/common/event'; export const Extensions = { JSONContribution: 'base.contributions.json' @@ -19,6 +18,8 @@ export interface ISchemaContributions { export interface IJSONContributionRegistry { + readonly onDidChangeSchema: Event; + /** * Register a schema to the registry. */ @@ -28,12 +29,6 @@ export interface IJSONContributionRegistry { * Get all schemas */ getSchemaContributions(): ISchemaContributions; - - /** - * Adds a change listener - */ - addRegistryChangedListener(callback: (e: IJSONContributionRegistryEvent) => void): IDisposable; - } export interface IJSONContributionRegistryEvent { @@ -50,21 +45,19 @@ function normalizeId(id: string) { class JSONContributionRegistry implements IJSONContributionRegistry { + private schemasById: { [id: string]: IJSONSchema }; - private eventEmitter: EventEmitter; + + private _onDidChangeSchema: Emitter = new Emitter(); + readonly onDidChangeSchema: Event = this._onDidChangeSchema.event; constructor() { this.schemasById = {}; - this.eventEmitter = new EventEmitter(); - } - - public addRegistryChangedListener(callback: (e: IJSONContributionRegistryEvent) => void): IDisposable { - return this.eventEmitter.addListener('registryChanged', callback); } public registerSchema(uri: string, unresolvedSchemaContent: IJSONSchema): void { this.schemasById[normalizeId(uri)] = unresolvedSchemaContent; - this.eventEmitter.emit('registryChanged', {}); + this._onDidChangeSchema.fire(uri); } public getSchemaContributions(): ISchemaContributions { diff --git a/src/vs/workbench/parts/preferences/common/preferencesContentProvider.ts b/src/vs/workbench/parts/preferences/common/preferencesContentProvider.ts index 4b58705c22b9898642b78aa1ca31207a0c458472..33141c96052743c9e6106f9ac3f4bb545c1a62d0 100644 --- a/src/vs/workbench/parts/preferences/common/preferencesContentProvider.ts +++ b/src/vs/workbench/parts/preferences/common/preferencesContentProvider.ts @@ -14,6 +14,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { ITextModelService } from 'vs/editor/common/services/resolverService'; import { IPreferencesService } from 'vs/workbench/parts/preferences/common/preferences'; +import { dispose } from 'vs/base/common/lifecycle'; const schemaRegistry = Registry.as(JSONContributionRegistry.Extensions.JSONContribution); @@ -33,18 +34,16 @@ export class PreferencesContentProvider implements IWorkbenchContribution { } private start(): void { + this.textModelResolverService.registerTextModelContentProvider('vscode', { provideTextContent: (uri: URI): TPromise => { 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)); + const schemaModel = this.getSchemaModel(uri); + if (schemaModel) { + return TPromise.as(schemaModel); } } return this.preferencesService.resolveContent(uri) @@ -59,4 +58,25 @@ export class PreferencesContentProvider implements IWorkbenchContribution { } }); } + + private getSchemaModel(uri: URI): IModel { + let schema = schemaRegistry.getSchemaContributions().schemas[uri.toString()]; + if (schema) { + const modelContent = JSON.stringify(schema); + const mode = this.modeService.getOrCreateMode('json'); + const model = this.modelService.createModel(modelContent, mode, uri); + + let disposables = []; + disposables.push(schemaRegistry.onDidChangeSchema(schemaUri => { + if (schemaUri === uri.toString()) { + schema = schemaRegistry.getSchemaContributions().schemas[uri.toString()]; + model.setValue(JSON.stringify(schema)); + } + })); + disposables.push(model.onWillDispose(() => dispose(disposables))); + + return model; + } + return null; + } }