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

TextMate color override #25

Closed bbatliner closed 5 years ago

bbatliner commented 5 years ago

I'm not sure what to call this, so let me explain. In certain cases (see #22), tree-sitter-cpp is unable to parse elements and the tree gets corrupted, as well as the resulting highlighting:

image

I'm wondering if it's possible to defer some of the highlighting to TextMate. A color customization rule like this correctly highlights the namespace keywords, but they get recolored, albeit incorrectly, by this extension:

{
    "scope": "storage.type.namespace",
    "settings": {
        "foreground": "#F92672",
        "fontStyle": ""
    }
},

I don't think this is possible given the nature of the extension (it applies after the TextMate highlighting), but I figured I'd ask.

EvgeniyPeshkov commented 5 years ago

Hello @bbatliner , I'm sorry for making you wait so long for an answer. I just needed some time to put thoughts in order. The reason why TextMate can deal with such cases is only because it's based on regex parsing. So here it simply captures word namespace and then everything is fine. But at the same time TextMate doesn't consider surrounding context and cannot deal with e.g. custom classes. On the other hand Tree-Sitter cannot deal with situation where part of syntax is embedded into macro. Speaking of deferring part of highlighting back to TextMate. First of all it will require the extension to provide some kind of stripped TextMate grammars for every language. And they will replace standard grammars provided by VSCode. This also implies keeping track of all the issues there and continuously providing bug-fixes and merges with upstream development. Moreover, it's a big question what parts might be left for TextMate. For example, in this issue the only reason is that part of syntax is hidden in the marco. In all other cases there's no need to skip parsing of namespace definitions by Tree-Sitter. Also inside the extension such syntax is parsed like function definition by Tree-Sitter. I really don't know why, maybe because of tricky recovery from bad parse branches. So inside the extension I have no tool to understand either this is a bad parsing and I should skip highlighting or everything is fine. For some time I was considering to implement fast highlighting mode, where only tricky parts of syntax, like identifiers of types or variables, are overridden by the extension, and the rest of TextMate colors are preserved, i.e. punctuation, operators, etc. Maybe I'll finally implement it in near future as an improvement. But unfortunately it doesn't resolve this issue. I'm very sorry.