EvgeniyPeshkov / syntax-highlighter

Syntax Highlighter extension for Visual Studio Code (VSCode). Based on Tree-sitter.
https://marketplace.visualstudio.com/items?itemName=evgeniypeshkov.syntax-highlighter
MIT License
210 stars 43 forks source link

[C++] Macro and namespace oddities #22

Closed bbatliner closed 5 years ago

bbatliner commented 5 years ago

When using macros to define namespaces, some weird things happen:

#define OPEN_BRACE namespace a {
#define CLOSE_BRACE }

OPEN_BRACE

namespace b { namespace c { namespace d {

CLOSE_BRACE // d
CLOSE_BRACE // c
} // b
} // a

image

The first namespace keyword is highlighted differently than the others. Additionally, the two macros at the end are highlighted differently. Do you know why?

Thanks for your work on this extension! It works the best of any I've tried so far.

EvgeniyPeshkov commented 5 years ago

Hello @bbatliner , welcome. Thank you for the feedback. {Syntax Highlighter} is based on Tree-sitter parser. Being just syntax parser, it doesn't track what's beneath macros, this is a task for a language server. So it doesn't expand them and cannot recover syntax tree if key terms like braces are embedded into the macro. In such cases syntax tree is corrupted from parser's point of view.

EvgeniyPeshkov commented 5 years ago

Hello @bbatliner , Don't you mind if we close this issue? I'm afraid, neither tree-sitter nor do I will be able to manage such cases.

bbatliner commented 5 years ago

Yeah, seems to be the case. I'll open a follow-up question in a different issue.