Thinking more about it, I think it should work like this:
// Scala parser, this is a scala file
val dependent =
// v search for a syntax highlighter for "html" / ".html" (no compilation need)
html"""
// HTML syntax highlighter
<button ...>
// `${` detected, switching back to Scala highlighter
${
if debug then "" else
// v search html syntax highlighter
html"
// HTML syntax highlighter
<MyDebug>
// `${` detected, switching back to Scala highlighter
${debugInfo}
// `}` detected, going back to previous highlighter (HTML)
</MyDebug>"
// end of string, going back to scala highlighter
}
// `}` detected, going back to previous highlighter (HTML)
</button>
"""
// end of string, going back to scala highlighter
Here is what would be given to the different highlighters (more or less):
scala:
val dependent = html"""dummy"""
html:
<button ...>
dummy
</button>
scala:
if debug then "" else html"dummy"
html:
<MyDebug>dummy</MyDebug>
scala:
debugInfo
Or potentially something like the following so the LSPs know where variables come from:
scala:
val dependent = html"""${if debug then "" else html"${debugInfo}"}"""
html:
<button ...>
<MyDebug>dummy</MyDebug>
</button>
This of course places limitations on what can be highlighted, the following would not (and should not ?) work:
val part1 = html"<bu"
val part2 = html"tton/>"
val sum = part1 + part2
In my mind this is a good thing, JSX-like libraries should not allow you to break the sub-language’s semantics (and to my knowledge JSX doesn’t)