@@ -23,7 +23,7 @@ import { CfnLint } from '../services/cfnlint';
2323import { Diagnostic } from 'vscode-languageserver-types' ;
2424import { LanguageService } from 'yaml-language-server' ;
2525import { ValidationHandler as YamlValidationHandler } from 'yaml-language-server/out/server/src/languageserver/handlers/validationHandlers' ;
26-
26+ import { isCloudFormation } from './helpers' ;
2727
2828// code adopted from https://github.com/redhat-developer/yaml-language-server/blob/main/src/languageserver/handlers/validationHandlers.ts
2929export class ValidationHandler extends YamlValidationHandler {
@@ -43,26 +43,6 @@ export class ValidationHandler extends YamlValidationHandler {
4343 } ) ;
4444 }
4545
46- private isCloudFormation ( template : string , filename : string ) : Boolean {
47-
48- if ( / " ? A W S T e m p l a t e F o r m a t V e r s i o n " ? \s * / . exec ( template ) ) {
49- this . cfnConnection . console . log ( "Determined this file is a CloudFormation Template. " + filename +
50- ". Found the string AWSTemplateFormatVersion" ) ;
51- return true ;
52- }
53- if ( / \n ? " ? R e s o u r c e s " ? \s * : / . exec ( template ) ) {
54- if ( / " ? T y p e " ? \s * : \s * " ? ' ? [ a - z A - Z 0 - 9 ] { 2 , 64 } : : [ a - z A - Z 0 - 9 ] { 2 , 64 } / . exec ( template ) ) {
55- // filter out serverless.io templates
56- if ( ! ( / \n r e s o u r c e s : / . exec ( template ) && / \n p r o v i d e r : / . exec ( template ) ) ) {
57- this . cfnConnection . console . log ( "Determined this file is a CloudFormation Template. " + filename +
58- ". Found 'Resources' and 'Type: [a-zA-Z0-9]{2,64}::[a-zA-Z0-9]{2,64}'" ) ;
59- return true ;
60- }
61- }
62- }
63- return false ;
64- }
65-
6646 private patchTemplateSchema ( registrySchemaDirectory : string ) {
6747 const stub = readFileSync ( __dirname + '/../../schema/resource-patch-stub.json' , 'utf8' ) ;
6848 let templateSchema = JSON . parse ( readFileSync ( __dirname + '/../../schema/all-spec.json' , 'utf8' ) ) ;
@@ -85,7 +65,7 @@ export class ValidationHandler extends YamlValidationHandler {
8565
8666 let fileToLint = URI . parse ( uri ) . fsPath ;
8767
88- let isCfn = this . isCloudFormation ( document . getText ( ) , uri . toString ( ) ) ;
68+ let isCfn = isCloudFormation ( document . getText ( ) , uri . toString ( ) , this . cfnConnection ) ;
8969
9070 this . cfnConnection . sendNotification ( 'cfn/isPreviewable' , isCfn ) ;
9171
0 commit comments