mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'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';
|
||||
|
||||
export const Extensions = {
|
||||
JSONContribution: 'base.contributions.json'
|
||||
};
|
||||
|
||||
export interface ISchemaContributions {
|
||||
schemas?: { [id: string]: IJSONSchema };
|
||||
}
|
||||
|
||||
export interface IJSONContributionRegistry {
|
||||
|
||||
/**
|
||||
* Register a schema to the registry.
|
||||
*/
|
||||
registerSchema(uri: string, unresolvedSchemaContent: IJSONSchema): void;
|
||||
|
||||
/**
|
||||
* Get all schemas
|
||||
*/
|
||||
getSchemaContributions(): ISchemaContributions;
|
||||
|
||||
/**
|
||||
* Adds a change listener
|
||||
*/
|
||||
addRegistryChangedListener(callback: (e: IJSONContributionRegistryEvent) => void): IDisposable;
|
||||
|
||||
}
|
||||
|
||||
export interface IJSONContributionRegistryEvent {
|
||||
|
||||
}
|
||||
|
||||
function normalizeId(id: string) {
|
||||
if (id.length > 0 && id.charAt(id.length - 1) === '#') {
|
||||
return id.substring(0, id.length - 1);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class JSONContributionRegistry implements IJSONContributionRegistry {
|
||||
private schemasById: { [id: string]: IJSONSchema };
|
||||
private eventEmitter: EventEmitter;
|
||||
|
||||
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', {});
|
||||
}
|
||||
|
||||
public getSchemaContributions(): ISchemaContributions {
|
||||
return {
|
||||
schemas: this.schemasById,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const jsonContributionRegistry = new JSONContributionRegistry();
|
||||
platform.Registry.add(Extensions.JSONContribution, jsonContributionRegistry);
|
||||
@@ -0,0 +1,76 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import nls = require('vs/nls');
|
||||
import { ExtensionsRegistry } from 'vs/platform/extensions/common/extensionsRegistry';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import strings = require('vs/base/common/strings');
|
||||
import paths = require('vs/base/common/paths');
|
||||
|
||||
interface IJSONValidationExtensionPoint {
|
||||
fileMatch: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
let configurationExtPoint = ExtensionsRegistry.registerExtensionPoint<IJSONValidationExtensionPoint[]>('jsonValidation', [], {
|
||||
description: nls.localize('contributes.jsonValidation', 'Contributes json schema configuration.'),
|
||||
type: 'array',
|
||||
defaultSnippets: [{ body: [{ fileMatch: '${1:file.json}', url: '${2:url}' }] }],
|
||||
items: {
|
||||
type: 'object',
|
||||
defaultSnippets: [{ body: { fileMatch: '${1:file.json}', url: '${2:url}' } }],
|
||||
properties: {
|
||||
fileMatch: {
|
||||
type: 'string',
|
||||
description: nls.localize('contributes.jsonValidation.fileMatch', 'The file pattern to match, for example "package.json" or "*.launch".'),
|
||||
},
|
||||
url: {
|
||||
description: nls.localize('contributes.jsonValidation.url', 'A schema URL (\'http:\', \'https:\') or relative path to the extension folder (\'./\').'),
|
||||
type: 'string'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export class JSONValidationExtensionPoint {
|
||||
|
||||
constructor() {
|
||||
configurationExtPoint.setHandler((extensions) => {
|
||||
for (var i = 0; i < extensions.length; i++) {
|
||||
var extensionValue = <IJSONValidationExtensionPoint[]>extensions[i].value;
|
||||
var collector = extensions[i].collector;
|
||||
var extensionPath = extensions[i].description.extensionFolderPath;
|
||||
|
||||
if (!extensionValue || !Array.isArray(extensionValue)) {
|
||||
collector.error(nls.localize('invalid.jsonValidation', "'configuration.jsonValidation' must be a array"));
|
||||
return;
|
||||
}
|
||||
extensionValue.forEach(extension => {
|
||||
if (typeof extension.fileMatch !== 'string') {
|
||||
collector.error(nls.localize('invalid.fileMatch', "'configuration.jsonValidation.fileMatch' must be defined"));
|
||||
return;
|
||||
}
|
||||
let uri = extension.url;
|
||||
if (typeof extension.url !== 'string') {
|
||||
collector.error(nls.localize('invalid.url', "'configuration.jsonValidation.url' must be a URL or relative path"));
|
||||
return;
|
||||
}
|
||||
if (strings.startsWith(uri, './')) {
|
||||
try {
|
||||
uri = URI.file(paths.normalize(paths.join(extensionPath, uri))).toString();
|
||||
} catch (e) {
|
||||
collector.error(nls.localize('invalid.url.fileschema', "'configuration.jsonValidation.url' is an invalid relative URL: {0}", e.message));
|
||||
}
|
||||
} else if (!strings.startsWith(uri, 'https:/') && strings.startsWith(uri, 'https:/')) {
|
||||
collector.error(nls.localize('invalid.url.schema', "'configuration.jsonValidation.url' must start with 'http:', 'https:' or './' to reference schemas located in the extension"));
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user