Prototype of getting active vscode theme in the extension#772
Prototype of getting active vscode theme in the extension#772
Conversation
Where this is currently at:
As was before, the code syntax highlighting in the Visual Editor simply does not match the Source Editor; Though this PR is an overall improvement in using the user's theme colors. Notable exception: the dark blue abyss theme looks very bad in the After. It should be possible to address this particular exception with some finessing, but I'm sure other custom themes would lead to other exceptions. How could we make the Visual Editor code block syntax highlighting actually match the Source Editor?To answer that, let me give some context: I have learned that
So, we would have to stop using Lezer. We may be able to replace Lezer with Shiki which seems to have support for VSCode themes. Another alternative: if we really care about consistency with the source editor, we could attempt to replace CodeMirror with Monaco. That scares me a bit, but should be do-able with some time and care. I talked to @softwarenerd and that is the approach that the Databot extension is using for this problem. What should I do from here?Options:
|
|
I know you put this as "hard" but I do think in the long term it might be the right call to use Monaco for the code cells. 😬 I am very open to landing something incremental and better now, based on your current work, but the consistency that using Monaco would give us would be HUGE. I know it's not super relevant to your work, but that would also mean it would be possible to be consistent across regular source editors, Databot, the Positron console, the new Positron notebook frontend (also Monaco), and more. |
The problem
As reported in #525, the visual editor does not use code highlighting colors from the user's vscode color theme.
The extension does get some colors from the theme, but it does not get any code highlighting related colors. I believe the extension includes its own code highlighting color themes for each of the default vscode themes. If the user is using a built-in vscode theme (e.g. Monokai, Solarized, etc.) then the extension is able to guess that and select a matching theme definition from its own list. However, if the user is not using a built-in vscode theme, the extension somehow picks one of the built-in themes to use as the code highlighting theme, which is not great.
You can see this maybe most glaringly with a monochrome theme from the extension store:
Can we get the user's theme colors?
Yes, to some extent at least. See the discussion on the vscode repo here.
This PR so far gives a prototype of getting and logging code highlighting theme data from the user's vscode theme. Here's an example of what we can get:
Here's an example of the data that is logged in this PR
Do the code colors we get from VSCode map to code colors for the Visual Editor?
No, not directly. Compare the keys in the code in the expandable section above with this code color theme type (from
packages/editor/src/editor/editor-theme.ts) for the Visual Editor:The keys do not directly correspond to eachother. That being said, we are getting quite a bit of data from the VSCode theme, I would think that we could manually come up with a reasonable mapping to this set of 16 colors for
CodeTheme.Open Questions