File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1- function ! DetectCfn (type )
1+ function ! DetectCfn ()
22 let likely = 0
33 let pointsRequired = 10
44
@@ -50,16 +50,20 @@ function! DetectCfn(type)
5050 \[ ' Resources' , 1 ],
5151 \[ ' Outputs' , 1 ],
5252 \]
53+ let json_type = 0
5354 for lineContents in getline (1 , line (' $' ))
5455 for strPoints in pointMap
5556 if lineContents = ~ strPoints[0 ]
5657 let likely += strPoints[1 ]
5758 endif
59+ if lineContents = ~ " ^\s *\{ "
60+ let json_type = 1
61+ endif
5862 if likely > pointsRequired
59- if a: type = ~ " yaml"
60- set filetype = yaml.cloudformation
61- elseif a: type = ~ " json"
63+ if json_type == 1
6264 set filetype = json.cloudformation
65+ else
66+ set filetype = yaml.cloudformation
6367 endif
6468 return
6569 endif
@@ -68,7 +72,7 @@ function! DetectCfn(type)
6872endfunction
6973
7074augroup filetypedetect
71- au BufRead ,BufNewFile *.yaml,*.yml call DetectCfn (' yaml ' )
72- au BufRead ,BufNewFile *.json call DetectCfn (' json ' )
73- au BufNewFile ,BufRead *.template setfiletype yaml.cloudformation
75+ au BufRead ,BufNewFile *.yaml,*.yml call DetectCfn ()
76+ au BufRead ,BufNewFile *.json call DetectCfn ()
77+ au BufNewFile ,BufRead *.template call DetectCfn ()
7478augroup END
You can’t perform that action at this time.
0 commit comments