JetBrains IDEs (IntelliJ, GoLand, etc) have a nifty feature called Language Injection that lets you get full language features when a language is embedded within another. For example, a SQL query within a string within a Go file.
A few of these come out of the box, but they are pretty limited -- I only had some XML ones prior to enabling the Databases plugin which added a few SQL ones. Fortunately, there is the ability to add custom ones. Unfortunately, this is expressed in a proprietary language with, as far as I can tell, zero documentation.
Despite this, I was able to get something working to build an injection for Kubernetes YAML templates. I commonly use these as inputs to tests, as Go strings, so having full IDE support is a huge win. This enables not only syntax highlighting, but also plugin support, giving Kubernetes validations.
I chose to inject YAML for any string that has the classic apiVersion:
string in it, since I am mostly targeting Kubernetes usage.
To do this, you can import the following under Editor > Language Injections
:
<LanguageInjectionConfiguration>
<injection language="yaml" injector-id="go">
<display-name>YAML</display-name>
<single-file value="true" />
<place><![CDATA[goStringLiteralThatMatches("(.*\n)?apiVersion: .*")]]></place>
</injection>
</LanguageInjectionConfiguration>