Skip to content

Commit

Permalink
Merge 615001b into 3d79d59
Browse files Browse the repository at this point in the history
  • Loading branch information
JPinkney committed Jan 27, 2020
2 parents 3d79d59 + 615001b commit 8340624
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 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 | string[]>;

export enum MODIFICATION_ACTIONS {
'delete',
Expand Down Expand Up @@ -241,25 +241,44 @@ export class YAMLSchemaService extends JSONSchemaService {
};
if (this.customSchemaProvider) {
return this.customSchemaProvider(resource)
.then(schemaUri => {
if (!schemaUri) {
return resolveSchema();
.then(schemaUris => {
if (Array.isArray(schemaUris)) {
if (schemaUris.length === 0) {
return resolveSchema();
}
return Promise.all(schemaUris.map(schemaUri => this.resolveCustomSchema(schemaUri, doc))).then(schemas =>
({
'errors': [],
'schema': {
'oneOf': schemas.map(schemaObj => schemaObj.schema)
}
})
, err => resolveSchema());

} else {
// we just got a normal schema uri back from the provider. default to the original implementation
if (!schemaUris) {
return resolveSchema();
}

return this.resolveCustomSchema(schemaUris, doc).then(schema => schema, err => 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 schema;
}));
})
.then(schema => schema, err => resolveSchema());
});
} else {
return resolveSchema();
}
}

private async 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 8340624

Please sign in to comment.