From 9ad45a6c126d7457e9d63aaebec45fafed7cd437 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Tue, 15 Mar 2022 19:25:49 +0100 Subject: [PATCH] Fix highlighting for computed map keys (#8) * 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. --- syntaxes/hcl.tmGrammar.json | 2 +- tests/snapshot/hcl/issue809.hcl | 10 +++++ tests/snapshot/hcl/issue809.hcl.snap | 55 ++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 tests/snapshot/hcl/issue809.hcl create mode 100644 tests/snapshot/hcl/issue809.hcl.snap diff --git a/syntaxes/hcl.tmGrammar.json b/syntaxes/hcl.tmGrammar.json index 6781d43..48488b3 100644 --- a/syntaxes/hcl.tmGrammar.json +++ b/syntaxes/hcl.tmGrammar.json @@ -488,7 +488,7 @@ "name": "punctuation.section.parens.begin.hcl" } }, - "end": "(\\))\\s*(\\=)\\s*", + "end": "(\\))\\s*(=|:)\\s*", "endCaptures": { "1": { "name": "punctuation.section.parens.end.hcl" diff --git a/tests/snapshot/hcl/issue809.hcl b/tests/snapshot/hcl/issue809.hcl new file mode 100644 index 0000000..b0257b9 --- /dev/null +++ b/tests/snapshot/hcl/issue809.hcl @@ -0,0 +1,10 @@ +locals { + key_name = "testing" + test_example = { + (local.key_name): "test" + } +} + +variable "test" { + default = "test" +} diff --git a/tests/snapshot/hcl/issue809.hcl.snap b/tests/snapshot/hcl/issue809.hcl.snap new file mode 100644 index 0000000..0c5465f --- /dev/null +++ b/tests/snapshot/hcl/issue809.hcl.snap @@ -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 +> \ No newline at end of file