Solidify handling of optional/default object attributes #917
Labels
enhancement
New feature or request
textDocument/completion
textDocument/hover
textDocument/semanticTokens
Semantic syntax highlighting
Background - TF Core
Support of optional and default object attributes has been developed through various experiments over time. We currently don't reflect any of these in IntelliSense.
Terraform 0.14 (optional types)
hashicorp/terraform#26540
Terraform 0.15 (default values)
hashicorp/terraform#26766
Terraform 1.3 (optional type with defaults)
hashicorp/terraform#31154
The Core team now considers this implementation/syntax to be stable and doesn't have more immediate plans for changing it.
Background - LS
We currently only reflect optional types as present in Terraform v0.14 via the
typeexpr
package was copied over from TF Core as part of theearlydecoder
. This allows us to decode variable types, such that we can then use it in IntelliSense formodule
inputs.That IntelliSense however only enables us to identify
object
, not the fact that it has an optional attribute - all attributes are treated/reported as required currently.Implementation Notes
earlydecoder
/ metadataIt seems impractical to distinguish between the different implementations between TF versions in the context of
earlydecoder
which is generally designed to run early and handle configuration of any TF version without knowing what that version is. We can take advantage of the final v1.3+ backwards-compatible implementation there as upstreamed into HCL v2.14.0.IntelliSense
If possible, IntelliSense we provide should reflect the Terraform version in use. In practice this means that:
< v0.14
configs: No optional attributes are recognised in completion, hover, or semantic highlightingv0.14.x
configs:optional(type)
with single attribute is recognised invariable
type
completion, hover and semantic highlightingv0.15+
configs: functiondefaults()
is recognized for completion, hover and semantic highlightingv1.3+
configs:optional(type, default_val)
with two attributes is recognised invariable
type
completion, hover and semantic highlightingProposal
terraform-schema
earlydecoder
: Use upstreamed HCLtypexpr
package terraform-schema#140hcl-lang
/terraform-ls
decoder.Decoder
to enable "legacy" optional types (single-argumentoptional()
)terraform-ls
: Enable the "legacy" mode on Terraform v0.14+ with relevant experiment enabled onlydecoder.Decoder
to enable "modern" optional types (with two-argumentoptional()
)terraform-ls
: Enable the "modern" mode on Terraform 1.3+ onlyoptional()
invariable
type
optional()
invariable
type
optional()
invariable
type
defaults()
function in v0.15+defaults()
function in v0.15+defaults()
function in v0.15+The text was updated successfully, but these errors were encountered: