From 1def88719406a499a1c857154b4c578d4be92e80 Mon Sep 17 00:00:00 2001 From: Josh Pinkney Date: Mon, 27 Jan 2020 11:11:11 -0500 Subject: [PATCH] Made yamlSchemaService accept multiple uris from requestCustomSchema --- .../services/yamlSchemaService.ts | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/src/languageservice/services/yamlSchemaService.ts b/src/languageservice/services/yamlSchemaService.ts index 10f1db21..89e550a1 100644 --- a/src/languageservice/services/yamlSchemaService.ts +++ b/src/languageservice/services/yamlSchemaService.ts @@ -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; +export declare type CustomSchemaProvider = (uri: string) => Thenable; export enum MODIFICATION_ACTIONS { 'delete', @@ -242,17 +242,27 @@ export class YAMLSchemaService extends JSONSchemaService { if (this.customSchemaProvider) { return this.customSchemaProvider(resource) .then(schemaUri => { - if (!schemaUri) { - 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]); + + if (Array.isArray(schemaUri)) { + if (schemaUri.length === 0) { + return resolveSchema(); } - return schema; - })); + return Promise.all(schemaUri.map(schemaUri => this.resolveCustomSchema(schemaUri, doc))).then(schemas => + ({ + 'errors': [], + 'schema': { + 'oneOf': schemas.map(schemaObj => schemaObj.schema) + } + }) + , err => resolveSchema()); + + } + + if (!schemaUri) { + return resolveSchema(); + } + + return this.resolveCustomSchema(schemaUri, doc); }) .then(schema => schema, err => resolveSchema()); } else { @@ -260,6 +270,15 @@ export class YAMLSchemaService extends JSONSchemaService { } } + private async resolveCustomSchema(schemaUri, doc) { + const unresolvedSchema = await this.loadSchema(schemaUri); + const schema = await this.resolveSchemaContent(unresolvedSchema, schemaUri, []); + 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.