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

Consider different schema representations for variable defaults (to aid highlighting variable name) #96

Closed
radeksimko opened this issue Mar 2, 2022 · 0 comments · Fixed by #100
Assignees
Labels
enhancement New feature or request

Comments

@radeksimko
Copy link
Member

Background

Currently we pre-decode variable blocks (via earlydecoder) for type and we use that in the 2nd (real) decoding in combination with DependentBody to inform what type default is:

func variableDependentBody(vars map[string]module.Variable) map[schema.SchemaKey]*schema.BodySchema {
depBodies := make(map[schema.SchemaKey]*schema.BodySchema)
for name, mVar := range vars {
depKeys := schema.DependencyKeys{
Labels: []schema.LabelDependent{
{Index: 0, Value: name},
},
}
depBodies[schema.NewSchemaKey(depKeys)] = &schema.BodySchema{
Attributes: map[string]*schema.AttributeSchema{
"default": {
Expr: schema.ExprConstraints{schema.LiteralTypeExpr{Type: mVar.Type}},
IsOptional: true,
Description: lang.Markdown("Default value to use when variable is not explicitly set"),
},
},
}
}
return depBodies
}

This has the benefit of providing more contextual/relevant help for defaults, e.g.
2022-03-02 12 43 15

However the downside is that we also use the existence of DependentBody to inform the user of which label or attribute has "pre-set" (enum) values, which has the less desirable effect here in the variable block, as demonstrated by semantic highlighting in hashicorp/terraform-ls#817
156360469-5de34aef-a069-4c43-85b9-ad158b0bf888

Proposal

Explore how else we could signify the relationship between type and default which doesn't involve DependentBody or consider adding a flag to LabelSchema which would control whether the label should be reported as dependent. We already have Completable flag there for similar reasons.

@radeksimko radeksimko added the enhancement New feature or request label Mar 2, 2022
@radeksimko radeksimko changed the title Consider different schema representations for variable defaults Consider different schema representations for variable defaults (for highlighting) Mar 2, 2022
@radeksimko radeksimko changed the title Consider different schema representations for variable defaults (for highlighting) Consider different schema representations for variable defaults (to aid highlighting) Mar 2, 2022
@radeksimko radeksimko changed the title Consider different schema representations for variable defaults (to aid highlighting) Consider different schema representations for variable defaults (to aid highlighting variable name) Mar 3, 2022
@radeksimko radeksimko self-assigned this Mar 21, 2022
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 a pull request may close this issue.

1 participant