Using OuterLanguageRangePatcher for the higlighting lexer

I have an extension of the HTML templating language I’m where I’m using an extension of TemplateDataElementType along with a OuterLanguageRangePatcher to properly parse the (HTML) contents of my template file. An example snippet would be:

<p class={@class}>

where {@class} would be an outer language element type. By default, this is stripped out of the HTML leaving us with invalid HTML <p class=>, which causes invalid parsing if any attributes follow. Using the OuterLanguageRangePatcher, I insert dummy data into the template for the lexer to properly parse it.

All that to say, I’ve got it working for the template parsing, but I cannot reuse the same solution for my highlighting, because the highlighter doesn’t use TemplateDataElementType and I’m not sure how to get my OuterLanguageRangePatcher working for my HTML lexer.

The PR I’m working on is here: Add language support for HEEx by mwnciau · Pull Request #3696 · KronicDeth/intellij-elixir · GitHub

A problematic snippet would be:

<.form for={@form} method="POST" action={~p"/auth"}>

which parses fine, but looks like this because the lexer doesn’t use OuterLanguageRangePatcher (and there are few examples of this being used at all):

image

Note the method="POST" is all in green because the highlighting lexer thinks it’s all part of the for attribute.