@@ -36,13 +36,38 @@ export class ValidationHandler extends YamlValidationHandler {
3636 this . cfnConnection = connection ;
3737
3838 this . cfnSettings . documents . onDidSave ( ( event ) => {
39- this . validate ( event . document ) ;
39+ this . validateCfn ( event . document ) ;
4040 } ) ;
4141 this . cfnSettings . documents . onDidOpen ( ( event ) => {
42- this . validate ( event . document ) ;
42+ this . validateCfn ( event . document ) ;
43+ } ) ;
44+ this . cfnSettings . documents . onDidClose ( ( event ) => {
45+ this . cleanPendingValidationCfn ( event . document ) ;
46+ this . cfnConnection . sendDiagnostics ( { uri : event . document . uri , diagnostics : [ ] } ) ;
4347 } ) ;
4448 }
4549
50+ // override the base version of this function
51+ // to prevent the onDidChange function
52+ validate ( _ : TextDocument ) : void { }
53+
54+ validateCfn ( textDocument : TextDocument ) : void {
55+ this . cfnSettings . pendingValidationRequests [ textDocument . uri ] = setTimeout ( ( ) => {
56+ delete this . cfnSettings . pendingValidationRequests [ textDocument . uri ] ;
57+ this . validateTextDocument ( textDocument ) ;
58+ } , this . cfnSettings . validationDelayMs ) ;
59+ }
60+
61+ private cleanPendingValidationCfn ( textDocument : TextDocument ) : void {
62+ const request = this . cfnSettings . pendingValidationRequests [ textDocument . uri ] ;
63+
64+ if ( request ) {
65+ clearTimeout ( request ) ;
66+ delete this . cfnSettings . pendingValidationRequests [ textDocument . uri ] ;
67+ }
68+ }
69+
70+
4671 private patchTemplateSchema ( registrySchemaDirectory : string ) {
4772 const stub = readFileSync ( __dirname + '/../../schema/resource-patch-stub.json' , 'utf8' ) ;
4873 let templateSchema = JSON . parse ( readFileSync ( __dirname + '/../../schema/all-spec.json' , 'utf8' ) ) ;
0 commit comments