From 0f5e706dcdc8291fbf6a5328498ecf1a2f3f9913 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Thu, 10 Feb 2022 11:56:33 +0100 Subject: [PATCH 1/3] Add a base snapshot test for issue #927 --- tests/snapshot/terraform/issue927.tf | 16 +++ tests/snapshot/terraform/issue927.tf.snap | 113 ++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 tests/snapshot/terraform/issue927.tf create mode 100644 tests/snapshot/terraform/issue927.tf.snap diff --git a/tests/snapshot/terraform/issue927.tf b/tests/snapshot/terraform/issue927.tf new file mode 100644 index 000000000..6e0420860 --- /dev/null +++ b/tests/snapshot/terraform/issue927.tf @@ -0,0 +1,16 @@ +variable "foo" {} +output "result-val" { value = var.foo } + +variable "some-var" { + default = "value" +} + +module "foo-mod" { + source = "./foo" + foo = var.some-var +} + +module "bar" { + source = "./foo" + foo = module.foo-mod.result-val +} \ No newline at end of file diff --git a/tests/snapshot/terraform/issue927.tf.snap b/tests/snapshot/terraform/issue927.tf.snap new file mode 100644 index 000000000..3271d0dd4 --- /dev/null +++ b/tests/snapshot/terraform/issue927.tf.snap @@ -0,0 +1,113 @@ +>variable "foo" {} +#^^^^^^^^ source.terraform meta.block.terraform entity.name.type.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform punctuation.section.block.begin.terraform +# ^ source.terraform meta.block.terraform punctuation.section.block.end.terraform +>output "result-val" { value = var.foo } +#^^^^^^ source.terraform meta.block.terraform entity.name.type.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^^^^^^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform punctuation.section.block.begin.terraform +# ^ source.terraform meta.block.terraform +# ^^^^^ source.terraform meta.block.terraform variable.declaration.terraform variable.other.readwrite.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform keyword.operator.assignment.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^^^ source.terraform meta.block.terraform support.constant.terraform +# ^ source.terraform meta.block.terraform keyword.operator.accessor.terraform +# ^^^ source.terraform meta.block.terraform variable.other.member.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform punctuation.section.block.end.terraform +> +>variable "some-var" { +#^^^^^^^^ source.terraform meta.block.terraform entity.name.type.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^^^^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform punctuation.section.block.begin.terraform +> default = "value" +#^^ source.terraform meta.block.terraform +# ^^^^^^^ source.terraform meta.block.terraform variable.declaration.terraform variable.other.readwrite.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform keyword.operator.assignment.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +>} +#^ source.terraform meta.block.terraform punctuation.section.block.end.terraform +> +>module "foo-mod" { +#^^^^^^ source.terraform meta.block.terraform entity.name.type.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^^^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform punctuation.section.block.begin.terraform +> source = "./foo" +#^^ source.terraform meta.block.terraform +# ^^^^^^ source.terraform meta.block.terraform variable.declaration.terraform variable.other.readwrite.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform keyword.operator.assignment.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +> foo = var.some-var +#^^ source.terraform meta.block.terraform +# ^^^ source.terraform meta.block.terraform variable.declaration.terraform variable.other.readwrite.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform keyword.operator.assignment.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^^^ source.terraform meta.block.terraform support.constant.terraform +# ^ source.terraform meta.block.terraform keyword.operator.accessor.terraform +# ^^^^ source.terraform meta.block.terraform variable.other.member.terraform +# ^ source.terraform meta.block.terraform keyword.operator.arithmetic.terraform +# ^^^ source.terraform meta.block.terraform support.constant.terraform +>} +#^ source.terraform meta.block.terraform punctuation.section.block.end.terraform +> +>module "bar" { +#^^^^^^ source.terraform meta.block.terraform entity.name.type.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +# ^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform punctuation.section.block.begin.terraform +> source = "./foo" +#^^ source.terraform meta.block.terraform +# ^^^^^^ source.terraform meta.block.terraform variable.declaration.terraform variable.other.readwrite.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform keyword.operator.assignment.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.begin.terraform +# ^^^^^ source.terraform meta.block.terraform string.quoted.double.terraform +# ^ source.terraform meta.block.terraform string.quoted.double.terraform punctuation.definition.string.end.terraform +> foo = module.foo-mod.result-val +#^^ source.terraform meta.block.terraform +# ^^^ source.terraform meta.block.terraform variable.declaration.terraform variable.other.readwrite.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform keyword.operator.assignment.terraform +# ^ source.terraform meta.block.terraform variable.declaration.terraform +# ^^^^^^ source.terraform meta.block.terraform support.constant.terraform +# ^ source.terraform meta.block.terraform keyword.operator.accessor.terraform +# ^^^ source.terraform meta.block.terraform variable.other.member.terraform +# ^ source.terraform meta.block.terraform keyword.operator.arithmetic.terraform +# ^^^ source.terraform meta.block.terraform +# ^ source.terraform meta.block.terraform keyword.operator.accessor.terraform +# ^^^^^^ source.terraform meta.block.terraform variable.other.member.terraform +# ^ source.terraform meta.block.terraform keyword.operator.arithmetic.terraform +# ^^^^ source.terraform meta.block.terraform +>} +#^ source.terraform meta.block.terraform punctuation.section.block.end.terraform \ No newline at end of file From eeb9d7ac20630a5e6c4a6435ede5fd9907fc4d60 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Thu, 10 Feb 2022 11:57:51 +0100 Subject: [PATCH 2/3] Fix syntax highlighting for attribute access with dashes The dash hasn't been a part of the attribute access end capture. Furthermore, we didn't correctly detect splat and indices on attribute access notation. --- syntaxes/terraform.tmGrammar.json | 8 ++------ tests/snapshot/terraform/expressions_splat.tf.snap | 12 +++++++++--- tests/snapshot/terraform/issue927.tf.snap | 12 +++--------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/syntaxes/terraform.tmGrammar.json b/syntaxes/terraform.tmGrammar.json index 116e90bc9..9ffb9f44b 100644 --- a/syntaxes/terraform.tmGrammar.json +++ b/syntaxes/terraform.tmGrammar.json @@ -638,7 +638,7 @@ "name": "keyword.operator.accessor.terraform" } }, - "end": "\\w+(\\[[0-9\\*]+\\])?", + "end": "[[:alpha:]][[:alnum:]_-]*(\\[[0-9\\*]+\\])?", "endCaptures": { "0": { "patterns": [ @@ -646,11 +646,7 @@ "match": "\\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\\b", "comment": "Attribute access", "name": "variable.other.member.terraform" - } - ] - }, - "1": { - "patterns": [ + }, { "match": "\\d+", "comment": "Subscript", diff --git a/tests/snapshot/terraform/expressions_splat.tf.snap b/tests/snapshot/terraform/expressions_splat.tf.snap index 3bcdfaead..8f01c05bc 100644 --- a/tests/snapshot/terraform/expressions_splat.tf.snap +++ b/tests/snapshot/terraform/expressions_splat.tf.snap @@ -21,7 +21,9 @@ #^^^ source.terraform support.constant.terraform # ^ source.terraform keyword.operator.accessor.terraform # ^^^^ source.terraform variable.other.member.terraform -# ^^^ source.terraform +# ^ source.terraform +# ^ source.terraform keyword.operator.splat.terraform +# ^ source.terraform # ^ source.terraform keyword.operator.accessor.terraform # ^^ source.terraform variable.other.member.terraform > @@ -29,10 +31,14 @@ #^^^ source.terraform support.constant.terraform # ^ source.terraform keyword.operator.accessor.terraform # ^^^^ source.terraform variable.other.member.terraform -# ^^^ source.terraform +# ^ source.terraform +# ^ source.terraform keyword.operator.splat.terraform +# ^ source.terraform # ^ source.terraform keyword.operator.accessor.terraform # ^^^^^^^^^^ source.terraform variable.other.member.terraform -# ^^^ source.terraform +# ^ source.terraform +# ^ source.terraform constant.numeric.integer.terraform +# ^ source.terraform # ^ source.terraform keyword.operator.accessor.terraform # ^^^^ source.terraform variable.other.member.terraform > \ No newline at end of file diff --git a/tests/snapshot/terraform/issue927.tf.snap b/tests/snapshot/terraform/issue927.tf.snap index 3271d0dd4..564d1e86e 100644 --- a/tests/snapshot/terraform/issue927.tf.snap +++ b/tests/snapshot/terraform/issue927.tf.snap @@ -71,9 +71,7 @@ # ^ source.terraform meta.block.terraform variable.declaration.terraform # ^^^ source.terraform meta.block.terraform support.constant.terraform # ^ source.terraform meta.block.terraform keyword.operator.accessor.terraform -# ^^^^ source.terraform meta.block.terraform variable.other.member.terraform -# ^ source.terraform meta.block.terraform keyword.operator.arithmetic.terraform -# ^^^ source.terraform meta.block.terraform support.constant.terraform +# ^^^^^^^^ source.terraform meta.block.terraform variable.other.member.terraform >} #^ source.terraform meta.block.terraform punctuation.section.block.end.terraform > @@ -102,12 +100,8 @@ # ^ source.terraform meta.block.terraform variable.declaration.terraform # ^^^^^^ source.terraform meta.block.terraform support.constant.terraform # ^ source.terraform meta.block.terraform keyword.operator.accessor.terraform -# ^^^ source.terraform meta.block.terraform variable.other.member.terraform -# ^ source.terraform meta.block.terraform keyword.operator.arithmetic.terraform -# ^^^ source.terraform meta.block.terraform +# ^^^^^^^ source.terraform meta.block.terraform variable.other.member.terraform # ^ source.terraform meta.block.terraform keyword.operator.accessor.terraform -# ^^^^^^ source.terraform meta.block.terraform variable.other.member.terraform -# ^ source.terraform meta.block.terraform keyword.operator.arithmetic.terraform -# ^^^^ source.terraform meta.block.terraform +# ^^^^^^^^^^ source.terraform meta.block.terraform variable.other.member.terraform >} #^ source.terraform meta.block.terraform punctuation.section.block.end.terraform \ No newline at end of file From c4abca8b20f1d1117fc8a7f592d57567cf6f7de2 Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Thu, 10 Feb 2022 15:23:31 +0100 Subject: [PATCH 3/3] add comments to attribute access section --- syntaxes/terraform.tmGrammar.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/syntaxes/terraform.tmGrammar.json b/syntaxes/terraform.tmGrammar.json index 9ffb9f44b..ee5b1f407 100644 --- a/syntaxes/terraform.tmGrammar.json +++ b/syntaxes/terraform.tmGrammar.json @@ -639,22 +639,23 @@ } }, "end": "[[:alpha:]][[:alnum:]_-]*(\\[[0-9\\*]+\\])?", + "comment": "Matches a variable with an optional splat or index ([*]/[0])", "endCaptures": { "0": { "patterns": [ { "match": "\\b(?!null|false|true)[[:alpha:]][[:alnum:]_-]*\\b", - "comment": "Attribute access", + "comment": "Attribute name including - and _", "name": "variable.other.member.terraform" }, { "match": "\\d+", - "comment": "Subscript", + "comment": "Optional attribute index", "name": "constant.numeric.integer.terraform" }, { "match": "\\*", - "comment": "Attribute-only splat", + "comment": "Optional attribute-only splat", "name": "keyword.operator.splat.terraform" } ]