mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
jsonValidation takes an array for fileMatch
This commit is contained in:
parent
fecb083391
commit
18f3bee3e9
|
@ -40,8 +40,13 @@ export interface ISchemaAssociations {
|
|||
[pattern: string]: string[];
|
||||
}
|
||||
|
||||
export interface ISchemaAssociation {
|
||||
fileMatch: string[];
|
||||
uri: string;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -264,10 +269,10 @@ export function activate(context: ExtensionContext) {
|
|||
|
||||
toDispose.push(commands.registerCommand('_json.retryResolveSchema', handleRetryResolveSchemaCommand));
|
||||
|
||||
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociation(context));
|
||||
client.sendNotification(SchemaAssociationNotification.type, getSchemaAssociations(context));
|
||||
|
||||
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.
|
||||
|
@ -324,8 +329,8 @@ export function deactivate(): Promise<any> {
|
|||
return telemetryReporter ? telemetryReporter.dispose() : Promise.resolve(null);
|
||||
}
|
||||
|
||||
function getSchemaAssociation(_context: ExtensionContext): ISchemaAssociations {
|
||||
const associations: ISchemaAssociations = {};
|
||||
function getSchemaAssociations(_context: ExtensionContext): ISchemaAssociation[] {
|
||||
const associations: ISchemaAssociation[] = [];
|
||||
extensions.all.forEach(extension => {
|
||||
const packageJSON = extension.packageJSON;
|
||||
if (packageJSON && packageJSON.contributes && packageJSON.contributes.jsonValidation) {
|
||||
|
@ -333,23 +338,21 @@ function getSchemaAssociation(_context: ExtensionContext): ISchemaAssociations {
|
|||
if (Array.isArray(jsonValidation)) {
|
||||
jsonValidation.forEach(jv => {
|
||||
let { fileMatch, url } = jv;
|
||||
if (fileMatch && url) {
|
||||
if (url[0] === '.' && url[1] === '/') {
|
||||
url = Uri.file(path.join(extension.extensionPath, url)).toString();
|
||||
}
|
||||
if (fileMatch[0] === '%') {
|
||||
fileMatch = fileMatch.replace(/%APP_SETTINGS_HOME%/, '/User');
|
||||
fileMatch = fileMatch.replace(/%MACHINE_SETTINGS_HOME%/, '/Machine');
|
||||
fileMatch = fileMatch.replace(/%APP_WORKSPACES_HOME%/, '/Workspaces');
|
||||
} else if (fileMatch.charAt(0) !== '/' && !fileMatch.match(/\w+:\/\//)) {
|
||||
fileMatch = '/' + fileMatch;
|
||||
}
|
||||
let association = associations[fileMatch];
|
||||
if (!association) {
|
||||
association = [];
|
||||
associations[fileMatch] = association;
|
||||
}
|
||||
association.push(url);
|
||||
if (typeof fileMatch === 'string') {
|
||||
fileMatch = [fileMatch];
|
||||
}
|
||||
if (Array.isArray(fileMatch) && url) {
|
||||
fileMatch = fileMatch.map(fm => {
|
||||
if (fm[0] === '%') {
|
||||
fm = fm.replace(/%APP_SETTINGS_HOME%/, '/User');
|
||||
fm = fm.replace(/%MACHINE_SETTINGS_HOME%/, '/Machine');
|
||||
fm = fm.replace(/%APP_WORKSPACES_HOME%/, '/Workspaces');
|
||||
} else if (!fm.match(/^(\w+:\/\/|\/|!)/)) {
|
||||
fm = '/' + fm;
|
||||
}
|
||||
return fm;
|
||||
});
|
||||
associations.push({ fileMatch, uri: url });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -23,8 +23,13 @@ interface ISchemaAssociations {
|
|||
[pattern: string]: string[];
|
||||
}
|
||||
|
||||
interface ISchemaAssociation {
|
||||
fileMatch: string[];
|
||||
uri: string;
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -230,7 +235,7 @@ namespace LimitExceededWarnings {
|
|||
}
|
||||
|
||||
let jsonConfigurationSettings: JSONSchemaSettings[] | undefined = undefined;
|
||||
let schemaAssociations: ISchemaAssociations | undefined = undefined;
|
||||
let schemaAssociations: ISchemaAssociations | ISchemaAssociation[] | undefined = undefined;
|
||||
let formatterRegistration: Thenable<Disposable> | null = null;
|
||||
|
||||
// The settings have changed. Is send on server activation as well.
|
||||
|
@ -291,12 +296,16 @@ function updateConfiguration() {
|
|||
schemas: new Array<SchemaConfiguration>()
|
||||
};
|
||||
if (schemaAssociations) {
|
||||
for (const pattern in schemaAssociations) {
|
||||
const association = schemaAssociations[pattern];
|
||||
if (Array.isArray(association)) {
|
||||
association.forEach(uri => {
|
||||
languageSettings.schemas.push({ uri, fileMatch: [pattern] });
|
||||
});
|
||||
if (Array.isArray(schemaAssociations)) {
|
||||
Array.prototype.push.apply(languageSettings.schemas, schemaAssociations);
|
||||
} else {
|
||||
for (const pattern in schemaAssociations) {
|
||||
const association = schemaAssociations[pattern];
|
||||
if (Array.isArray(association)) {
|
||||
association.forEach(uri => {
|
||||
languageSettings.schemas.push({ uri, fileMatch: [pattern] });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ export interface IGrammar {
|
|||
}
|
||||
|
||||
export interface IJSONValidation {
|
||||
fileMatch: string;
|
||||
fileMatch: string | string[];
|
||||
url: string;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,9 +7,10 @@ import * as nls from 'vs/nls';
|
|||
import { ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import * as resources from 'vs/base/common/resources';
|
||||
import { isString } from 'vs/base/common/types';
|
||||
|
||||
interface IJSONValidationExtensionPoint {
|
||||
fileMatch: string;
|
||||
fileMatch: string | string[];
|
||||
url: string;
|
||||
}
|
||||
|
||||
|
@ -25,8 +26,11 @@ const configurationExtPoint = ExtensionsRegistry.registerExtensionPoint<IJSONVal
|
|||
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".'),
|
||||
type: ['string', 'array'],
|
||||
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: {
|
||||
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;
|
||||
}
|
||||
extensionValue.forEach(extension => {
|
||||
if (typeof extension.fileMatch !== 'string') {
|
||||
collector.error(nls.localize('invalid.fileMatch', "'configuration.jsonValidation.fileMatch' must be defined"));
|
||||
if (!isString(extension.fileMatch) && !(Array.isArray(extension.fileMatch) && extension.fileMatch.every(isString))) {
|
||||
collector.error(nls.localize('invalid.fileMatch', "'configuration.jsonValidation.fileMatch' must be defined as a string or an array of strings."));
|
||||
return;
|
||||
}
|
||||
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"));
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1208,7 +1208,7 @@ export class ExtensionEditor extends BaseEditor {
|
|||
$('th', undefined, localize('schema', "Schema"))
|
||||
),
|
||||
...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)
|
||||
))));
|
||||
|
||||
|
|
Loading…
Reference in a new issue