Skip to content

Commit

Permalink
Merge 2d63dc3 into 75d031d
Browse files Browse the repository at this point in the history
  • Loading branch information
JPinkney committed Aug 23, 2019
2 parents 75d031d + 2d63dc3 commit 0c8b3ca
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ 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 { CustomSchemaProvider } from './jsonSchemaService';

export class YAMLHover {

private promise: PromiseConstructor;
private shouldHover: boolean;
private jsonLanguageService: LanguageService;
public customSchemaProvider: CustomSchemaProvider = null;

constructor(promiseConstructor: PromiseConstructor, jsonLanguageService: LanguageService) {
this.promise = promiseConstructor || Promise;
Expand All @@ -41,6 +43,20 @@ export class YAMLHover {
return this.promise.resolve(void 0);
}

if (this.customSchemaProvider) {
return this.customSchemaProvider(document.uri).then(schemaURI => {
this.jsonLanguageService.configure({
schemas: [
{
fileMatch: ['*.yaml', '*.yml'],
uri: schemaURI
}
]
});
return this.jsonLanguageService.doHover(document, position, currentDoc);
});
}

return this.jsonLanguageService.doHover(document, position, currentDoc);
}
}
15 changes: 15 additions & 0 deletions src/languageservice/services/yamlValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ 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 { CustomSchemaProvider } from './jsonSchemaService';

export class YAMLValidation {

private promise: PromiseConstructor;
private validationEnabled: boolean;
private jsonLanguageService: LanguageService;
private customTags: String[];
public customSchemaProvider: CustomSchemaProvider = null;

private MATCHES_MULTIPLE = 'Matches multiple schemas when only one must validate.';

Expand All @@ -42,6 +44,19 @@ export class YAMLValidation {
const validationResult: Diagnostic[] = [];
for (const currentYAMLDoc of yamlDocument.documents) {
currentYAMLDoc.isKubernetes = isKubernetes;

if (this.customSchemaProvider) {
const uri = await this.customSchemaProvider(textDocument.uri);
this.jsonLanguageService.configure({
validate: true,
schemas: [
{
fileMatch: ['*.yaml', '*.yml'],
uri: uri
}
]
});
}
const validation = await this.jsonLanguageService.doValidation(textDocument, currentYAMLDoc);
const syd = currentYAMLDoc as unknown as SingleYAMLDocument;
if (syd.errors.length > 0) {
Expand Down
2 changes: 2 additions & 0 deletions src/languageservice/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export function getLanguageService(schemaRequestService: SchemaRequestService,
},
registerCustomSchemaProvider: (schemaProvider: CustomSchemaProvider) => {
schemaService.registerCustomSchemaProvider(schemaProvider);
hover.customSchemaProvider = schemaProvider;
yamlValidation.customSchemaProvider = schemaProvider;
},
doComplete: completer.doComplete.bind(completer),
doResolve: completer.doResolve.bind(completer),
Expand Down

0 comments on commit 0c8b3ca

Please sign in to comment.