Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix highlighting for attribute access with a dash #933

Merged
merged 3 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions syntaxes/terraform.tmGrammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,27 +638,24 @@
"name": "keyword.operator.accessor.terraform"
}
},
"end": "\\w+(\\[[0-9\\*]+\\])?",
"end": "[[:alpha:]][[:alnum:]_-]*(\\[[0-9\\*]+\\])?",
dbanck marked this conversation as resolved.
Show resolved Hide resolved
"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"
}
]
},
"1": {
"patterns": [
},
{
"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"
}
]
Expand Down
12 changes: 9 additions & 3 deletions tests/snapshot/terraform/expressions_splat.tf.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,24 @@
#^^^ 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
>
>var.list[*].interfaces[0].name
#^^^ 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
>
16 changes: 16 additions & 0 deletions tests/snapshot/terraform/issue927.tf
Original file line number Diff line number Diff line change
@@ -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
}
107 changes: 107 additions & 0 deletions tests/snapshot/terraform/issue927.tf.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
>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 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.accessor.terraform
# ^^^^^^^^^^ source.terraform meta.block.terraform variable.other.member.terraform
>}
#^ source.terraform meta.block.terraform punctuation.section.block.end.terraform