Extend theme converter to allow multimatching against vscode colors
This commit is contained in:
parent
31a6409a4c
commit
4cd37e6e62
14 changed files with 3926 additions and 879 deletions
|
@ -268,19 +268,15 @@ impl VsCodeThemeConverter {
|
|||
let mut highlight_styles = IndexMap::new();
|
||||
|
||||
for syntax_token in ZedSyntaxToken::iter() {
|
||||
let vscode_scope = syntax_token.to_vscode();
|
||||
let multimatch_scopes = syntax_token.to_vscode();
|
||||
|
||||
let token_color = self
|
||||
.theme
|
||||
.token_colors
|
||||
.iter()
|
||||
.find(|token_color| match token_color.scope {
|
||||
Some(VsCodeTokenScope::One(ref scope)) => scope == vscode_scope,
|
||||
Some(VsCodeTokenScope::Many(ref scopes)) => {
|
||||
scopes.contains(&vscode_scope.to_string())
|
||||
}
|
||||
None => false,
|
||||
});
|
||||
let token_color = self.theme.token_colors.iter().find(|token_color| {
|
||||
token_color
|
||||
.scope
|
||||
.as_ref()
|
||||
.map(|scope| scope.multimatch(&multimatch_scopes))
|
||||
.unwrap_or(false)
|
||||
});
|
||||
|
||||
let Some(token_color) = token_color else {
|
||||
continue;
|
||||
|
|
|
@ -8,6 +8,17 @@ pub enum VsCodeTokenScope {
|
|||
Many(Vec<String>),
|
||||
}
|
||||
|
||||
impl VsCodeTokenScope {
|
||||
pub fn multimatch(&self, matches: &[&'static str]) -> bool {
|
||||
match self {
|
||||
VsCodeTokenScope::One(scope) => matches.iter().any(|&s| s == scope),
|
||||
VsCodeTokenScope::Many(scopes) => {
|
||||
matches.iter().any(|s| scopes.contains(&s.to_string()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct VsCodeTokenColor {
|
||||
pub scope: Option<VsCodeTokenScope>,
|
||||
|
@ -118,49 +129,90 @@ impl std::fmt::Display for ZedSyntaxToken {
|
|||
}
|
||||
|
||||
impl ZedSyntaxToken {
|
||||
pub fn to_vscode(&self) -> &'static str {
|
||||
pub fn to_vscode(&self) -> Vec<&'static str> {
|
||||
use ZedSyntaxToken::*;
|
||||
|
||||
match self {
|
||||
SyntaxAttribute => "entity.other.attribute-name",
|
||||
SyntaxBoolean => "constant.language",
|
||||
SyntaxComment => "comment",
|
||||
SyntaxCommentDoc => "comment.block.documentation",
|
||||
SyntaxConstant => "constant.character",
|
||||
SyntaxConstructor => "entity.name.function.definition.special.constructor",
|
||||
SyntaxEmbedded => "embedded",
|
||||
SyntaxEmphasis => "emphasis",
|
||||
SyntaxEmphasisStrong => "emphasis.strong",
|
||||
SyntaxEnum => "support.type.enum",
|
||||
SyntaxFunction => "entity.name.function",
|
||||
SyntaxHint => "hint",
|
||||
SyntaxKeyword => "keyword",
|
||||
SyntaxLabel => "label",
|
||||
SyntaxLinkText => "link_text",
|
||||
SyntaxLinkUri => "link_uri",
|
||||
SyntaxNumber => "number",
|
||||
SyntaxOperator => "operator",
|
||||
SyntaxPredictive => "predictive",
|
||||
SyntaxPreproc => "preproc",
|
||||
SyntaxPrimary => "primary",
|
||||
SyntaxProperty => "variable.object.property", //"variable.other.field"
|
||||
SyntaxPunctuation => "punctuation",
|
||||
SyntaxPunctuationBracket => "punctuation.bracket",
|
||||
SyntaxPunctuationDelimiter => "punctuation.delimiter",
|
||||
SyntaxPunctuationListMarker => "punctuation.list_marker",
|
||||
SyntaxPunctuationSpecial => "punctuation.special",
|
||||
SyntaxString => "string",
|
||||
SyntaxStringEscape => "string.escape",
|
||||
SyntaxStringRegex => "string.regex",
|
||||
SyntaxStringSpecial => "string.special",
|
||||
SyntaxStringSpecialSymbol => "string.special.symbol",
|
||||
SyntaxTag => "tag",
|
||||
SyntaxTextLiteral => "text.literal",
|
||||
SyntaxTitle => "title",
|
||||
SyntaxType => "entity.name.type",
|
||||
SyntaxVariable => "variable.language",
|
||||
SyntaxVariableSpecial => "variable.special",
|
||||
SyntaxVariant => "variant",
|
||||
SyntaxAttribute => vec!["entity.other.attribute-name"],
|
||||
SyntaxBoolean => vec!["constant.language"],
|
||||
SyntaxComment => vec!["comment"],
|
||||
SyntaxCommentDoc => vec!["comment.block.documentation"],
|
||||
SyntaxConstant => vec!["constant.character"],
|
||||
SyntaxConstructor => vec!["entity.name.function.definition.special.constructor"],
|
||||
SyntaxEmbedded => vec!["meta.embedded"],
|
||||
SyntaxEmphasis => vec!["markup.italic"],
|
||||
SyntaxEmphasisStrong => vec![
|
||||
"markup.bold",
|
||||
"markup.italic markup.bold",
|
||||
"markup.bold markup.italic",
|
||||
],
|
||||
SyntaxEnum => vec!["support.type.enum"],
|
||||
SyntaxFunction => vec![
|
||||
"entity.name.function",
|
||||
"variable.function",
|
||||
"support.function",
|
||||
],
|
||||
SyntaxKeyword => vec!["keyword"],
|
||||
SyntaxLabel => vec![
|
||||
"label",
|
||||
"entity.name",
|
||||
"entity.name.import",
|
||||
"entity.name.package",
|
||||
],
|
||||
SyntaxLinkText => vec!["markup.underline.link", "string.other.link"],
|
||||
SyntaxLinkUri => vec!["markup.underline.link", "string.other.link"],
|
||||
SyntaxNumber => vec!["constant.numeric", "number"],
|
||||
SyntaxOperator => vec!["operator", "keyword.operator"],
|
||||
SyntaxPreproc => vec!["preproc"],
|
||||
SyntaxProperty => vec![
|
||||
"variable.member",
|
||||
"support.type.property-name",
|
||||
"variable.object.property",
|
||||
"variable.other.field",
|
||||
],
|
||||
SyntaxPunctuation => vec![
|
||||
"punctuation",
|
||||
"punctuation.section",
|
||||
"punctuation.accessor",
|
||||
"punctuation.separator",
|
||||
"punctuation.terminator",
|
||||
"punctuation.definition.tag",
|
||||
],
|
||||
SyntaxPunctuationBracket => vec![
|
||||
"punctuation.bracket",
|
||||
"punctuation.definition.tag.begin",
|
||||
"punctuation.definition.tag.end",
|
||||
],
|
||||
SyntaxPunctuationDelimiter => vec![
|
||||
"punctuation.delimiter",
|
||||
"punctuation.separator",
|
||||
"punctuation.terminator",
|
||||
],
|
||||
SyntaxPunctuationListMarker => vec!["markup.list punctuation.definition.list.begin"],
|
||||
SyntaxPunctuationSpecial => vec!["punctuation.special"],
|
||||
SyntaxString => vec!["string"],
|
||||
SyntaxStringEscape => vec!["string.escape", "constant.character", "constant.other"],
|
||||
SyntaxStringRegex => vec!["string.regex"],
|
||||
SyntaxStringSpecial => vec!["string.special", "constant.other.symbol"],
|
||||
SyntaxStringSpecialSymbol => vec!["string.special.symbol", "constant.other.symbol"],
|
||||
SyntaxTag => vec!["tag", "entity.name.tag", "meta.tag.sgml"],
|
||||
SyntaxTextLiteral => vec!["text.literal", "string"],
|
||||
SyntaxTitle => vec!["title", "entity.name"],
|
||||
SyntaxType => vec!["entity.name.type", "support.type", "support.class"],
|
||||
SyntaxVariable => vec![
|
||||
"variable",
|
||||
"variable.language",
|
||||
"variable.member",
|
||||
"variable.parameter.function-call",
|
||||
],
|
||||
SyntaxVariableSpecial => vec![
|
||||
"variable.special",
|
||||
"variable.member",
|
||||
"variable.annotation",
|
||||
"variable.language",
|
||||
],
|
||||
SyntaxVariant => vec!["variant"],
|
||||
_ => vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue