Skip to content

Commit

Permalink
Fix an issue with running validation on change (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Nov 3, 2022
1 parent 5d6b5a9 commit 7a72432
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions server/src/handlers/validationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,38 @@ export class ValidationHandler extends YamlValidationHandler {
this.cfnConnection = connection;

this.cfnSettings.documents.onDidSave((event) => {
this.validate(event.document);
this.validateCfn(event.document);
});
this.cfnSettings.documents.onDidOpen((event) => {
this.validate(event.document);
this.validateCfn(event.document);
});
this.cfnSettings.documents.onDidClose((event) => {
this.cleanPendingValidationCfn(event.document);
this.cfnConnection.sendDiagnostics({ uri: event.document.uri, diagnostics: [] });
});
}

// override the base version of this function
// to prevent the onDidChange function
validate(_: TextDocument): void {}

validateCfn(textDocument: TextDocument): void {
this.cfnSettings.pendingValidationRequests[textDocument.uri] = setTimeout(() => {
delete this.cfnSettings.pendingValidationRequests[textDocument.uri];
this.validateTextDocument(textDocument);
}, this.cfnSettings.validationDelayMs);
}

private cleanPendingValidationCfn(textDocument: TextDocument): void {
const request = this.cfnSettings.pendingValidationRequests[textDocument.uri];

if (request) {
clearTimeout(request);
delete this.cfnSettings.pendingValidationRequests[textDocument.uri];
}
}


private patchTemplateSchema(registrySchemaDirectory: string) {
const stub = readFileSync(__dirname + '/../../schema/resource-patch-stub.json', 'utf8');
let templateSchema = JSON.parse(readFileSync(__dirname + '/../../schema/all-spec.json', 'utf8'));
Expand Down

0 comments on commit 7a72432

Please sign in to comment.