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

decoder: Add support for parenthesis on LHS (map keys & attribute names) #367

Merged
merged 13 commits into from
Jan 22, 2024

Conversation

radeksimko
Copy link
Member

@radeksimko radeksimko commented Jan 18, 2024

Depends on:


This enables support for interpolated map keys and object attribute names,. Since this is enabled by parenthesis it is closely related to that linked PR which adds support for that expression type.

In other words this enables parenthesis support on the LHS (left hand side).

Example:

map_attr = {
  (var.keyname) = "foo"
}

Implementation Notes

This does not enable equivalent support inside of inferred maps/objects, such as in the context of Terraform's locals. This is currently tracked under hashicorp/terraform-ls#1586

It originally started out as "hidden implementation detail" of decoder (the decision whether interpolation is allowed was originally just implied by AnyExpression{} until I realised that we still use schema.Map{} and schema.Object{} in contexts where we expect interpolation, including interpolated keys, so I had to walk it back and make it a more 1st class feature of the schema, for better or worse.

For that reason, this will also require some changes downstream:

UX Examples

Completion

Screenshot 2024-01-18 at 20 47 21

Hover

Screenshot 2024-01-18 at 20 49 08

Semantic Tokens

Screenshot 2024-01-18 at 20 49 28

Reference Origins

2024-01-18 20 50 14

@radeksimko radeksimko added the enhancement New feature or request label Jan 18, 2024
@radeksimko radeksimko force-pushed the f-expr-parenthesis-lhs branch from 3eeec7e to e53cd53 Compare January 18, 2024 20:37
@radeksimko radeksimko marked this pull request as ready for review January 18, 2024 21:07
@radeksimko radeksimko requested a review from a team as a code owner January 18, 2024 21:07
@radeksimko radeksimko force-pushed the f-expr-parenthesis-lhs branch from e53cd53 to c073161 Compare January 19, 2024 10:05
schema/constraint_object.go Outdated Show resolved Hide resolved
@radeksimko radeksimko requested a review from dbanck January 19, 2024 13:11
Copy link
Member

@dbanck dbanck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just two small nits

decoder/expr_object_semtok.go Outdated Show resolved Hide resolved
decoder/expr_object_semtok.go Outdated Show resolved Hide resolved
@radeksimko radeksimko merged commit f43c272 into main Jan 22, 2024
5 checks passed
@radeksimko radeksimko deleted the f-expr-parenthesis-lhs branch January 22, 2024 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants