Skip to content

Commit 150b507

Browse files
gpanderschrisbra
authored andcommitted
runtime(hcl,terraform): Add runtime files for HCL and Terraform
closes: #15618 Signed-off-by: Gregory Anders <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 315b6f7 commit 150b507

7 files changed

Lines changed: 166 additions & 0 deletions

File tree

.github/MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ nsis/lang/russian.nsi @RestorerZ
1313
runtime/autoload/freebasic.vim @dkearns
1414
runtime/autoload/hare.vim @selenebun
1515
runtime/autoload/haskell.vim @alx741
16+
runtime/autoload/hcl.vim @gpanders
1617
runtime/autoload/javascript.vim @jsit
1718
runtime/autoload/modula2.vim @dkearns
1819
runtime/autoload/php.vim @david-szabo97
@@ -170,6 +171,7 @@ runtime/ftplugin/haml.vim @tpope
170171
runtime/ftplugin/hare.vim @selenebun
171172
runtime/ftplugin/haredoc.vim @selenebun
172173
runtime/ftplugin/heex.vim @cvincent
174+
runtime/ftplugin/hcl.vim @gpanders
173175
runtime/ftplugin/hgcommit.vim @k-takata
174176
runtime/ftplugin/hlsplaylist.vim @avidseeker
175177
runtime/ftplugin/hog.vim @wtfbbqhax
@@ -316,6 +318,7 @@ runtime/indent/go.vim @dbarnett
316318
runtime/indent/gyp.vim @ObserverOfTime
317319
runtime/indent/haml.vim @tpope
318320
runtime/indent/hare.vim @selenebun
321+
runtime/indent/hcl.vim @gpanders
319322
runtime/indent/hog.vim @wtfbbqhax
320323
runtime/indent/idlang.vim @dkearns
321324
runtime/indent/j.vim @glts
@@ -360,6 +363,7 @@ runtime/indent/systemverilog.vim @Kocha
360363
runtime/indent/tcl.vim @dkearns
361364
runtime/indent/tcsh.vim @dkearns
362365
runtime/indent/teraterm.vim @k-takata
366+
runtime/indent/terraform.vim @gpanders.com
363367
runtime/indent/thrift.vim @jiangyinzuo
364368
runtime/indent/typescript.vim @HerringtonDarkholme
365369
runtime/indent/typst.vim @gpanders
@@ -459,6 +463,7 @@ runtime/syntax/haml.vim @tpope
459463
runtime/syntax/hare.vim @selenebun
460464
runtime/syntax/haredoc.vim @selenebun
461465
runtime/syntax/haskell.vim @coot
466+
runtime/syntax/hcl.vim @gpanders
462467
runtime/syntax/help_ru.vim @RestorerZ
463468
runtime/syntax/hgcommit.vim @k-takata
464469
runtime/syntax/hitest.vim @lacygoill
@@ -566,6 +571,7 @@ runtime/syntax/systemverilog.vim @Kocha
566571
runtime/syntax/tap.vim @petdance
567572
runtime/syntax/tcsh.vim @dkearns
568573
runtime/syntax/teraterm.vim @k-takata
574+
runtime/syntax/terraform.vim @gpanders
569575
runtime/syntax/thrift.vim @jiangyinzuo
570576
runtime/syntax/tidy.vim @dkearns
571577
runtime/syntax/tmux.vim @ericpruitt

runtime/autoload/hcl.vim

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
" Language: HCL
2+
" Maintainer: Gregory Anders
3+
" Last Change: 2024-09-03
4+
" Based on: https://github.com/hashivim/vim-terraform
5+
6+
function! hcl#indentexpr(lnum)
7+
" Beginning of the file should have no indent
8+
if a:lnum == 0
9+
return 0
10+
endif
11+
12+
" Usual case is to continue at the same indent as the previous non-blank line.
13+
let prevlnum = prevnonblank(a:lnum-1)
14+
let thisindent = indent(prevlnum)
15+
16+
" If that previous line is a non-comment ending in [ { (, increase the
17+
" indent level.
18+
let prevline = getline(prevlnum)
19+
if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$'
20+
let thisindent += &shiftwidth
21+
endif
22+
23+
" If the current line ends a block, decrease the indent level.
24+
let thisline = getline(a:lnum)
25+
if thisline =~# '^\s*[\)}\]]'
26+
let thisindent -= &shiftwidth
27+
endif
28+
29+
" If the previous line starts a block comment /*, increase by one
30+
if prevline =~# '/\*'
31+
let thisindent += 1
32+
endif
33+
34+
" If the previous line ends a block comment */, decrease by one
35+
if prevline =~# '\*/'
36+
let thisindent -= 1
37+
endif
38+
39+
return thisindent
40+
endfunction

runtime/ftplugin/hcl.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
" Vim filetype plugin
2+
" Language: HCL
3+
" Maintainer: Gregory Anders
4+
" Last Change: 2024-09-03
5+
6+
if exists('b:did_ftplugin')
7+
finish
8+
endif
9+
10+
runtime! ftplugin/terraform.vim

runtime/indent/hcl.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
" Vim indent file
2+
" Language: HCL
3+
" Maintainer: Gregory Anders
4+
" Upstream: https://github.com/hashivim/vim-terraform
5+
" Last Change: 2024-09-03
6+
7+
if exists('b:did_indent')
8+
finish
9+
endif
10+
let b:did_indent = 1
11+
12+
setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 expandtab
13+
setlocal indentexpr=hcl#indentexpr(v:lnum)
14+
setlocal indentkeys+=<:>,0=},0=)
15+
16+
let b:undo_indent = 'setlocal ai< sw< ts< sts< et< inde< indk<'

runtime/indent/terraform.vim

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
" Vim indent file
2+
" Language: Terraform
3+
" Maintainer: Gregory Anders
4+
" Upstream: https://github.com/hashivim/vim-terraform
5+
" Last Change: 2024-09-03
6+
7+
if exists('b:did_indent')
8+
finish
9+
endif
10+
11+
runtime! indent/hcl.vim

runtime/syntax/hcl.vim

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
" Vim syntax file
2+
" Language: HCL
3+
" Maintainer: Gregory Anders
4+
" Upstream: https://github.com/hashivim/vim-terraform
5+
" Last Change: 2024-09-03
6+
7+
if exists('b:current_syntax')
8+
finish
9+
endif
10+
11+
syn iskeyword a-z,A-Z,48-57,_,-
12+
13+
syn case match
14+
15+
" A block is introduced by a type, some number of labels - which are either
16+
" strings or identifiers - and an opening curly brace. Match the type.
17+
syn match hclBlockType /^\s*\zs\K\k*\ze\s\+\(\("\K\k*"\|\K\k*\)\s\+\)*{/
18+
19+
" An attribute name is an identifier followed by an equals sign.
20+
syn match hclAttributeAssignment /\(\K\k*\.\)*\K\k*\s\+=\s/ contains=hclAttributeName
21+
syn match hclAttributeName /\<\K\k*\>/ contained
22+
23+
syn keyword hclValueBool true false
24+
25+
syn keyword hclTodo contained TODO FIXME XXX BUG
26+
syn region hclComment start="/\*" end="\*/" contains=hclTodo,@Spell
27+
syn region hclComment start="#" end="$" contains=hclTodo,@Spell
28+
syn region hclComment start="//" end="$" contains=hclTodo,@Spell
29+
30+
""" misc.
31+
syn match hclValueDec "\<[0-9]\+\([kKmMgG]b\?\)\?\>"
32+
syn match hclValueHexaDec "\<0x[0-9a-f]\+\([kKmMgG]b\?\)\?\>"
33+
syn match hclBraces "[\[\]]"
34+
35+
""" skip \" and \\ in strings.
36+
syn region hclValueString start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=hclStringInterp
37+
syn region hclStringInterp matchgroup=hclBraces start=/\(^\|[^$]\)\$\zs{/ end=/}/ contained contains=ALLBUT,hclAttributeName
38+
syn region hclHereDocText start=/<<-\?\z([a-z0-9A-Z]\+\)/ end=/^\s*\z1/ contains=hclStringInterp
39+
40+
"" Functions.
41+
syn match hclFunction "[a-z0-9]\+(\@="
42+
43+
""" HCL2
44+
syn keyword hclRepeat for in
45+
syn keyword hclConditional if
46+
syn keyword hclValueNull null
47+
48+
" enable block folding
49+
syn region hclBlockBody matchgroup=hclBraces start="{" end="}" fold transparent
50+
51+
hi def link hclComment Comment
52+
hi def link hclTodo Todo
53+
hi def link hclBraces Delimiter
54+
hi def link hclAttributeName Identifier
55+
hi def link hclBlockType Type
56+
hi def link hclValueBool Boolean
57+
hi def link hclValueDec Number
58+
hi def link hclValueHexaDec Number
59+
hi def link hclValueString String
60+
hi def link hclHereDocText String
61+
hi def link hclFunction Function
62+
hi def link hclRepeat Repeat
63+
hi def link hclConditional Conditional
64+
hi def link hclValueNull Constant
65+
66+
let b:current_syntax = 'hcl'

runtime/syntax/terraform.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
" Vim syntax file
2+
" Language: Terraform
3+
" Maintainer: Gregory Anders
4+
" Upstream: https://github.com/hashivim/vim-terraform
5+
" Last Change: 2024-09-03
6+
7+
if exists('b:current_syntax')
8+
finish
9+
endif
10+
11+
runtime! syntax/hcl.vim
12+
13+
syn keyword terraType string bool number object tuple list map set any
14+
15+
hi def link terraType Type
16+
17+
let b:current_syntax = 'terraform'

0 commit comments

Comments
 (0)