]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(hcl,terraform): Add runtime files for HCL and Terraform
authorGregory Anders <greg@gpanders.com>
Wed, 4 Sep 2024 20:19:45 +0000 (22:19 +0200)
committerChristian Brabandt <cb@256bit.org>
Wed, 4 Sep 2024 20:19:45 +0000 (22:19 +0200)
closes: #15618

Signed-off-by: Gregory Anders <greg@gpanders.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
.github/MAINTAINERS
runtime/autoload/hcl.vim [new file with mode: 0644]
runtime/ftplugin/hcl.vim [new file with mode: 0644]
runtime/indent/hcl.vim [new file with mode: 0644]
runtime/indent/terraform.vim [new file with mode: 0644]
runtime/syntax/hcl.vim [new file with mode: 0644]
runtime/syntax/terraform.vim [new file with mode: 0644]

index 9c2923fc3a4313e7e88c31750ba83d42ef709b3e..9cb50fe966417a56780e2e1b319128ed32ddaaf0 100644 (file)
@@ -13,6 +13,7 @@ nsis/lang/russian.nsi                 @RestorerZ
 runtime/autoload/freebasic.vim         @dkearns
 runtime/autoload/hare.vim              @selenebun
 runtime/autoload/haskell.vim           @alx741
+runtime/autoload/hcl.vim               @gpanders
 runtime/autoload/javascript.vim                @jsit
 runtime/autoload/modula2.vim           @dkearns
 runtime/autoload/php.vim               @david-szabo97
@@ -170,6 +171,7 @@ runtime/ftplugin/haml.vim           @tpope
 runtime/ftplugin/hare.vim              @selenebun
 runtime/ftplugin/haredoc.vim           @selenebun
 runtime/ftplugin/heex.vim              @cvincent
+runtime/ftplugin/hcl.vim               @gpanders
 runtime/ftplugin/hgcommit.vim          @k-takata
 runtime/ftplugin/hlsplaylist.vim               @avidseeker
 runtime/ftplugin/hog.vim               @wtfbbqhax
@@ -316,6 +318,7 @@ runtime/indent/go.vim                       @dbarnett
 runtime/indent/gyp.vim                 @ObserverOfTime
 runtime/indent/haml.vim                        @tpope
 runtime/indent/hare.vim                        @selenebun
+runtime/indent/hcl.vim                 @gpanders
 runtime/indent/hog.vim                 @wtfbbqhax
 runtime/indent/idlang.vim              @dkearns
 runtime/indent/j.vim                   @glts
@@ -360,6 +363,7 @@ runtime/indent/systemverilog.vim    @Kocha
 runtime/indent/tcl.vim                 @dkearns
 runtime/indent/tcsh.vim                        @dkearns
 runtime/indent/teraterm.vim            @k-takata
+runtime/indent/terraform.vim           @gpanders.com
 runtime/indent/thrift.vim              @jiangyinzuo
 runtime/indent/typescript.vim          @HerringtonDarkholme
 runtime/indent/typst.vim               @gpanders
@@ -459,6 +463,7 @@ runtime/syntax/haml.vim                     @tpope
 runtime/syntax/hare.vim                        @selenebun
 runtime/syntax/haredoc.vim             @selenebun
 runtime/syntax/haskell.vim             @coot
+runtime/syntax/hcl.vim                 @gpanders
 runtime/syntax/help_ru.vim             @RestorerZ
 runtime/syntax/hgcommit.vim            @k-takata
 runtime/syntax/hitest.vim              @lacygoill
@@ -566,6 +571,7 @@ runtime/syntax/systemverilog.vim    @Kocha
 runtime/syntax/tap.vim                 @petdance
 runtime/syntax/tcsh.vim                        @dkearns
 runtime/syntax/teraterm.vim            @k-takata
+runtime/syntax/terraform.vim           @gpanders
 runtime/syntax/thrift.vim              @jiangyinzuo
 runtime/syntax/tidy.vim                        @dkearns
 runtime/syntax/tmux.vim                        @ericpruitt
diff --git a/runtime/autoload/hcl.vim b/runtime/autoload/hcl.vim
new file mode 100644 (file)
index 0000000..2215fc8
--- /dev/null
@@ -0,0 +1,40 @@
+" Language:    HCL
+" Maintainer:  Gregory Anders
+" Last Change: 2024-09-03
+" Based on:    https://github.com/hashivim/vim-terraform
+
+function! hcl#indentexpr(lnum)
+  " Beginning of the file should have no indent
+  if a:lnum == 0
+    return 0
+  endif
+
+  " Usual case is to continue at the same indent as the previous non-blank line.
+  let prevlnum = prevnonblank(a:lnum-1)
+  let thisindent = indent(prevlnum)
+
+  " If that previous line is a non-comment ending in [ { (, increase the
+  " indent level.
+  let prevline = getline(prevlnum)
+  if prevline !~# '^\s*\(#\|//\)' && prevline =~# '[\[{\(]\s*$'
+    let thisindent += &shiftwidth
+  endif
+
+  " If the current line ends a block, decrease the indent level.
+  let thisline = getline(a:lnum)
+  if thisline =~# '^\s*[\)}\]]'
+    let thisindent -= &shiftwidth
+  endif
+
+  " If the previous line starts a block comment /*, increase by one
+  if prevline =~# '/\*'
+    let thisindent += 1
+  endif
+
+  " If the previous line ends a block comment */, decrease by one
+  if prevline =~# '\*/'
+    let thisindent -= 1
+  endif
+
+  return thisindent
+endfunction
diff --git a/runtime/ftplugin/hcl.vim b/runtime/ftplugin/hcl.vim
new file mode 100644 (file)
index 0000000..c47a037
--- /dev/null
@@ -0,0 +1,10 @@
+" Vim filetype plugin
+" Language:    HCL
+" Maintainer:  Gregory Anders
+" Last Change: 2024-09-03
+
+if exists('b:did_ftplugin')
+  finish
+endif
+
+runtime! ftplugin/terraform.vim
diff --git a/runtime/indent/hcl.vim b/runtime/indent/hcl.vim
new file mode 100644 (file)
index 0000000..b13d2c5
--- /dev/null
@@ -0,0 +1,16 @@
+" Vim indent file
+" Language:    HCL
+" Maintainer:  Gregory Anders
+" Upstream:    https://github.com/hashivim/vim-terraform
+" Last Change: 2024-09-03
+
+if exists('b:did_indent')
+  finish
+endif
+let b:did_indent = 1
+
+setlocal autoindent shiftwidth=2 tabstop=2 softtabstop=2 expandtab
+setlocal indentexpr=hcl#indentexpr(v:lnum)
+setlocal indentkeys+=<:>,0=},0=)
+
+let b:undo_indent = 'setlocal ai< sw< ts< sts< et< inde< indk<'
diff --git a/runtime/indent/terraform.vim b/runtime/indent/terraform.vim
new file mode 100644 (file)
index 0000000..d62813d
--- /dev/null
@@ -0,0 +1,11 @@
+" Vim indent file
+" Language:    Terraform
+" Maintainer:  Gregory Anders
+" Upstream:    https://github.com/hashivim/vim-terraform
+" Last Change: 2024-09-03
+
+if exists('b:did_indent')
+  finish
+endif
+
+runtime! indent/hcl.vim
diff --git a/runtime/syntax/hcl.vim b/runtime/syntax/hcl.vim
new file mode 100644 (file)
index 0000000..5e9349a
--- /dev/null
@@ -0,0 +1,66 @@
+" Vim syntax file
+" Language:    HCL
+" Maintainer:  Gregory Anders
+" Upstream:    https://github.com/hashivim/vim-terraform
+" Last Change: 2024-09-03
+
+if exists('b:current_syntax')
+  finish
+endif
+
+syn iskeyword a-z,A-Z,48-57,_,-
+
+syn case match
+
+" A block is introduced by a type, some number of labels - which are either
+" strings or identifiers - and an opening curly brace.  Match the type.
+syn match hclBlockType /^\s*\zs\K\k*\ze\s\+\(\("\K\k*"\|\K\k*\)\s\+\)*{/
+
+" An attribute name is an identifier followed by an equals sign.
+syn match hclAttributeAssignment /\(\K\k*\.\)*\K\k*\s\+=\s/ contains=hclAttributeName
+syn match hclAttributeName /\<\K\k*\>/ contained
+
+syn keyword hclValueBool true false
+
+syn keyword hclTodo         contained TODO FIXME XXX BUG
+syn region  hclComment      start="/\*" end="\*/" contains=hclTodo,@Spell
+syn region  hclComment      start="#" end="$" contains=hclTodo,@Spell
+syn region  hclComment      start="//" end="$" contains=hclTodo,@Spell
+
+""" misc.
+syn match hclValueDec      "\<[0-9]\+\([kKmMgG]b\?\)\?\>"
+syn match hclValueHexaDec  "\<0x[0-9a-f]\+\([kKmMgG]b\?\)\?\>"
+syn match hclBraces        "[\[\]]"
+
+""" skip \" and \\ in strings.
+syn region hclValueString   start=/"/ skip=/\\\\\|\\"/ end=/"/ contains=hclStringInterp
+syn region hclStringInterp  matchgroup=hclBraces start=/\(^\|[^$]\)\$\zs{/ end=/}/ contained contains=ALLBUT,hclAttributeName
+syn region hclHereDocText   start=/<<-\?\z([a-z0-9A-Z]\+\)/ end=/^\s*\z1/ contains=hclStringInterp
+
+"" Functions.
+syn match hclFunction "[a-z0-9]\+(\@="
+
+""" HCL2
+syn keyword hclRepeat         for in
+syn keyword hclConditional    if
+syn keyword hclValueNull      null
+
+" enable block folding
+syn region hclBlockBody matchgroup=hclBraces start="{" end="}" fold transparent
+
+hi def link hclComment           Comment
+hi def link hclTodo              Todo
+hi def link hclBraces            Delimiter
+hi def link hclAttributeName     Identifier
+hi def link hclBlockType         Type
+hi def link hclValueBool         Boolean
+hi def link hclValueDec          Number
+hi def link hclValueHexaDec      Number
+hi def link hclValueString       String
+hi def link hclHereDocText       String
+hi def link hclFunction          Function
+hi def link hclRepeat            Repeat
+hi def link hclConditional       Conditional
+hi def link hclValueNull         Constant
+
+let b:current_syntax = 'hcl'
diff --git a/runtime/syntax/terraform.vim b/runtime/syntax/terraform.vim
new file mode 100644 (file)
index 0000000..559dc79
--- /dev/null
@@ -0,0 +1,17 @@
+" Vim syntax file
+" Language:    Terraform
+" Maintainer:  Gregory Anders
+" Upstream:    https://github.com/hashivim/vim-terraform
+" Last Change: 2024-09-03
+
+if exists('b:current_syntax')
+  finish
+endif
+
+runtime! syntax/hcl.vim
+
+syn keyword terraType string bool number object tuple list map set any
+
+hi def link terraType Type
+
+let b:current_syntax = 'terraform'