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

Improve highlighting within objects/maps #112

Merged
merged 5 commits into from
Mar 22, 2024
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
11 changes: 4 additions & 7 deletions src/_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ repository:
match: '\"[^\"\r\n]*\"'
- name: variable.other.enummember.hcl
comment: Block label (Indentifier)
match: '[[:alpha:]][[:alnum:]_-]*'
match: "[[:alpha:]][[:alnum:]_-]*"
"3":
name: punctuation.section.block.begin.hcl
end: \}
Expand Down Expand Up @@ -229,7 +229,7 @@ repository:
- match: \.\.\.
name: keyword.operator.hcl
- match: "\\:"
scope: keyword.operator.hcl
name: keyword.operator.hcl
brackets:
begin: \[
beginCaptures:
Expand Down Expand Up @@ -264,17 +264,14 @@ repository:
- include: "#objects"
- include: "#inline_for_expression"
- include: "#inline_if_expression"
- match: \b((?!null|false|true)[[:alpha:]][[:alnum:]_-]*)\s*(\=\>?)\s*
- match: \b((?!null|false|true)[[:alpha:]][[:alnum:]_-]*)\s*(\=(?!=))\s*
comment: Literal, named object key
captures:
"1":
name: meta.mapping.key.hcl variable.other.readwrite.hcl
"2":
name: keyword.operator.assignment.hcl
patterns:
- match: \=\>
name: storage.type.function.hcl
- match: \b((").*("))\s*(\=)\s*
- match: ^\s*((").*("))\s*(\=)\s*
comment: String object key
captures:
"1":
Expand Down
13 changes: 4 additions & 9 deletions syntaxes/hcl.tmGrammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions syntaxes/terraform.tmGrammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/snapshot/hcl/expressions_conditional.hcl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# ^ source.hcl keyword.operator.accessor.hcl
# ^ source.hcl variable.other.member.hcl
# ^ source.hcl
# ^ source.hcl
# ^ source.hcl keyword.operator.hcl
# ^ source.hcl
# ^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^^^^ source.hcl string.quoted.double.hcl
Expand All @@ -30,7 +30,7 @@
# ^^ source.hcl meta.function-call.hcl constant.numeric.integer.hcl
# ^ source.hcl meta.function-call.hcl punctuation.section.parens.end.hcl
# ^ source.hcl
# ^ source.hcl
# ^ source.hcl keyword.operator.hcl
# ^ source.hcl
# ^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^ source.hcl string.quoted.double.hcl
Expand All @@ -44,7 +44,7 @@
# ^ source.hcl
# ^^ source.hcl constant.numeric.integer.hcl
# ^ source.hcl
# ^ source.hcl
# ^ source.hcl keyword.operator.hcl
# ^ source.hcl
# ^ source.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^ source.hcl string.quoted.double.hcl
Expand Down
10 changes: 10 additions & 0 deletions tests/snapshot/hcl/issue79.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
block {
attr = var.test
attr2 = var.test == "foo" ? "true" : "false"
nested_obj = {
attr = var.test
attr2 = var.test == "foo" ? "true" : "false"
"attr2" = var.test == "foo" ? "true" : "false"
(attr2) = var.test == "foo" ? "true" : "false"
}
}
134 changes: 134 additions & 0 deletions tests/snapshot/hcl/issue79.hcl.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
>block {
#^^^^^ source.hcl meta.block.hcl entity.name.type.hcl
# ^ source.hcl meta.block.hcl
# ^ source.hcl meta.block.hcl punctuation.section.block.begin.hcl
> attr = var.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
# ^ source.hcl meta.block.hcl keyword.operator.accessor.hcl
# ^^^^ source.hcl meta.block.hcl variable.other.member.hcl
> attr2 = var.test == "foo" ? "true" : "false"
#^^^^ 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
# ^ source.hcl meta.block.hcl keyword.operator.accessor.hcl
# ^^^^ source.hcl meta.block.hcl variable.other.member.hcl
# ^ source.hcl meta.block.hcl
# ^^ source.hcl meta.block.hcl keyword.operator.hcl
# ^ source.hcl meta.block.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
# ^ source.hcl meta.block.hcl keyword.operator.hcl
# ^ source.hcl meta.block.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
# ^ source.hcl meta.block.hcl keyword.operator.hcl
# ^ source.hcl meta.block.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
> nested_obj = {
#^^^^ 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
> attr = var.test
#^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl
# ^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl variable.other.readwrite.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl keyword.operator.assignment.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl
# ^^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl
> attr2 = var.test == "foo" ? "true" : "false"
#^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl
# ^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl variable.other.readwrite.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl keyword.operator.assignment.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl
# ^^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl
# ^^ source.hcl meta.block.hcl meta.braces.hcl keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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
> "attr2" = var.test == "foo" ? "true" : "false"
#^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.hcl string.quoted.double.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl meta.mapping.key.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.hcl
# ^^^^^^^^^ source.hcl meta.block.hcl meta.braces.hcl
# ^^ source.hcl meta.block.hcl meta.braces.hcl keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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
> (attr2) = var.test == "foo" ? "true" : "false"
#^^^^^^^^^ 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 punctuation.section.parens.end.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.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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 keyword.operator.hcl
# ^ source.hcl meta.block.hcl meta.braces.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
4 changes: 2 additions & 2 deletions tests/snapshot/hcl/issue941.hcl.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# ^^^^^^^ source.hcl comment.line.number-sign.hcl
> : #Comment
#^^ source.hcl
# ^ source.hcl
# ^ source.hcl keyword.operator.hcl
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl
# ^ source.hcl comment.line.number-sign.hcl punctuation.definition.comment.hcl
# ^^^^^^^ source.hcl comment.line.number-sign.hcl
Expand Down Expand Up @@ -73,7 +73,7 @@
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl comment.line.number-sign.hcl
> : #
#^^^^ source.hcl
# ^ source.hcl
# ^ source.hcl keyword.operator.hcl
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ source.hcl
# ^ source.hcl comment.line.number-sign.hcl punctuation.definition.comment.hcl
> lookup(local.instance_size_map, local.cloud, null) #If instance size is not provided and var.insane_mode is false, lookup in this table.
Expand Down
6 changes: 3 additions & 3 deletions tests/snapshot/terraform/expressions_conditional.tf.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# ^ source.hcl.terraform keyword.operator.accessor.hcl
# ^ source.hcl.terraform variable.other.member.hcl
# ^ source.hcl.terraform
# ^ source.hcl.terraform
# ^ source.hcl.terraform keyword.operator.hcl
# ^ source.hcl.terraform
# ^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^^^^^ source.hcl.terraform string.quoted.double.hcl
Expand All @@ -31,7 +31,7 @@
# ^^ source.hcl.terraform meta.function-call.hcl constant.numeric.integer.hcl
# ^ source.hcl.terraform meta.function-call.hcl punctuation.section.parens.end.hcl
# ^ source.hcl.terraform
# ^ source.hcl.terraform
# ^ source.hcl.terraform keyword.operator.hcl
# ^ source.hcl.terraform
# ^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^ source.hcl.terraform string.quoted.double.hcl
Expand All @@ -45,7 +45,7 @@
# ^ source.hcl.terraform
# ^^ source.hcl.terraform constant.numeric.integer.hcl
# ^ source.hcl.terraform
# ^ source.hcl.terraform
# ^ source.hcl.terraform keyword.operator.hcl
# ^ source.hcl.terraform
# ^ source.hcl.terraform string.quoted.double.hcl punctuation.definition.string.begin.hcl
# ^^^^^ source.hcl.terraform string.quoted.double.hcl
Expand Down
Loading
Loading