Ah, this made me want to try right away if i can match an incomplete tag without breaking the string parsing, and so far it works. The use case in the gif above used to break the syntax highlighting on my previous work, but I just fixed it by improving the grammar
XML strings can be matched if the strings starts (in its first line) with an opening tag.
There are some cases (for indentation mostly) where we want to start the xml on the next line. Then we need to be explicit and precede the string with @xml meta to treat the string as XML
String interpolation is mostly treated in the same way as haxe standard strings depending on the type of quotes we are using
Incomplete XML content in strings never breaks syntax highlighting of the rest of the file, but incomplete string interpolation does (just like normal haxe strings)
The idea of using an @xml meta before the string is to try to be as agnostic as possible, while using valid haxe syntax. Plus this meta could be used by frameworks in macro code
The jsx() call is handled because it is the default way to write jsx-like code in haxe-react and would make it much nicer for people using haxe-react with vscode. We could decide to remove this part and stick with a 100% agnostic solution, but I believe that would just create more friction to newcomers while non-haxe-react developers really probably don’t care if jsx() is triggering xml syntax highlighting.
Interested in your opinion on these, but all of the above works!
@back2dos The second rule is mostly a limitation because I didn’t find any way of matching the xml preceded with line breaks. I agree that it would be great if we could remove it, but didn’t find a way to do so yet. There are a bunch of things I want to try before saying it’s not possible though!
@alex_dja Go to definition from markup is out of the scope of my work here and I personally don’t plan to do anything about it, however go to definition works from ${identifier} and $identifier like in regular haxe strings.
In my latest proposal, I am skipping xml syntax coloring on double quoted strings to still give the option to developers to discard xml syntax coloring if they really don’t want it, just like they may use double quotes to skip haxe string literals as well. That could be a compromise which doesn’t require to hardcode any framework identifier?
Nothing stops a developer to use the syntax coloring to make snippets of XML code that could be integrated in a bigger XML content etc… making the snippet itself valid in the use case. I am not making any assumptions here, and it may not even be possible to skip the syntax coloring of xml depending on this rule anyway so…
If that was part of the official plugin, would there be a way (excepted using double quotes) to disable this behaviour (some people are really opinionated)? I’m fine with instructions to go manually patching the syntax file
@nadako do you think this is something we could get accepted?
I guess it’s always possible to patch the syntax file afterwards, even if that’s also a bit hacky.
In the same fashion, I guess it would also be possible to run a script to patch existing syntax file locally to add xml string parsing, but I’d rather have it integrated by default if most users are fine with it.
Yeah, I think we can accept this, if it’s not too invasive (ideally - a single “include” of a separate tmLanguage file), so we can remove it if/once vscode gets some way to patch/replace tmLanguages by an extension, and if you pledge to support it (replying to/fixing issues on github)
For now I opted for the option of putting everything xml-related at the end of the haxe syntax file, and insert a single include in the strings: part of haxe grammar. So, it’s in the same file but very easy to remove.
If you think using a separate grammar file (with its own scope name etc…) is better, then I can try that (but not sure about all the implications, in that case, do we need to declare a new grammar file in vshaxe’s package.json?)
This has already been discussed in various issues and on various occasions. The outcome is that VS Code won’t do anything special for embedded languages and that it’s the sole responsibility of the embedder, e.g. html must know that it embeds js and it must handle it.
In other words, if we do want to highlight XML syntax in Haxe, there are no other option than adding the syntax in Haxe grammar and VSCode doesn’t plan to change this anytime soon.
@nadako I will give a try to putting everything XML-related in a separate file included by Haxe grammar. If that works I will make a new PR with the result.
I think it should be possible if you’re do precise bookkeeping of generated expression positions. @back2dos might have more knowledge about that. If there are issues we can fix regarding it - please report