I'm extending the bundled YAML language for a custom language. For this we use the concept of variables that are declared in one part of the file and which can be used in another:
- variableA <-- declaring element (YamlPlainTextImpl)
someOtherSegment: variableA <-- usage (YamlPlainTextImpl)
I can use the PsiReferenceContributor to create a reference on the usage element. However, to make use of things like find-usage and certain refactoring tools (rename, safe-delete), the declaring element should implement PsiNamedElement/PsiNameIdentifierOwner, if I'm not mistaken.
What would be the best approach to do this?
I currently have a very ugly workaround where I implement a ParserDefinition that extends the YamlParserDefinition with a 'first' priority that specifically checks for a SCALAR_PLAIN_VALUE node to be parsed, and then provides an instance of a custom extension of the YamlPlainTextImpl which does implement PsiNamedElement. This works but I'm trying to get rid of this workaround, so hopefully there is another solution, or you could implement PsiNamedElement on YamlPlainTextImpl also.