-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime(hcl,terraform): Add runtime files for HCL and Terraform
closes: #15618 Signed-off-by: Gregory Anders <greg@gpanders.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
- Loading branch information
Showing
7 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |