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

[Suggestion] Script-Based Theme Json generation #132

Open
sharpchen opened this issue Dec 11, 2024 · 2 comments
Open

[Suggestion] Script-Based Theme Json generation #132

sharpchen opened this issue Dec 11, 2024 · 2 comments

Comments

@sharpchen
Copy link
Contributor

sharpchen commented Dec 11, 2024

Overview

I suggest generate theme json by script for better maintainability and readability.

This might benefits:

  • Much more readable for reviewing PR.
  • More maintainable for contributors.
  • CI/CD
  • Better isolation for different languages.

Motivation

The current way to add or modify highlighting is really tedious, I'll have to find the correct position to append the highlight scope. And repeat the same operation for 7 other theme variants. This is just for the one scope, if one would like to add support for a new language, that would be overwhelming.

The idea was essentially inspired during when I implement the Eva-Theme.nvim which is a script-based implementation. And I do think it has a sufficient readability for its api, so I was thinking maybe we can do the same thing in the upstream.

Potential Problem

This new approach might bring some problems.

  • We might still want the old way to modify the json directly.
    A: We can store those old json files at somewhere like legacy/*.json and merge it with script-generated values into the new json. One can modify legacy/*.json in the old way.

  • What would happen when there's duplicated setting for a same scope from both legacy json and script?
    A: Honestly I don't know how does vscode handle this, if that matters we can throw an error when generating.

Implementation

I've done a prototype branch in typescript few days ago, and it should work fine at least for syntax highlighting(we can do it for ui colors too).

The example usage is can be:

highlight
  .map('function', 'storage.type.powershell') // map the scope as color of function
  .map('property', ['variable.other.member.powershell', 'storage.type.powershell']) // map for multiple scopes with a same setting
  .map('none', 'storage.type.powershell', (palette, _) => {
    return { fontStyle: 'bold', foreground: palette.typeparam }; // override by more complex setting
  });

Note

To generate, use npm run build.

This applies to all variants with just a single line for one or more scopes!

@fisheva
Copy link
Owner

fisheva commented Dec 17, 2024

I didn't understand your code (I know only a little typescript, ashamed...). But I understood your idea and requirements, so I wrote a simple program. Now, you can add/modify syntax and UI styles in jsonc files. The way to generate theme json files is git bash under the index folder, node index.js.

微信截图_20241217221718

@sharpchen
Copy link
Contributor Author

Well it's ok for not having much knowledge about typescript, I use it just for more informative intellisense, nothing else. However, I believe there are still some gaps in your current solution that need to be addressed to resolve the inconvenience.

  • hard-coded colors are still required.
  • doesn't handle font style automatically. (I didn't come with a smarter solution though)
  • still have to repeat for variants.

Anyway, it's merely a draft proposal, so there's no rush to reach a conclusion. I understand you're developing for JetBrains IDEs; I'm not certain how JetBrains manages highlighting, but if they also use static configuration files, maintaining two repositories could be challenging. Hopefully, this proposal will serve as some inspiration. If you have any additional worries or insights, please don't hesitate to share. :)

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

No branches or pull requests

2 participants