-
Notifications
You must be signed in to change notification settings - Fork 130
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
Recognize individual expressions when nested #496
Comments
This functionality has been released in v0.31.0 of the language server. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Background (current state)
Through the logic in
hcl-lang/schema
and related schema interraform-schema
we currently provide completion, hover and semantic highlighting for the outermost expression (with a few exceptions for HCL objects and tuples) and generally don't take into account (potentially infinite) nesting.Completion
For
ami
we can provide completion of anystring
candidates, for completion withindepends_on
brackets we can provide references to other resources and data sources.Hover
When hovering over
"test"
we can match the string constant against schema (string type) and show relevant popup ("test"
string). Similarly when hovering over[ aws_vpc.test ]
we can match it against schema (set of references) and show relevant popup (set of references).Semantic Tokens
Here
"test"
is expected to be string (per schema) andaws_vpc.test
is expected to be a reference (per schema), so LS will report relevant semantic tokens in both cases.Use-cases
User would benefit from recognition of arbitrarily nested expressions in all relevant functions of the LS, as described in more detail below.
Completion
within
${}
we should provide any compatible expressions (presumably all primitive types).for the second position we should provide any available references other than
aws_vpc.test
.Hover
when hovering over
data.aws_ami.example.test.id
we display popup with details about the reference (stringThe ID of the AMI.
)when hover over
aws_vpc.test
we display popup with details about the reference (resource).Semantic Tokens
"ami-${data.aws_ami.example.test.image_id}"
is highlighted as a template expression withami-
highlighted as string anddata.aws_ami.example.test.image_id
as reference.2 * var.core_count
is highlighted as multiplication expression with2
highlighted as number andvar.core_count
as a reference.Proposal
hclsyntax.TupleConsExpr
(attr = [ var.foo, _ ]
)hclsyntax.ObjectConsItem
(attr = { foo = _ }
) in the context of object/map as value &object({})
type declarationhclsyntax.ObjectConsExpr
(attr = { _ }
) in the context of object/map as value &object({})
type declarationhclsyntax.TemplateExpr
(attr = "${_}"
)hclsyntax.FunctionCallExpr
(attr = fun(_)
) in the context of type declarations such aslist()
,set()
,map()
& built-in functionshclsyntax.TupleConsExpr
(attr = [ var.foo, _ ]
)hclsyntax.ObjectConsItem
(attr = { foo = _ }
) in the context of object/map as value &object({})
type declarationhclsyntax.ObjectConsExpr
(attr = { _ }
) in the context of object/map as value &object({})
type declarationhclsyntax.TemplateExpr
(attr = "${_}"
)hclsyntax.FunctionCallExpr
(attr = fun(_)
) in the context of type declarations such aslist()
,set()
,map()
& built-in functionshclsyntax.TupleConsExpr
(attr = [ var.foo, _ ]
)hclsyntax.ObjectConsItem
(attr = { foo = _ }
) in the context of object/map as value &object({})
type declarationhclsyntax.ObjectConsExpr
(attr = { _ }
) in the context of object/map as value &object({})
type declarationhclsyntax.TemplateExpr
(attr = "${_}"
)hclsyntax.FunctionCallExpr
(attr = fun(_)
) in the context of type declarations such aslist()
,set()
,map()
& built-in functionshashicorp/hcl-lang
schema.TupleConsExpr
Expression interface
indecoder
such that completion for any expression type can be delegated and each type can also delegate completion of nested expressions to other expression typesdecoder.NewExpression(expr hcl.Expression, cons schema.ExprConstraints) Expression
schema.ObjectTypeDeclItemExpr
lang.PrimitiveTypeDeclExpr
lang.ComplexTypeDeclExpr
lang.ObjectTypeDeclItemExpr
schema.AnyExprOfType{Type: cty.Type}
to act as an alias toschema.LiteralTypeExpr
schema.TraversalExpr
Type
Type
Type
Type
LiteralValueExpr
asdecoder.Expression
ScopeTraversalExpr
asdecoder.Expression
(for type declarations, references and keywords)TupleConsExpr
asdecoder.Expression
ObjectConsExpr
asdecoder.Expression
FunctionCallExpr
asdecoder.Expression
(for type declarations)TemplateExpr
asdecoder.Expression
TemplateWrapExpr
asdecoder.Expression
decoder.Expression
types intoPathDecoder
-CandidatesAtPos
decoder.Expression
types intoPathDecoder
-HoverAtPos
decoder.Expression
types intoPathDecoder
-SemanticTokensInFile
Prototype WIP: hashicorp/hcl-lang@d21a863
The text was updated successfully, but these errors were encountered: