georgewfraser/vscode-tree-sitter

Use colors from color-scheme

gossi opened this issue · 8 comments

gossi commented

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?

It seems it's not possible:
#7 (comment)

gossi commented

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?

@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: microsoft/vscode#32813 (comment)

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

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 microsoft/vscode#32813 (comment)

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

gossi commented

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

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!

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

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.