diff --git a/decoder/dependent_body_test.go b/decoder/dependent_body_test.go index 1a583803..30371f34 100644 --- a/decoder/dependent_body_test.go +++ b/decoder/dependent_body_test.go @@ -111,17 +111,22 @@ func TestBodySchema_DependentBodySchema_dependentAttr(t *testing.T) { firstDepBody := &schema.BodySchema{ Attributes: map[string]*schema.AttributeSchema{ "backend": { - Expr: schema.LiteralTypeOnly(cty.String), - IsDepKey: true, + Expr: schema.LiteralTypeOnly(cty.String), + IsDepKey: true, + SemanticTokenModifiers: lang.SemanticTokenModifiers{}, }, }, } secondDepBody := &schema.BodySchema{ Attributes: map[string]*schema.AttributeSchema{ - "extra": {Expr: schema.LiteralTypeOnly(cty.Number)}, + "extra": { + Expr: schema.LiteralTypeOnly(cty.Number), + SemanticTokenModifiers: lang.SemanticTokenModifiers{}, + }, "backend": { - Expr: schema.LiteralTypeOnly(cty.String), - IsDepKey: true, + Expr: schema.LiteralTypeOnly(cty.String), + IsDepKey: true, + SemanticTokenModifiers: lang.SemanticTokenModifiers{}, }, }, } diff --git a/decoder/semantic_tokens.go b/decoder/semantic_tokens.go index a43cbd20..37027b0a 100644 --- a/decoder/semantic_tokens.go +++ b/decoder/semantic_tokens.go @@ -56,14 +56,16 @@ func (d *PathDecoder) tokensForBody(body *hclsyntax.Body, bodySchema *schema.Bod attrSchema = bodySchema.AnyAttribute } - modifiers := make([]lang.SemanticTokenModifier, 0) + attrModifiers := make([]lang.SemanticTokenModifier, 0) + attrModifiers = append(attrModifiers, parentModifiers...) if isDependent { - modifiers = append(modifiers, lang.TokenModifierDependent) + attrModifiers = append(attrModifiers, lang.TokenModifierDependent) } + attrModifiers = append(attrModifiers, attrSchema.SemanticTokenModifiers...) tokens = append(tokens, lang.SemanticToken{ Type: lang.TokenAttrName, - Modifiers: modifiers, + Modifiers: attrModifiers, Range: attr.NameRange, }) diff --git a/decoder/semantic_tokens_test.go b/decoder/semantic_tokens_test.go index 3aeee9ab..03b14b73 100644 --- a/decoder/semantic_tokens_test.go +++ b/decoder/semantic_tokens_test.go @@ -658,8 +658,10 @@ resource "vault_auth_backend" "blah" { }, }, { // source - Type: lang.TokenAttrName, - Modifiers: []lang.SemanticTokenModifier{}, + Type: lang.TokenAttrName, + Modifiers: []lang.SemanticTokenModifier{ + lang.SemanticTokenModifier("module"), + }, Range: hcl.Range{ Filename: "test.tf", Start: hcl.Pos{ @@ -692,8 +694,10 @@ resource "vault_auth_backend" "blah" { }, }, { // count - Type: lang.TokenAttrName, - Modifiers: []lang.SemanticTokenModifier{}, + Type: lang.TokenAttrName, + Modifiers: []lang.SemanticTokenModifier{ + lang.SemanticTokenModifier("module"), + }, Range: hcl.Range{ Filename: "test.tf", Start: hcl.Pos{ diff --git a/schema/attribute_schema.go b/schema/attribute_schema.go index c06db23f..968905ab 100644 --- a/schema/attribute_schema.go +++ b/schema/attribute_schema.go @@ -31,6 +31,11 @@ type AttributeSchema struct { // as an origin for another target (e.g. module inputs, // or tfvars entires in Terraform) OriginForTarget *PathTarget + + // SemanticTokenModifiers represents the semantic token modifiers + // to report for the attribute name + // (in addition to any modifiers of any parent blocks) + SemanticTokenModifiers lang.SemanticTokenModifiers } type AttributeAddrSchema struct { @@ -94,16 +99,17 @@ func (as *AttributeSchema) Copy() *AttributeSchema { } newAs := &AttributeSchema{ - IsRequired: as.IsRequired, - IsOptional: as.IsOptional, - IsDeprecated: as.IsDeprecated, - IsComputed: as.IsComputed, - IsSensitive: as.IsSensitive, - IsDepKey: as.IsDepKey, - Description: as.Description, - Expr: as.Expr.Copy(), - Address: as.Address.Copy(), - OriginForTarget: as.OriginForTarget.Copy(), + IsRequired: as.IsRequired, + IsOptional: as.IsOptional, + IsDeprecated: as.IsDeprecated, + IsComputed: as.IsComputed, + IsSensitive: as.IsSensitive, + IsDepKey: as.IsDepKey, + Description: as.Description, + Expr: as.Expr.Copy(), + Address: as.Address.Copy(), + OriginForTarget: as.OriginForTarget.Copy(), + SemanticTokenModifiers: as.SemanticTokenModifiers.Copy(), } return newAs