Skip to content

Support return types for yaml.customTags#1255

Merged
datho7561 merged 1 commit into
redhat-developer:mainfrom
shin19991207:fix-867
May 19, 2026
Merged

Support return types for yaml.customTags#1255
datho7561 merged 1 commit into
redhat-developer:mainfrom
shin19991207:fix-867

Conversation

@shin19991207
Copy link
Copy Markdown
Member

What does this PR do?

This PR adds optional return types to the yaml.customTags setting.

Previously, a custom tag could only describe the YAML node type the tag is written on. For example, "!Seq-example sequence" tells the parser that !Seq-example would map to a sequence custom tag, but schema validation still treats the tagged value as a sequence.

This PR adds a new form "!Tag nodeType:returnType", where nodeType specifies the YAML node type that the tag is written on, and returnType specifies the schema type that the tagged value evaluates to.

yaml.customTags now supports three forms:

!Tag
!Tag nodeType
!Tag nodeType:returnType

Existing configurations remain supported, so this is backward compatible. Behavior only changes when a user explicitly adds :returnType.

What issues does this PR fix or reference?

Fixes redhat-developer/vscode-yaml#867

Note that yaml.customTags only applies to YAML short-form tags. It does not apply to CloudFormation long form such as Fn::.... Long form values are normal YAML mappings, not YAML tags.

Is it tested? How?

  • New automated tests
  • Manual testing:
  1. Add the following yaml.customTags configuration in workspace setting (a list of all intrinsic functions in short form with return types added, based on the AWS CloudFormation intrinsic function docs):
{
  "yaml.customTags": [
    "!Base64 scalar:string",
    "!Cidr sequence:array",
    "!And sequence:boolean",
    "!Equals sequence:boolean",
    "!If sequence",
    "!Not sequence:boolean",
    "!Or sequence:boolean",
    "!Condition scalar:boolean",
    "!FindInMap sequence:string",
    "!GetAtt scalar:string",
    "!GetAtt sequence:string",
    "!GetAZs scalar:array",
    "!ImportValue scalar:string",
    "!Join sequence:string",
    "!Select sequence:string",
    "!Split sequence:array",
    "!Sub scalar:string",
    "!Sub sequence:string",
    "!Transform mapping",
    "!Ref scalar:string"
  ]
}
  1. Create a file named template.yaml with the following content:
Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      # example of short-form tag with block sequence input
      AvailabilityZone: !GetAtt
        - Ec2SecurityGroup
        - GroupId

      # example of short-form tag with flow sequence input
      ImageId: !FindInMap [AWSRegionArch2AMI, !Ref "AWS::Region", HVM64]

      # example of short-form tag with scalar input
      InstanceType: !Ref InstanceType

      SecurityGroupIds:
        # example of short-form tag inside an array item
        - !GetAtt
          - Ec2SecurityGroup
          - GroupId
  1. Expect no errors.

Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Copy link
Copy Markdown
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

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

Looks good, works well and seems really helpful. Thanks, Morgan!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants