Skip to content

Commit

Permalink
Merge pull request #4 from Andrwe/master
Browse files Browse the repository at this point in the history
implemented detection for mixed usage of .template
  • Loading branch information
speshak committed Jun 19, 2020
2 parents 62ef848 + e96b5c4 commit 3300b32
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions ftdetect/cloudformation.vim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function! DetectCfn(type)
function! DetectCfn()
let likely = 0
let pointsRequired = 10

Expand Down Expand Up @@ -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
Expand All @@ -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

0 comments on commit 3300b32

Please sign in to comment.