Add support for theme family-specific syntax mapping overrides (#3551)

This PR adds support for adding a specific set of mappings from Zed
syntax tokens to VS Code scopes for a particular theme family.

We can use this as a fallback when we aren't otherwise able to rely on
the mappings in the theme importer, as sometimes it isn't possible to
make a specific enough matcher that works across all of the themes.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-12-07 23:37:49 -05:00 committed by GitHub
parent 5b96ffbbd1
commit 7a9f764aa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 11 deletions

View file

@ -12,6 +12,7 @@ use std::str::FromStr;
use anyhow::{anyhow, Context, Result};
use convert_case::{Case, Casing};
use gpui::serde_json;
use indexmap::IndexMap;
use json_comments::StripComments;
use log::LevelFilter;
use serde::Deserialize;
@ -27,6 +28,14 @@ struct FamilyMetadata {
pub name: String,
pub author: String,
pub themes: Vec<ThemeMetadata>,
/// Overrides for specific syntax tokens.
///
/// Use this to ensure certain Zed syntax tokens are matched
/// to an exact set of scopes when it is not otherwise possible
/// to rely on the default mappings in the theme importer.
#[serde(default)]
pub syntax: IndexMap<String, Vec<String>>,
}
#[derive(Debug, Clone, Copy, Deserialize)]
@ -127,7 +136,11 @@ fn main() -> Result<()> {
let vscode_theme: VsCodeTheme = serde_json::from_reader(theme_without_comments)
.context(format!("failed to parse theme {theme_file_path:?}"))?;
let converter = VsCodeThemeConverter::new(vscode_theme, theme_metadata);
let converter = VsCodeThemeConverter::new(
vscode_theme,
theme_metadata,
family_metadata.syntax.clone(),
);
let theme = converter.convert()?;