vscode-arm
vscode-arm copied to clipboard
Inline assembly comment in macro does not terminate at end of string
In my project I have a C header that defines a macro which allows for easier insertion of assembly comments (very specific use case, I know). However, after the @
symbol is inserted, it recognizes it as a line comment and the rest of the line (even after the quotation mark) is green. That would be mildly annoying by itself, but it actually breaks the entire rest of the file. I'm not sure exactly what's going on but it seems to make Code think that the entire rest of the file is meant to be in the macro, and makes absolutely everything blue.
Can be seen in this file, starting on line 14: https://github.com/pret/pokeemerald/blob/master/include/global.h
Hey - thanks for reporting this. That's a really weird bug! (I also had no idea that source.arm
was being automatically included in the built-in C syntax!) I've been trying to reproduce with ARM set as the language mode for the file you've provided (and with my own code) and haven't been able to bring out the same issue - but see it when C is set as the language mode (and my package is installed).
Could you report this on the main VSCode repository and reference this issue? (the file that's likely the cause is: https://github.com/microsoft/vscode/blob/master/extensions/cpp/syntaxes/c.tmLanguage.json)
I'm happy to work with the VSCode team to try and identify where the issue sits 😄
Yeah sorry, forgot to mention that it's triggering when the language mode is C and your extension is installed. So you're thinking this is actually an issue with the cpp extension from Microsoft?
Yeah, it looks to be. In a file with just ARM syntax in use, you can do :
”test @ test”
Without the same issue arising, so it may be to do with how their asm string patterns are working.
@Sierraffinity try installing this (the latest VS Code C syntax), let me know if that fixes the issue. https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-cpp-syntax
Also 🤔 I didn't know the Emerald source code was publicly available! @Sierraffinity
@jeff-hykin Yeah, myself and a bunch of other volunteers spent a few years reverse-engineering it to source!
Anyway, installing that extension does not change anything, unfortunately.
Wow that's really strange it didn't fix it. I would ask if you reloaded vs code but it should do that automatically. Something strange is going on with loading/applying the syntax likely something with extensions.
My guess is there's a asm syntax extension that's eating the "
causing it to miss the ending and overflow.
Can you do "Inspect TM Scopes" in the command pallet (Ctrl/CMD + P) and then click on some of that light blue text, and the quote where it first starts to overflow. (Post screenshots of those, or paste the list of scopes). That should get us more info.
I looked through some of the emerald code, and wow, feels weird to see the mechanics behind it. That's awesome you guys did that. I've always wanted to know how they did the interactions/priorities between moves (wrap, leech seed, some mons not being affected by leech seed, absorb, liquid ooze ability causing absorb to do damage back, etc) Looks like they just hardcoded all of it 😆 . It looks brutal to have to code something that big in C
Does the issue disappear when the arm extension is disabled? @Sierraffinity
The @ -- " x " -- ")
explains what's going on.
Arm thinks it's a comment, so it marks the rest of the line as a comment. However, that includes the quote. There's nothing* C++ can do to prevent arm from matching that.
This is a flaw in the Textmate parsing engine and embedded/nested languages. Myself and someone else worked on a workaround for this, called a bailout system. It's currently used in the LaTeX syntax and we use it for working around some preprocessor stuff in C++. It's not a good workaround though, it takes an entire grammar, duplicates it, then it injects a "bailout" into every pattern in the grammar. In this case the bailout pattern would be the double quote.
Sadly this is a lot of work to fix.
I see, and yeah, disabling the ARM extension makes the issue go away. So when you say it's a "lot of work to fix", does that mean from the C++ extension point of view or would it also be hard to fix from ARM?
Would a valid workaround be making the extension not highlight @
as a comment at all in .c/.h files? Would probably cause some other ugliness, but it'd fix the cascading issue of unterminated defines seen here. (And I don't want to have to toggle the extension whenever I start/stop editing asm in that repo.)
"lot of work to fix"
Is a lot because it's a really a problem with the engine.
It's probably more work that needs to be done on the C syntax, but basically we need to make a special version the ARM syntax that "knows" it's going to be inside of C strings, and "knows" to stop itself any time it sees a random "
Would a valid workaround be making the extension not highlight @ as a comment
not just inside comments but anything that might match a ".
So it's possible for me or @MandL27 to make that version of ARM using that bailout tool (or doing it manually). You could then switch to the ARM-that-knows-it-is-inside-c version and it should work without modifying the C syntax. But it would be best (just more work) for the C grammar to automatically import/use that version of ARM-that-knows-it-is-inside-c so that users don't have to manually switch. (However importing that version will basically require putting a copy of the entire ARM syntax inside of the C syntax)
C could also do a better job of finding the whole string first, trapping the ARM syntax (or any ASM syntax) inside the string, which would be a less hacky solution (no side effects) but would only fix the problem for strings that are on a single line, (if the string had \ and the end for multiline it would fail). This is something that should be done on the C syntax, but it adds more complexity and work.