From e96b5c44c3a1857fd0fa87164b9c3cac35bb1538 Mon Sep 17 00:00:00 2001 From: Andrwe Lord Weber Date: Thu, 18 Jun 2020 05:51:36 +0200 Subject: [PATCH] implemented detection for mixed usage of .template Signed-off-by: Andrwe Lord Weber --- ftdetect/cloudformation.vim | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/ftdetect/cloudformation.vim b/ftdetect/cloudformation.vim index 3d6fb13..c58d94c 100644 --- a/ftdetect/cloudformation.vim +++ b/ftdetect/cloudformation.vim @@ -1,4 +1,4 @@ -function! DetectCfn(type) +function! DetectCfn() let likely = 0 let pointsRequired = 10 @@ -50,16 +50,20 @@ function! DetectCfn(type) \['Resources', 1], \['Outputs', 1], \] + let json_type = 0 for lineContents in getline(1, line('$')) for strPoints in pointMap if lineContents =~ strPoints[0] let likely += strPoints[1] endif + if lineContents =~ "^\s*\{" + let json_type = 1 + endif if likely > pointsRequired - if a:type =~ "yaml" - set filetype=yaml.cloudformation - elseif a:type =~ "json" + if json_type == 1 set filetype=json.cloudformation + else + set filetype=yaml.cloudformation endif return endif @@ -68,7 +72,7 @@ function! DetectCfn(type) endfunction augroup filetypedetect - au BufRead,BufNewFile *.yaml,*.yml call DetectCfn('yaml') - au BufRead,BufNewFile *.json call DetectCfn('json') - au BufNewFile,BufRead *.template setfiletype yaml.cloudformation + au BufRead,BufNewFile *.yaml,*.yml call DetectCfn() + au BufRead,BufNewFile *.json call DetectCfn() + au BufNewFile,BufRead *.template call DetectCfn() augroup END