georgewfraser / vscode-tree-sitter

Accurate syntax coloring for VSCode using tree-sitter
MIT License
175 stars 25 forks source link

Use colors from color-scheme #10

Closed gossi closed 5 years ago

gossi commented 5 years ago

After installing it, I had a feeling it wasn't using the colors from my color-scheme but its own colors (or maybe it was colors from my scheme but used very differently than my scheme was using them)

Is there a way to better align those colors with those from the scheme?

Geobert commented 5 years ago

It seems it's not possible: https://github.com/georgewfraser/vscode-tree-sitter/issues/7#issuecomment-494467392

gossi commented 5 years ago

If I understand this correctly, then the theme must provide a color to treeSitter.*? Given the theme doesn't support it yet, can I do this on my own?

georgewfraser commented 5 years ago

@gossi Yes, you can add a user setting like:

    "workbench.colorCustomizations": {
        "treeSitter.field": "#ff0000"
    }

Unfortunately, there is currently no way to access syntax colors from an extension: https://github.com/microsoft/vscode/issues/32813#issuecomment-488572556

If VSCode adds an API to access syntax colors, I will drop the treeSitter.* system and just use the colors from the theme.

jeff-hykin commented 5 years ago

The only real fix I can think of is to find a general mapping of textmate scopes to tree-sitter scopes. Then create a converter program that can take any textmate theme and convert it to a tree-sitter theme. It will almost certainly not be a perfect conversion but it is at least doable, and if theme makers want to add support they can fix any inconsistencies.

Basically as a workaround, we can build up a folder of all the tree-sitter versions of themes. Then, at runtime, we can retrieve the name of the theme, find our tree-sitter version of it, and then use the tree-sitter version to provide the coloring.

If we could access the theme's json programmatically that would be even better, and we could generate a tree-sitter version dynamically. I didn't even know that was a potential option until I saw https://github.com/microsoft/vscode/issues/32813#issuecomment-495005152

I think this issue is going to need to be solved before there can be large adoption

gossi commented 5 years ago

@georgewfraser exactly what I was looking for. Thank you so much.

georgewfraser commented 5 years ago

So it turns out that while VSCode doesn't provide an API for syntax scope colors, it is possible to read the actual color themes off the disk. I was able to adapt some code from https://github.com/microsoft/vscode-cpptools/tree/coleng/Colorization , and now tree-sitter changes color with the theme!

jeff-hykin commented 5 years ago

That's awesome! How are you pulling the colors from the themes and matching them to tree-sitter-scopes?

georgewfraser commented 5 years ago

I read the color themes off the disk. It's a hack, but it's the same hack being used by the Microsoft folks working on the CPP plugin.