mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
jsonValidation takes an array for fileMatch
This commit is contained in:
@@ -40,8 +40,13 @@ export interface ISchemaAssociations {
|
|||||||
[pattern: string]: string[];
|
[pattern: string]: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ISchemaAssociation {
|
||||||
|
fileMatch: string[];
|
||||||
|
uri: string;
|
||||||
|
}
|
||||||
|
|
||||||
namespace SchemaAssociationNotification {
|
namespace SchemaAssociationNotification {
|
||||||
export const type: NotificationType<ISchemaAssociations, any> = new NotificationType('json/schemaAssociations');
|
export const type: NotificationType<ISchemaAssociations | ISchemaAssociation[], any> = new NotificationType('json/schemaAssociations');
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ResultLimitReachedNotification {
|
namespace ResultLimitReachedNotification {
|
||||||
@@ -264,10 +269,10 @@ export function activate(context: ExtensionContext) {
|
|||||||
|
|
||||||
toDispose.push(commands.registerCommand('_json.retryResolveSchema', handleRetryResolveSchemaCommand));
|
toDispose.push(commands.registerCommand('_json.retryResolveSchema', handleRetryResolveSchemaCommand));
|
||||||
|
|
||||||
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
|
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociations(context));
|
||||||
|
|
||||||
extensions.onDidChange(_ => {
|
extensions.onDidChange(_ => {
|
||||||
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
|
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociations(context));
|
||||||
});
|
});
|
||||||
|
|
||||||
// manually register / deregister format provider based on the `html.format.enable` setting avoiding issues with late registration. See #71652.
|
// manually register / deregister format provider based on the `html.format.enable` setting avoiding issues with late registration. See #71652.
|
||||||
@@ -324,8 +329,8 @@ export function deactivate(): Promise<any> {
|
|||||||
return telemetryReporter ? telemetryReporter.dispose() : Promise.resolve(null);
|
return telemetryReporter ? telemetryReporter.dispose() : Promise.resolve(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSchemaAssociation(_context: ExtensionContext): ISchemaAssociations {
|
function getSchemaAssociations(_context: ExtensionContext): ISchemaAssociation[] {
|
||||||
const associations: ISchemaAssociations = {};
|
const associations: ISchemaAssociation[] = [];
|
||||||
extensions.all.forEach(extension => {
|
extensions.all.forEach(extension => {
|
||||||
const packageJSON = extension.packageJSON;
|
const packageJSON = extension.packageJSON;
|
||||||
if (packageJSON && packageJSON.contributes && packageJSON.contributes.jsonValidation) {
|
if (packageJSON && packageJSON.contributes && packageJSON.contributes.jsonValidation) {
|
||||||
@@ -333,23 +338,21 @@ function getSchemaAssociation(_context: ExtensionContext): ISchemaAssociations {
|
|||||||
if (Array.isArray(jsonValidation)) {
|
if (Array.isArray(jsonValidation)) {
|
||||||
jsonValidation.forEach(jv => {
|
jsonValidation.forEach(jv => {
|
||||||
let { fileMatch, url } = jv;
|
let { fileMatch, url } = jv;
|
||||||
if (fileMatch && url) {
|
if (typeof fileMatch === 'string') {
|
||||||
if (url[0] === '.' && url[1] === '/') {
|
fileMatch = [fileMatch];
|
||||||
url = Uri.file(path.join(extension.extensionPath, url)).toString();
|
|
||||||
}
|
}
|
||||||
if (fileMatch[0] === '%') {
|
if (Array.isArray(fileMatch) && url) {
|
||||||
fileMatch = fileMatch.replace(/%APP_SETTINGS_HOME%/, '/User');
|
fileMatch = fileMatch.map(fm => {
|
||||||
fileMatch = fileMatch.replace(/%MACHINE_SETTINGS_HOME%/, '/Machine');
|
if (fm[0] === '%') {
|
||||||
fileMatch = fileMatch.replace(/%APP_WORKSPACES_HOME%/, '/Workspaces');
|
fm = fm.replace(/%APP_SETTINGS_HOME%/, '/User');
|
||||||
} else if (fileMatch.charAt(0) !== '/' && !fileMatch.match(/\w+:\/\//)) {
|
fm = fm.replace(/%MACHINE_SETTINGS_HOME%/, '/Machine');
|
||||||
fileMatch = '/' + fileMatch;
|
fm = fm.replace(/%APP_WORKSPACES_HOME%/, '/Workspaces');
|
||||||
|
} else if (!fm.match(/^(\w+:\/\/|\/|!)/)) {
|
||||||
|
fm = '/' + fm;
|
||||||
}
|
}
|
||||||
let association = associations[fileMatch];
|
return fm;
|
||||||
if (!association) {
|
});
|
||||||
association = [];
|
associations.push({ fileMatch, uri: url });
|
||||||
associations[fileMatch] = association;
|
|
||||||
}
|
|
||||||
association.push(url);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,13 @@ interface ISchemaAssociations {
|
|||||||
[pattern: string]: string[];
|
[pattern: string]: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ISchemaAssociation {
|
||||||
|
fileMatch: string[];
|
||||||
|
uri: string;
|
||||||
|
}
|
||||||
|
|
||||||
namespace SchemaAssociationNotification {
|
namespace SchemaAssociationNotification {
|
||||||
export const type: NotificationType<ISchemaAssociations, any> = new NotificationType('json/schemaAssociations');
|
export const type: NotificationType<ISchemaAssociations | ISchemaAssociation[], any> = new NotificationType('json/schemaAssociations');
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace VSCodeContentRequest {
|
namespace VSCodeContentRequest {
|
||||||
@@ -230,7 +235,7 @@ namespace LimitExceededWarnings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let jsonConfigurationSettings: JSONSchemaSettings[] | undefined = undefined;
|
let jsonConfigurationSettings: JSONSchemaSettings[] | undefined = undefined;
|
||||||
let schemaAssociations: ISchemaAssociations | undefined = undefined;
|
let schemaAssociations: ISchemaAssociations | ISchemaAssociation[] | undefined = undefined;
|
||||||
let formatterRegistration: Thenable<Disposable> | null = null;
|
let formatterRegistration: Thenable<Disposable> | null = null;
|
||||||
|
|
||||||
// The settings have changed. Is send on server activation as well.
|
// The settings have changed. Is send on server activation as well.
|
||||||
@@ -291,6 +296,9 @@ function updateConfiguration() {
|
|||||||
schemas: new Array<SchemaConfiguration>()
|
schemas: new Array<SchemaConfiguration>()
|
||||||
};
|
};
|
||||||
if (schemaAssociations) {
|
if (schemaAssociations) {
|
||||||
|
if (Array.isArray(schemaAssociations)) {
|
||||||
|
Array.prototype.push.apply(languageSettings.schemas, schemaAssociations);
|
||||||
|
} else {
|
||||||
for (const pattern in schemaAssociations) {
|
for (const pattern in schemaAssociations) {
|
||||||
const association = schemaAssociations[pattern];
|
const association = schemaAssociations[pattern];
|
||||||
if (Array.isArray(association)) {
|
if (Array.isArray(association)) {
|
||||||
@@ -300,6 +308,7 @@ function updateConfiguration() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (jsonConfigurationSettings) {
|
if (jsonConfigurationSettings) {
|
||||||
jsonConfigurationSettings.forEach((schema, index) => {
|
jsonConfigurationSettings.forEach((schema, index) => {
|
||||||
let uri = schema.url;
|
let uri = schema.url;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export interface IGrammar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IJSONValidation {
|
export interface IJSONValidation {
|
||||||
fileMatch: string;
|
fileMatch: string | string[];
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,10 @@ import * as nls from 'vs/nls';
|
|||||||
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||||
import * as strings from 'vs/base/common/strings';
|
import * as strings from 'vs/base/common/strings';
|
||||||
import * as resources from 'vs/base/common/resources';
|
import * as resources from 'vs/base/common/resources';
|
||||||
|
import { isString } from 'vs/base/common/types';
|
||||||
|
|
||||||
interface IJSONValidationExtensionPoint {
|
interface IJSONValidationExtensionPoint {
|
||||||
fileMatch: string;
|
fileMatch: string | string[];
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,8 +26,11 @@ const configurationExtPoint = ExtensionsRegistry.registerExtensionPoint<IJSONVal
|
|||||||
defaultSnippets: [{ body: { fileMatch: '${1:file.json}', url: '${2:url}' } }],
|
defaultSnippets: [{ body: { fileMatch: '${1:file.json}', url: '${2:url}' } }],
|
||||||
properties: {
|
properties: {
|
||||||
fileMatch: {
|
fileMatch: {
|
||||||
type: 'string',
|
type: ['string', 'array'],
|
||||||
description: nls.localize('contributes.jsonValidation.fileMatch', 'The file pattern to match, for example "package.json" or "*.launch".'),
|
description: nls.localize('contributes.jsonValidation.fileMatch', 'The file pattern (or an array of patterns) to match, for example "package.json" or "*.launch". Exclusion patterns start with \'!\''),
|
||||||
|
items: {
|
||||||
|
type: ['string']
|
||||||
|
}
|
||||||
},
|
},
|
||||||
url: {
|
url: {
|
||||||
description: nls.localize('contributes.jsonValidation.url', 'A schema URL (\'http:\', \'https:\') or relative path to the extension folder (\'./\').'),
|
description: nls.localize('contributes.jsonValidation.url', 'A schema URL (\'http:\', \'https:\') or relative path to the extension folder (\'./\').'),
|
||||||
@@ -51,12 +55,12 @@ export class JSONValidationExtensionPoint {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
extensionValue.forEach(extension => {
|
extensionValue.forEach(extension => {
|
||||||
if (typeof extension.fileMatch !== 'string') {
|
if (!isString(extension.fileMatch) && !(Array.isArray(extension.fileMatch) && extension.fileMatch.every(isString))) {
|
||||||
collector.error(nls.localize('invalid.fileMatch', "'configuration.jsonValidation.fileMatch' must be defined"));
|
collector.error(nls.localize('invalid.fileMatch', "'configuration.jsonValidation.fileMatch' must be defined as a string or an array of strings."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let uri = extension.url;
|
let uri = extension.url;
|
||||||
if (typeof extension.url !== 'string') {
|
if (!isString(uri)) {
|
||||||
collector.error(nls.localize('invalid.url', "'configuration.jsonValidation.url' must be a URL or relative path"));
|
collector.error(nls.localize('invalid.url', "'configuration.jsonValidation.url' must be a URL or relative path"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1208,7 +1208,7 @@ export class ExtensionEditor extends BaseEditor {
|
|||||||
$('th', undefined, localize('schema', "Schema"))
|
$('th', undefined, localize('schema', "Schema"))
|
||||||
),
|
),
|
||||||
...contrib.map(v => $('tr', undefined,
|
...contrib.map(v => $('tr', undefined,
|
||||||
$('td', undefined, $('code', undefined, v.fileMatch)),
|
$('td', undefined, $('code', undefined, Array.isArray(v.fileMatch) ? v.fileMatch.join(', ') : v.fileMatch)),
|
||||||
$('td', undefined, v.url)
|
$('td', undefined, v.url)
|
||||||
))));
|
))));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user