From f10e8954b333522ce5300c63ea6e19162e7ae2c4 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 4 Mar 2022 17:53:27 +0100 Subject: [PATCH 1/2] add snapshot test for issue #809 --- tests/snapshot/hcl/issue809.hcl | 10 ++++++++ tests/snapshot/hcl/issue809.hcl.snap | 38 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/snapshot/hcl/issue809.hcl create mode 100644 tests/snapshot/hcl/issue809.hcl.snap 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..702afa8 --- /dev/null +++ b/tests/snapshot/hcl/issue809.hcl.snap @@ -0,0 +1,38 @@ +>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 +> } +#^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl +>} +#^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl +> +>variable "test" { +#^^^^^^^^^^^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl +> default = "test" +#^^^^^^^^^^^^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl +>} +#^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl +> \ No newline at end of file From 8a167bfa757e29ba07e080525e0e3b408a9a3cce Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 4 Mar 2022 17:55:10 +0100 Subject: [PATCH 2/2] 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.snap | 29 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) 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.snap b/tests/snapshot/hcl/issue809.hcl.snap index 702afa8..0c5465f 100644 --- a/tests/snapshot/hcl/issue809.hcl.snap +++ b/tests/snapshot/hcl/issue809.hcl.snap @@ -23,16 +23,33 @@ # ^^^^^ 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 +# ^ 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 meta.mapping.key.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 meta.braces.hcl meta.mapping.key.hcl +#^ source.hcl meta.block.hcl punctuation.section.block.end.hcl > >variable "test" { -#^^^^^^^^^^^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl +#^^^^^^^^ 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 meta.braces.hcl meta.mapping.key.hcl +#^^ 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 meta.braces.hcl meta.mapping.key.hcl +#^ source.hcl meta.block.hcl punctuation.section.block.end.hcl > \ No newline at end of file