Skip to content

Commit

Permalink
Fix highlighting for computed map keys (#8)
Browse files Browse the repository at this point in the history
* add snapshot test for issue #809

* fix regex for computed object keys

The regex only matched for a `=` and was never able to find
a matching end, though matching everything until the end of
the file. Adding a `:` fixes this.
  • Loading branch information
dbanck authored Mar 15, 2022
1 parent b1d3bf7 commit 9ad45a6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion syntaxes/hcl.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@
"name": "punctuation.section.parens.begin.hcl"
}
},
"end": "(\\))\\s*(\\=)\\s*",
"end": "(\\))\\s*(=|:)\\s*",
"endCaptures": {
"1": {
"name": "punctuation.section.parens.end.hcl"
Expand Down
10 changes: 10 additions & 0 deletions tests/snapshot/hcl/issue809.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
locals {
key_name = "testing"
test_example = {
(local.key_name): "test"
}
}

variable "test" {
default = "test"
}
55 changes: 55 additions & 0 deletions tests/snapshot/hcl/issue809.hcl.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
>locals {
#^^^^^^ source.hcl meta.block.hcl entity.name.type.hcl
# ^ source.hcl meta.block.hcl
# ^ source.hcl meta.block.hcl punctuation.section.block.begin.hcl
> key_name = "testing"
#^^ source.hcl meta.block.hcl
# ^^^^^^^^ source.hcl meta.block.hcl variable.declaration.hcl variable.other.readwrite.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl keyword.operator.assignment.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl
# ^ source.hcl meta.block.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^^ source.hcl meta.block.hcl string.quoted.double.hcl
# ^ source.hcl meta.block.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
> test_example = {
#^^ source.hcl meta.block.hcl
# ^^^^^^^^^^^^ source.hcl meta.block.hcl variable.declaration.hcl variable.other.readwrite.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl keyword.operator.assignment.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl punctuation.section.braces.begin.hcl
> (local.key_name): "test"
#^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl punctuation.section.parens.begin.hcl
# ^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl keyword.operator.accessor.hcl
# ^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl variable.other.member.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl punctuation.section.parens.end.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^ source.hcl meta.block.hcl meta.braces.hcl string.quoted.double.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
> }
#^^ source.hcl meta.block.hcl meta.braces.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl punctuation.section.braces.end.hcl
>}
#^ source.hcl meta.block.hcl punctuation.section.block.end.hcl
>
>variable "test" {
#^^^^^^^^ source.hcl meta.block.hcl entity.name.type.hcl
# ^ source.hcl meta.block.hcl
# ^^^^^^ source.hcl meta.block.hcl variable.other.enummember.hcl
# ^ source.hcl meta.block.hcl
# ^ source.hcl meta.block.hcl punctuation.section.block.begin.hcl
> default = "test"
#^^ source.hcl meta.block.hcl
# ^^^^^^^ source.hcl meta.block.hcl variable.declaration.hcl variable.other.readwrite.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl keyword.operator.assignment.hcl
# ^ source.hcl meta.block.hcl variable.declaration.hcl
# ^ source.hcl meta.block.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^ source.hcl meta.block.hcl string.quoted.double.hcl
# ^ source.hcl meta.block.hcl string.quoted.double.hcl punctuation.definition.string.end.hcl
>}
#^ source.hcl meta.block.hcl punctuation.section.block.end.hcl
>

0 comments on commit 9ad45a6

Please sign in to comment.