Skip to content

Commit

Permalink
Merge a7f76c4 into d613734
Browse files Browse the repository at this point in the history
  • Loading branch information
JPinkney committed Jan 24, 2020
2 parents d613734 + a7f76c4 commit 092ff68
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/languageservice/services/yamlSchemaService.ts
Expand Up @@ -14,7 +14,7 @@ import * as nls from 'vscode-nls';
import { convertSimple2RegExpPattern } from '../utils/strings';
const localize = nls.loadMessageBundle();

export declare type CustomSchemaProvider = (uri: string) => Thenable<string>;
export declare type CustomSchemaProvider = (uri: string) => Thenable<string[]>;

export enum MODIFICATION_ACTIONS {
'delete',
Expand Down Expand Up @@ -241,25 +241,40 @@ export class YAMLSchemaService extends JSONSchemaService {
};
if (this.customSchemaProvider) {
return this.customSchemaProvider(resource)
.then(schemaUri => {
if (!schemaUri) {
.then(schemaUris => {
if (schemaUris.length === 0) {
return resolveSchema();
}

return this.loadSchema(schemaUri)
.then(unsolvedSchema => this.resolveSchemaContent(unsolvedSchema, schemaUri, []).then(schema => {
if (schema.schema && schema.schema.schemaSequence && schema.schema.schemaSequence[doc.currentDocIndex]) {
return new ResolvedSchema(schema.schema.schemaSequence[doc.currentDocIndex]);
return Promise.all(schemaUris.map(schemaUri => this.resolveCustomSchema(schemaUri, doc)));
})
.then(schemas =>
{
// If its not an array then its just a normal resolved schema
if (!Array.isArray(schemas)) {
return schemas;
}
return {
'errors': [],
'schema': {
'oneOf': schemas.map(schemaObj => schemaObj.schema)
}
return schema;
}));
})
.then(schema => schema, err => resolveSchema());
};
}, err => resolveSchema());
} else {
return resolveSchema();
}
}

private resolveCustomSchema(schemaUri, doc) {
return this.loadSchema(schemaUri)
.then(unsolvedSchema => this.resolveSchemaContent(unsolvedSchema, schemaUri, []).then(schema => {
if (schema.schema && schema.schema.schemaSequence && schema.schema.schemaSequence[doc.currentDocIndex]) {
return new ResolvedSchema(schema.schema.schemaSequence[doc.currentDocIndex]);
}
return schema;
}));
}

/**
* Save a schema with schema ID and schema content.
* Overrides previous schemas set for that schema ID.
Expand Down

0 comments on commit 092ff68

Please sign in to comment.