diff --git a/package-lock.json b/package-lock.json index e42b6846..0f2cfdfe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yaml-language-server", - "version": "0.5.5", + "version": "0.5.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/languageservice/services/documentSymbols.ts b/src/languageservice/services/documentSymbols.ts index b2382120..0c4c57e6 100644 --- a/src/languageservice/services/documentSymbols.ts +++ b/src/languageservice/services/documentSymbols.ts @@ -8,14 +8,15 @@ import { parse as parseYAML } from '../parser/yamlParser07'; import { SymbolInformation, TextDocument, DocumentSymbol } from 'vscode-languageserver-types'; -import { LanguageService } from 'vscode-json-languageservice'; +import { JSONSchemaService } from './jsonSchemaService'; +import { JSONDocumentSymbols } from 'vscode-json-languageservice/lib/umd/services/jsonDocumentSymbols'; export class YAMLDocumentSymbols { - private jsonLanguageService: LanguageService; + private jsonDocumentSymbols; - constructor(jsonLanguageService: LanguageService) { - this.jsonLanguageService = jsonLanguageService; + constructor(schemaService: JSONSchemaService) { + this.jsonDocumentSymbols = new JSONDocumentSymbols(schemaService); } public findDocumentSymbols(document: TextDocument): SymbolInformation[] { @@ -28,7 +29,7 @@ export class YAMLDocumentSymbols { let results = []; for (const yamlDoc of doc['documents']) { if (yamlDoc.root) { - results = results.concat(this.jsonLanguageService.findDocumentSymbols(document, yamlDoc)); + results = results.concat(this.jsonDocumentSymbols.findDocumentSymbols(document, yamlDoc)); } } @@ -44,7 +45,7 @@ export class YAMLDocumentSymbols { let results = []; for (const yamlDoc of doc['documents']) { if (yamlDoc.root) { - results = results.concat(this.jsonLanguageService.findDocumentSymbols2(document, yamlDoc)); + results = results.concat(this.jsonDocumentSymbols.findDocumentSymbols2(document, yamlDoc)); } } diff --git a/src/languageservice/services/jsonSchemaService.ts b/src/languageservice/services/jsonSchemaService.ts index 9b66ad44..4242bc5a 100644 --- a/src/languageservice/services/jsonSchemaService.ts +++ b/src/languageservice/services/jsonSchemaService.ts @@ -56,7 +56,8 @@ export interface IJSONSchemaService { /** * Looks up the appropriate schema for the given URI */ - getSchemaForResource(resource: string): Thenable; + // tslint:disable-next-line: no-any + getSchemaForResource(resource: string, document?: any): Thenable; /** * Returns all registered schema ids @@ -527,7 +528,7 @@ export class JSONSchemaService implements IJSONSchemaService { return resolveRefs(schema, schema, schemaURL).then(_ => new ResolvedSchema(schema, resolveErrors)); } - public getSchemaForResource(resource: string ): Thenable { + public getSchemaForResource(resource: string, doc = undefined): Thenable { const resolveSchema = () => { // check for matching file names, last to first for (let i = this.filePatternAssociations.length - 1; i >= 0; i--) { @@ -545,8 +546,8 @@ export class JSONSchemaService implements IJSONSchemaService { return resolveSchema(); } - this.loadSchema(schemaUri) - .then(unsolvedSchema => this.resolveSchemaContent(unsolvedSchema, schemaUri)) + return this.loadSchema(schemaUri) + .then(unsolvedSchema => this.resolveSchemaContent(unsolvedSchema, schemaUri)); }) .then(schema => schema, err => resolveSchema()); } else { diff --git a/src/languageservice/services/yamlHover.ts b/src/languageservice/services/yamlHover.ts index 51a7044f..2e7bbc08 100644 --- a/src/languageservice/services/yamlHover.ts +++ b/src/languageservice/services/yamlHover.ts @@ -10,17 +10,19 @@ import { Hover, TextDocument, Position } from 'vscode-languageserver-types'; import { matchOffsetToDocument2 } from '../utils/arrUtils'; import { LanguageSettings } from '../yamlLanguageService'; import { parse as parseYAML } from '../parser/yamlParser07'; +import { JSONSchemaService } from './jsonSchemaService'; +import { JSONHover } from 'vscode-json-languageservice/lib/umd/services/jsonHover'; export class YAMLHover { private promise: PromiseConstructor; private shouldHover: boolean; - private jsonLanguageService: LanguageService; + private jsonHover; - constructor(promiseConstructor: PromiseConstructor, jsonLanguageService: LanguageService) { + constructor(schemaService: JSONSchemaService, promiseConstructor: PromiseConstructor) { this.promise = promiseConstructor || Promise; this.shouldHover = true; - this.jsonLanguageService = jsonLanguageService; + this.jsonHover = new JSONHover(schemaService, [], Promise); } public configure(languageSettings: LanguageSettings) { @@ -41,6 +43,6 @@ export class YAMLHover { return this.promise.resolve(void 0); } - return this.jsonLanguageService.doHover(document, position, currentDoc); + return this.jsonHover.doHover(document, position, currentDoc); } } diff --git a/src/languageservice/services/yamlValidation.ts b/src/languageservice/services/yamlValidation.ts index a6a37b2f..be03493a 100644 --- a/src/languageservice/services/yamlValidation.ts +++ b/src/languageservice/services/yamlValidation.ts @@ -7,23 +7,24 @@ import { Diagnostic, TextDocument } from 'vscode-languageserver-types'; import { PromiseConstructor, LanguageSettings } from '../yamlLanguageService'; -import { LanguageService } from 'vscode-json-languageservice'; import { parse as parseYAML, YAMLDocument } from '../parser/yamlParser07'; import { SingleYAMLDocument } from '../parser/yamlParser04'; +import { JSONSchemaService } from './jsonSchemaService'; +import { JSONValidation } from 'vscode-json-languageservice/lib/umd/services/jsonValidation'; export class YAMLValidation { private promise: PromiseConstructor; private validationEnabled: boolean; - private jsonLanguageService: LanguageService; private customTags: String[]; + private jsonValidation; private MATCHES_MULTIPLE = 'Matches multiple schemas when only one must validate.'; - public constructor(promiseConstructor: PromiseConstructor, jsonLanguageService: LanguageService) { - this.promise = promiseConstructor; + public constructor(schemaService: JSONSchemaService, promiseConstructor: PromiseConstructor) { + this.promise = promiseConstructor || Promise; this.validationEnabled = true; - this.jsonLanguageService = jsonLanguageService; + this.jsonValidation = new JSONValidation(schemaService, this.promise); } public configure(settings: LanguageSettings) { @@ -42,7 +43,8 @@ export class YAMLValidation { const validationResult: Diagnostic[] = []; for (const currentYAMLDoc of yamlDocument.documents) { currentYAMLDoc.isKubernetes = isKubernetes; - const validation = await this.jsonLanguageService.doValidation(textDocument, currentYAMLDoc); + + const validation = await this.jsonValidation.doValidation(textDocument, currentYAMLDoc); const syd = currentYAMLDoc as unknown as SingleYAMLDocument; if (syd.errors.length > 0) { validationResult.push(...syd.errors); diff --git a/src/languageservice/yamlLanguageService.ts b/src/languageservice/yamlLanguageService.ts index 0b9aaf25..9ec7891d 100644 --- a/src/languageservice/yamlLanguageService.ts +++ b/src/languageservice/yamlLanguageService.ts @@ -125,21 +125,16 @@ export function getLanguageService(schemaRequestService: SchemaRequestService, contributions: JSONWorkerContribution[], promiseConstructor?: PromiseConstructor ): LanguageService { const promise = promiseConstructor || Promise; - const jsonLanguageService = getJSONLanguageService({ - schemaRequestService, - workspaceContext - }); const schemaService = new JSONSchemaService(schemaRequestService, workspaceContext); const completer = new YAMLCompletion(schemaService, contributions, promise); - const hover = new YAMLHover(promise, jsonLanguageService); - const yamlDocumentSymbols = new YAMLDocumentSymbols(jsonLanguageService); - const yamlValidation = new YAMLValidation(promise, jsonLanguageService); + const hover = new YAMLHover(schemaService, promise); + const yamlDocumentSymbols = new YAMLDocumentSymbols(schemaService); + const yamlValidation = new YAMLValidation(schemaService, promise); const formatter = new YAMLFormatter(); return { configure: settings => { - jsonLanguageService.configure(settings); schemaService.clearExternalSchemas(); if (settings.schemas) { settings.schemas.forEach(settings => { @@ -161,11 +156,7 @@ export function getLanguageService(schemaRequestService: SchemaRequestService, doHover: hover.doHover.bind(hover), findDocumentSymbols: yamlDocumentSymbols.findDocumentSymbols.bind(yamlDocumentSymbols), findDocumentSymbols2: yamlDocumentSymbols.findHierarchicalDocumentSymbols.bind(yamlDocumentSymbols), - resetSchema: (uri: string) => { - jsonLanguageService.resetSchema(uri); - return schemaService.onResourceChange(uri); - }, - + resetSchema: (uri: string) => schemaService.onResourceChange(uri), doFormat: formatter.format.bind(formatter) }; }