Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First-class custom themes #270

Open
wadetregaskis opened this issue Nov 21, 2023 · 6 comments
Open

First-class custom themes #270

wadetregaskis opened this issue Nov 21, 2023 · 6 comments

Comments

@wadetregaskis
Copy link

wadetregaskis commented Nov 21, 2023

The theme customisation is pretty useless for me as it stands because it cripples the syntax analysis, at least for languages like Swift. e.g. it then confuses numeric literals and type names, can't understand macro and property wrapper arguments at all (they default back to plain text), no longer distinguishes argument labels from their values, doesn't recognise property references, etc.

With at least some of the built-in themes, the syntax analysis is far more powerful (much better than other engines I've tried, including Prism.js, Highlight.js, Enlighter, etc). But I can't really do anything useful with them re. CSS customisation because the individual elements (spans) don't have any distinguishing classes (or attributes otherwise).

Thus there doesn't appear to be any way to define a 'proper' custom theme, one that has access to the full syntax grammar.

@KevinBatdorf
Copy link
Owner

Yeah it's quite limited. One option would be to forcefully override the styles. Find a theme that tokenizes in a way you like, then target it by the actual color:

span[style*="#96E072"] {
  color:red !important;
}

I'm not sure when I'll have a better solution, so that's probably the best option at the moment.

@wadetregaskis
Copy link
Author

Having looked more into the underpinnings (Shiki etc), I think what I actually want is simply the ability to use an existing VS Code theme that doesn't happen to be one of the ones built in to the plug-in. e.g. https://github.com/vbaswin/Xcode14-VScode-Extension, or perhaps older variants like https://github.com/lunacookies/xcode-theme or https://github.com/smockle-archive/xcode-default-theme (I can't be sure which will actually work best without trying them - which I guess I could do by downloading VS Code etc…).

I did consider the approach you mentioned - I'd already been doing that a little bit to adjust fonts - but it seems inherently pretty fragile - I'd first have to find a theme which works well with Swift, from the shortlisted options, and has distinct colours for all the different types I need, and then hope that it never changes any of them.

Would it be possible to support using an arbitrary theme file? I did glance through the source code in case there were some obvious point I could hack in with PHP and add to the themes list, but nothing jumped out at me. I'm okay with something a little hacky - e.g. using functions.php - if that's what it takes.

@KevinBatdorf
Copy link
Owner

If you want to try them out and pick one I can add it to the add-on pack, which I believe you purchased already (based on your initial comment here). It wouldn't make sense to add all three, but if you decide on one then I can add it this week.

@wadetregaskis
Copy link
Author

Sure, that'd be awesome. Give me a day or two to test them all out in VS Code, and I'll report back here with the results.

@wadetregaskis
Copy link
Author

Sorry for the delay in following up. This led me down quite a rabbit-hole.

Upon testing pretty much every existing VS Code "Xcode" theme I could find (in the Marketplace), more than a dozen of them, I discovered that they're all pretty terrible. VS Code's underlying Swift support is a bit mediocre (at least, without bespoke extensions that probably aren't applicable to a WordPress plug-in like yours). Yet even so, most of the themes I tested don't even hit the grammar parser's limits because they're little more than existing themes - intended for JavaScript & CSS, predominately - very slightly modified. They cover some of the more obvious syntax elements, such that they look like they work at very first glance, but they crumble completely under any real scrutiny.

I spent several days working on a new theme to properly support Swift, but - while I did quickly get further than any existing themes - I eventually realised it was going to be a lot more work to finish it, let-alone to get it published into the VS Code Marketplace, and then support it indefinitely. Creating VS Code themes is laborious and error-prone, because of the complete lack of tooling and infrastructure to support it (i.e. there's no way to even know what the matchable grammar is, short of reverse-engineering the TextMate grammar files).

So, for now at least, I think there's nothing for you to do here. If you want to keep this bug open, I can keep an eye on developments in the relevant grammar and theme files, and can report here if there's any notable improvements. There is actually some work being done in that area as we speak, for the first time in years, so there is maybe still hope for this.

@KevinBatdorf
Copy link
Owner

That's surprising and unfortunate. It's interesting that people are still talking about it too. Yeah let's leave this issue open and check back on the issue you linked to to see if some progress has been made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants