<NME> UnionTypeDeclaration.txt
<BEF> Elm File
  ElmTypeDeclaration(TYPE_DECLARATION)
    PsiElement(TYPE)('type')
    PsiWhiteSpace(' ')
    PsiElement(UPPER_CASE_IDENTIFIER)('Msg')
    PsiWhiteSpace('\n')
    PsiWhiteSpace('    ')
    PsiElement(EQ)('=')
    PsiWhiteSpace(' ')
    ElmUnionVariant(UNION_VARIANT)
      PsiElement(UPPER_CASE_IDENTIFIER)('Dismiss')
    PsiWhiteSpace('\n')
    PsiWhiteSpace('    ')
    PsiElement(PIPE)('|')
    PsiWhiteSpace(' ')
    ElmUnionVariant(UNION_VARIANT)
      PsiElement(UPPER_CASE_IDENTIFIER)('Show')
      PsiWhiteSpace(' ')
      ElmTupleType(TUPLE_TYPE)
        PsiElement(LEFT_PARENTHESIS)('(')
        ElmTypeExpression(TYPE_EXPRESSION)
          ElmTypeRef(TYPE_REF)
            ElmUpperCaseQID(UPPER_CASE_QID)
              PsiElement(UPPER_CASE_IDENTIFIER)('Int')
        PsiElement(COMMA)(',')
        PsiWhiteSpace(' ')
        ElmTypeExpression(TYPE_EXPRESSION)
          ElmTypeRef(TYPE_REF)
            ElmUpperCaseQID(UPPER_CASE_QID)
              PsiElement(UPPER_CASE_IDENTIFIER)('String')
        PsiElement(RIGHT_PARENTHESIS)(')')
  PsiElement(VIRTUAL_END_DECL)('\n')
  PsiWhiteSpace('\n')
  ElmTypeDeclaration(TYPE_DECLARATION)
    PsiElement(TYPE)('type')
    PsiWhiteSpace(' ')
    PsiElement(UPPER_CASE_IDENTIFIER)('Configurator')
    PsiWhiteSpace(' ')
    ElmLowerTypeName(LOWER_TYPE_NAME)
      PsiElement(LOWER_CASE_IDENTIFIER)('model')
    PsiWhiteSpace('\n')
    PsiWhiteSpace('    ')
    PsiElement(EQ)('=')
    PsiWhiteSpace(' ')
    ElmUnionVariant(UNION_VARIANT)
      PsiElement(UPPER_CASE_IDENTIFIER)('Init')
      PsiWhiteSpace(' ')
      PsiElement(LEFT_PARENTHESIS)('(')
      ElmTypeExpression(TYPE_EXPRESSION)
        ElmTupleType(TUPLE_TYPE)
          ElmUnitExpr(UNIT_EXPR)
            PsiElement(LEFT_PARENTHESIS)('(')
            PsiElement(RIGHT_PARENTHESIS)(')')
        PsiWhiteSpace(' ')
        PsiElement(ARROW)('->')
        PsiWhiteSpace(' ')
        ElmTypeVariableRef(TYPE_VARIABLE_REF)
          PsiElement(LOWER_CASE_IDENTIFIER)('model')
      PsiElement(RIGHT_PARENTHESIS)(')')
    PsiWhiteSpace('\n')
    PsiWhiteSpace('    ')
    PsiElement(PIPE)('|')
    PsiWhiteSpace(' ')
    ElmUnionVariant(UNION_VARIANT)
      PsiElement(UPPER_CASE_IDENTIFIER)('Apply')
      PsiWhiteSpace(' ')
      ElmTypeVariableRef(TYPE_VARIABLE_REF)
        PsiElement(LOWER_CASE_IDENTIFIER)('model')
      PsiWhiteSpace(' ')
      ElmTypeRef(TYPE_REF)
        ElmUpperCaseQID(UPPER_CASE_QID)
          PsiElement(UPPER_CASE_IDENTIFIER)('Int')
      PsiWhiteSpace(' ')
      PsiElement(LEFT_PARENTHESIS)('(')
      ElmTypeExpression(TYPE_EXPRESSION)
        ElmTypeVariableRef(TYPE_VARIABLE_REF)
          PsiElement(LOWER_CASE_IDENTIFIER)('model')
        PsiWhiteSpace(' ')
        PsiElement(ARROW)('->')
        PsiWhiteSpace(' ')
        ElmTypeRef(TYPE_REF)
          ElmUpperCaseQID(UPPER_CASE_QID)
            PsiElement(UPPER_CASE_IDENTIFIER)('Int')
        PsiWhiteSpace(' ')
        PsiElement(ARROW)('->')
        PsiWhiteSpace(' ')
        ElmTypeVariableRef(TYPE_VARIABLE_REF)
          PsiElement(LOWER_CASE_IDENTIFIER)('model')
      PsiElement(RIGHT_PARENTHESIS)(')')
    PsiWhiteSpace('\n')
    PsiWhiteSpace('    ')
    PsiElement(PIPE)('|')
    PsiWhiteSpace(' ')
    ElmUnionVariant(UNION_VARIANT)
      PsiElement(UPPER_CASE_IDENTIFIER)('Configure')
      PsiWhiteSpace(' ')
      ElmRecordType(RECORD_TYPE)
        PsiElement(LEFT_BRACE)('{')
        PsiWhiteSpace(' ')
        ElmFieldType(FIELD_TYPE)
          PsiElement(LOWER_CASE_IDENTIFIER)('foo')
          PsiElement(COLON)(':')
          PsiWhiteSpace(' ')
          ElmTypeExpression(TYPE_EXPRESSION)
            ElmTypeRef(TYPE_REF)
              ElmUpperCaseQID(UPPER_CASE_QID)
                PsiElement(UPPER_CASE_IDENTIFIER)('Bool')
        PsiElement(COMMA)(',')
        PsiWhiteSpace(' ')
        ElmFieldType(FIELD_TYPE)
          PsiElement(LOWER_CASE_IDENTIFIER)('bar')
          PsiElement(COLON)(':')
          PsiWhiteSpace(' ')
          ElmTypeExpression(TYPE_EXPRESSION)
            ElmTypeRef(TYPE_REF)
              ElmUpperCaseQID(UPPER_CASE_QID)
                PsiElement(UPPER_CASE_IDENTIFIER)('List')
              PsiWhiteSpace(' ')
              ElmTypeVariableRef(TYPE_VARIABLE_REF)
                PsiElement(LOWER_CASE_IDENTIFIER)('model')
        PsiWhiteSpace(' ')
        PsiElement(RIGHT_BRACE)('}')

<MSG> Add reference support for type variables in annotations (#380)

This allows you to rename type variables.

It's also necessary for tracking rigid type variables that reference parent annotations during inference. The fact that type annotations on nested functions can refer to variable in their parent functions was surprising to me. Here's an example of that: https://ellie-app.com/56HqfsFx2Z5a1

Note that the reference semantics for type variables aren't clear with respect to record base identifiers. I ended up treating them like any other type variable. The Elm compiler often crashes when you use them in type annotations.

I also renamed ElmTypeVariableRef to ElmTypeVariable and merged its anonymous reference implementation into TypeVariableReference, since they were almost identical.
<DFF> @@ -54,7 +54,7 @@ Elm File
         PsiWhiteSpace(' ')
         PsiElement(ARROW)('->')
         PsiWhiteSpace(' ')
-        ElmTypeVariableRef(TYPE_VARIABLE_REF)
+        ElmTypeVariable(TYPE_VARIABLE)
           PsiElement(LOWER_CASE_IDENTIFIER)('model')
       PsiElement(RIGHT_PARENTHESIS)(')')
     PsiWhiteSpace('\n')
@@ -64,7 +64,7 @@ Elm File
     ElmUnionVariant(UNION_VARIANT)
       PsiElement(UPPER_CASE_IDENTIFIER)('Apply')
       PsiWhiteSpace(' ')
-      ElmTypeVariableRef(TYPE_VARIABLE_REF)
+      ElmTypeVariable(TYPE_VARIABLE)
         PsiElement(LOWER_CASE_IDENTIFIER)('model')
       PsiWhiteSpace(' ')
       ElmTypeRef(TYPE_REF)
@@ -73,7 +73,7 @@ Elm File
       PsiWhiteSpace(' ')
       PsiElement(LEFT_PARENTHESIS)('(')
       ElmTypeExpression(TYPE_EXPRESSION)
-        ElmTypeVariableRef(TYPE_VARIABLE_REF)
+        ElmTypeVariable(TYPE_VARIABLE)
           PsiElement(LOWER_CASE_IDENTIFIER)('model')
         PsiWhiteSpace(' ')
         PsiElement(ARROW)('->')
@@ -84,7 +84,7 @@ Elm File
         PsiWhiteSpace(' ')
         PsiElement(ARROW)('->')
         PsiWhiteSpace(' ')
-        ElmTypeVariableRef(TYPE_VARIABLE_REF)
+        ElmTypeVariable(TYPE_VARIABLE)
           PsiElement(LOWER_CASE_IDENTIFIER)('model')
       PsiElement(RIGHT_PARENTHESIS)(')')
     PsiWhiteSpace('\n')
@@ -116,7 +116,7 @@ Elm File
               ElmUpperCaseQID(UPPER_CASE_QID)
                 PsiElement(UPPER_CASE_IDENTIFIER)('List')
               PsiWhiteSpace(' ')
-              ElmTypeVariableRef(TYPE_VARIABLE_REF)
+              ElmTypeVariable(TYPE_VARIABLE)
                 PsiElement(LOWER_CASE_IDENTIFIER)('model')
         PsiWhiteSpace(' ')
         PsiElement(RIGHT_BRACE)('}')

Add reference support for type variables in annotations (#380)