theme_importer: Improve syntax token matching (#3549)

This PR improves the approach we use to match syntax tokens between Zed
and VS Code in the `theme_importer`.

We now use the list of scopes assigned to each Zed syntax token to rank
the possible candidates in the VS Code and then pick the candidate with
the highest rank.

So far this has proved to provide better colors across the board, but
we'll continue to refine the matching over time.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2023-12-07 22:11:31 -05:00 committed by GitHub
parent 89f62a1a69
commit f272881a6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 520 additions and 405 deletions

View file

@ -66,7 +66,7 @@ pub fn andromeda() -> UserThemeFamily {
( (
"attribute".into(), "attribute".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf39c12ff).into()), color: Some(rgba(0xffe66dff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -77,6 +77,13 @@ pub fn andromeda() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0xa0a1a7cc).into()),
..Default::default()
},
),
( (
"emphasis".into(), "emphasis".into(),
UserHighlightStyle { UserHighlightStyle {
@ -143,7 +150,7 @@ pub fn andromeda() -> UserThemeFamily {
( (
"type".into(), "type".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffe66dff).into()), color: Some(rgba(0xee5d43ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -154,6 +161,13 @@ pub fn andromeda() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x00e8c6ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },
@ -210,7 +224,7 @@ pub fn andromeda() -> UserThemeFamily {
( (
"attribute".into(), "attribute".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf39c12ff).into()), color: Some(rgba(0xffe66dff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -221,6 +235,13 @@ pub fn andromeda() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0xa0a1a7cc).into()),
..Default::default()
},
),
( (
"emphasis".into(), "emphasis".into(),
UserHighlightStyle { UserHighlightStyle {
@ -287,7 +308,7 @@ pub fn andromeda() -> UserThemeFamily {
( (
"type".into(), "type".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffe66dff).into()), color: Some(rgba(0xee5d43ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -298,6 +319,13 @@ pub fn andromeda() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x00e8c6ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },

View file

@ -89,6 +89,14 @@ pub fn ayu() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x787b8099).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -122,14 +130,14 @@ pub fn ayu() -> UserThemeFamily {
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf2ae49ff).into()), color: Some(rgba(0xf07171ff).into()),
..Default::default() ..Default::default()
}, },
), ),
( (
"keyword".into(), "keyword".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xfa8d3eff).into()), color: Some(rgba(0x55b4d4ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -171,7 +179,7 @@ pub fn ayu() -> UserThemeFamily {
( (
"property".into(), "property".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf07171ff).into()), color: Some(rgba(0x55b4d4ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -269,7 +277,7 @@ pub fn ayu() -> UserThemeFamily {
( (
"variable.special".into(), "variable.special".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf07171ff).into()), color: Some(rgba(0xf2ae49ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -352,6 +360,14 @@ pub fn ayu() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0xb8cfe680).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -385,14 +401,14 @@ pub fn ayu() -> UserThemeFamily {
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffd173ff).into()), color: Some(rgba(0xf28779ff).into()),
..Default::default() ..Default::default()
}, },
), ),
( (
"keyword".into(), "keyword".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffad66ff).into()), color: Some(rgba(0x5ccfe6ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -434,7 +450,7 @@ pub fn ayu() -> UserThemeFamily {
( (
"property".into(), "property".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf28779ff).into()), color: Some(rgba(0x5ccfe6ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -532,7 +548,7 @@ pub fn ayu() -> UserThemeFamily {
( (
"variable.special".into(), "variable.special".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf28779ff).into()), color: Some(rgba(0xffd173ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -615,6 +631,14 @@ pub fn ayu() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0xacb6bf8c).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -648,14 +672,14 @@ pub fn ayu() -> UserThemeFamily {
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffb454ff).into()), color: Some(rgba(0xf07178ff).into()),
..Default::default() ..Default::default()
}, },
), ),
( (
"keyword".into(), "keyword".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xff8f40ff).into()), color: Some(rgba(0x39bae6ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -697,7 +721,7 @@ pub fn ayu() -> UserThemeFamily {
( (
"property".into(), "property".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf07178ff).into()), color: Some(rgba(0x39bae6ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -795,7 +819,7 @@ pub fn ayu() -> UserThemeFamily {
( (
"variable.special".into(), "variable.special".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xf07178ff).into()), color: Some(rgba(0xffb454ff).into()),
..Default::default() ..Default::default()
}, },
), ),

View file

@ -83,6 +83,13 @@ pub fn dracula() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x6272a4ff).into()),
..Default::default()
},
),
( (
"emphasis".into(), "emphasis".into(),
UserHighlightStyle { UserHighlightStyle {
@ -159,8 +166,7 @@ pub fn dracula() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xbd93f9ff).into()), color: Some(rgba(0xf8f8f2ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),

View file

@ -82,8 +82,9 @@ pub fn gruvbox() -> UserThemeFamily {
}, },
), ),
( (
"emphasis".into(), "comment.doc".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x928374ff).into()),
font_style: Some(UserFontStyle::Italic), font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
@ -148,7 +149,7 @@ pub fn gruvbox() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xa89984ff).into()), color: Some(rgba(0x83a598ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -201,6 +202,13 @@ pub fn gruvbox() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x83a598ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },
@ -273,8 +281,9 @@ pub fn gruvbox() -> UserThemeFamily {
}, },
), ),
( (
"emphasis".into(), "comment.doc".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x928374ff).into()),
font_style: Some(UserFontStyle::Italic), font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
@ -339,7 +348,7 @@ pub fn gruvbox() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xa89984ff).into()), color: Some(rgba(0x83a598ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -392,6 +401,13 @@ pub fn gruvbox() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x83a598ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },
@ -464,8 +480,9 @@ pub fn gruvbox() -> UserThemeFamily {
}, },
), ),
( (
"emphasis".into(), "comment.doc".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x928374ff).into()),
font_style: Some(UserFontStyle::Italic), font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
@ -530,7 +547,7 @@ pub fn gruvbox() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xa89984ff).into()), color: Some(rgba(0x83a598ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -583,6 +600,13 @@ pub fn gruvbox() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x83a598ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },
@ -655,8 +679,9 @@ pub fn gruvbox() -> UserThemeFamily {
}, },
), ),
( (
"emphasis".into(), "comment.doc".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x928374ff).into()),
font_style: Some(UserFontStyle::Italic), font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
@ -721,7 +746,7 @@ pub fn gruvbox() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x7c6f64ff).into()), color: Some(rgba(0x076678ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -774,6 +799,13 @@ pub fn gruvbox() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x076678ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },
@ -846,8 +878,9 @@ pub fn gruvbox() -> UserThemeFamily {
}, },
), ),
( (
"emphasis".into(), "comment.doc".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x928374ff).into()),
font_style: Some(UserFontStyle::Italic), font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
@ -912,7 +945,7 @@ pub fn gruvbox() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x7c6f64ff).into()), color: Some(rgba(0x076678ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -965,6 +998,13 @@ pub fn gruvbox() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x076678ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },
@ -1037,8 +1077,9 @@ pub fn gruvbox() -> UserThemeFamily {
}, },
), ),
( (
"emphasis".into(), "comment.doc".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x928374ff).into()),
font_style: Some(UserFontStyle::Italic), font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
@ -1103,7 +1144,7 @@ pub fn gruvbox() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x7c6f64ff).into()), color: Some(rgba(0x076678ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -1156,6 +1197,13 @@ pub fn gruvbox() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"variable.special".into(),
UserHighlightStyle {
color: Some(rgba(0x076678ff).into()),
..Default::default()
},
),
], ],
}), }),
}, },

View file

@ -90,6 +90,14 @@ pub fn night_owl() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x637777ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -100,8 +108,7 @@ pub fn night_owl() -> UserThemeFamily {
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xc792eaff).into()), color: Some(rgba(0x82aaffff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -137,8 +144,7 @@ pub fn night_owl() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xc792eaff).into()), color: Some(rgba(0x7fdbcaff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -180,7 +186,7 @@ pub fn night_owl() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xc5e478ff).into()), color: Some(rgba(0xd7dbe0ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -272,6 +278,14 @@ pub fn night_owl() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x989fb1ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -282,8 +296,7 @@ pub fn night_owl() -> UserThemeFamily {
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x994cc3ff).into()), color: Some(rgba(0x4876d6ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -320,7 +333,6 @@ pub fn night_owl() -> UserThemeFamily {
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x994cc3ff).into()), color: Some(rgba(0x994cc3ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -362,7 +374,7 @@ pub fn night_owl() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x4876d6ff).into()), color: Some(rgba(0x403f53ff).into()),
..Default::default() ..Default::default()
}, },
), ),

File diff suppressed because it is too large Load diff

View file

@ -90,16 +90,16 @@ pub fn nord() -> UserThemeFamily {
}, },
), ),
( (
"constant".into(), "comment.doc".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xebcb8bff).into()), color: Some(rgba(0x616e88ff).into()),
..Default::default() ..Default::default()
}, },
), ),
( (
"emphasis.strong".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
font_weight: Some(UserFontWeight(700.0)), color: Some(rgba(0xebcb8bff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -134,7 +134,7 @@ pub fn nord() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xeceff4ff).into()), color: Some(rgba(0x81a1c1ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -183,7 +183,7 @@ pub fn nord() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x81a1c1ff).into()), color: Some(rgba(0xd8dee9ff).into()),
..Default::default() ..Default::default()
}, },
), ),

View file

@ -89,6 +89,14 @@ pub fn palenight() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x697098ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -164,7 +172,7 @@ pub fn palenight() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xc792eaff).into()), color: Some(rgba(0x89ddffff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -206,7 +214,7 @@ pub fn palenight() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffcb6bff).into()), color: Some(rgba(0xff5572ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -296,6 +304,14 @@ pub fn palenight() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x697098ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -371,7 +387,7 @@ pub fn palenight() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xc792eaff).into()), color: Some(rgba(0x89ddffff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -413,7 +429,7 @@ pub fn palenight() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffcb6bff).into()), color: Some(rgba(0xff5572ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -503,6 +519,14 @@ pub fn palenight() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x697098ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -578,7 +602,7 @@ pub fn palenight() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xc792eaff).into()), color: Some(rgba(0x89ddffff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -620,7 +644,7 @@ pub fn palenight() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xffcb6bff).into()), color: Some(rgba(0xff5572ff).into()),
..Default::default() ..Default::default()
}, },
), ),

View file

@ -91,11 +91,18 @@ pub fn rose_pine() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x6e6a86ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xeb6f92ff).into()), color: Some(rgba(0xe0def4ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -123,7 +130,7 @@ pub fn rose_pine() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x908caaff).into()), color: Some(rgba(0x6e6a86ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -165,8 +172,7 @@ pub fn rose_pine() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xebbcbaff).into()), color: Some(rgba(0xc4a7e7ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -258,11 +264,18 @@ pub fn rose_pine() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x6e6a86ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xeb6f92ff).into()), color: Some(rgba(0xe0def4ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -290,7 +303,7 @@ pub fn rose_pine() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x908caaff).into()), color: Some(rgba(0x6e6a86ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -332,8 +345,7 @@ pub fn rose_pine() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xea9a97ff).into()), color: Some(rgba(0xc4a7e7ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -425,11 +437,18 @@ pub fn rose_pine() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x9893a5ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xb4637aff).into()), color: Some(rgba(0x575279ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),
@ -457,7 +476,7 @@ pub fn rose_pine() -> UserThemeFamily {
( (
"punctuation".into(), "punctuation".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x797593ff).into()), color: Some(rgba(0x9893a5ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -499,8 +518,7 @@ pub fn rose_pine() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xd7827eff).into()), color: Some(rgba(0x907aa9ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default() ..Default::default()
}, },
), ),

View file

@ -86,6 +86,14 @@ pub fn solarized() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x657b83ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -117,14 +125,14 @@ pub fn solarized() -> UserThemeFamily {
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x268bd2ff).into()), color: Some(rgba(0x839496ff).into()),
..Default::default() ..Default::default()
}, },
), ),
( (
"keyword".into(), "keyword".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x859900ff).into()), color: Some(rgba(0x268bd2ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -180,14 +188,14 @@ pub fn solarized() -> UserThemeFamily {
( (
"type".into(), "type".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xcb4b16ff).into()), color: Some(rgba(0x859900ff).into()),
..Default::default() ..Default::default()
}, },
), ),
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x268bd2ff).into()), color: Some(rgba(0x839496ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -271,6 +279,14 @@ pub fn solarized() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x93a1a1ff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"constant".into(), "constant".into(),
UserHighlightStyle { UserHighlightStyle {
@ -302,14 +318,14 @@ pub fn solarized() -> UserThemeFamily {
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x268bd2ff).into()), color: Some(rgba(0x657b83ff).into()),
..Default::default() ..Default::default()
}, },
), ),
( (
"keyword".into(), "keyword".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x859900ff).into()), color: Some(rgba(0x268bd2ff).into()),
..Default::default() ..Default::default()
}, },
), ),
@ -358,7 +374,7 @@ pub fn solarized() -> UserThemeFamily {
( (
"type".into(), "type".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0x268bd2ff).into()), color: Some(rgba(0x859900ff).into()),
..Default::default() ..Default::default()
}, },
), ),

View file

@ -75,6 +75,14 @@ pub fn synthwave_84() -> UserThemeFamily {
..Default::default() ..Default::default()
}, },
), ),
(
"comment.doc".into(),
UserHighlightStyle {
color: Some(rgba(0x848bbdff).into()),
font_style: Some(UserFontStyle::Italic),
..Default::default()
},
),
( (
"function".into(), "function".into(),
UserHighlightStyle { UserHighlightStyle {
@ -162,7 +170,8 @@ pub fn synthwave_84() -> UserThemeFamily {
( (
"variable".into(), "variable".into(),
UserHighlightStyle { UserHighlightStyle {
color: Some(rgba(0xff7edbff).into()), color: Some(rgba(0xfe4450ff).into()),
font_weight: Some(UserFontWeight(700.0)),
..Default::default() ..Default::default()
}, },
), ),

View file

@ -15,7 +15,7 @@ use gpui::serde_json;
use json_comments::StripComments; use json_comments::StripComments;
use log::LevelFilter; use log::LevelFilter;
use serde::Deserialize; use serde::Deserialize;
use simplelog::SimpleLogger; use simplelog::{TermLogger, TerminalMode};
use theme::{Appearance, UserThemeFamily}; use theme::{Appearance, UserThemeFamily};
use crate::theme_printer::UserThemeFamilyPrinter; use crate::theme_printer::UserThemeFamilyPrinter;
@ -56,9 +56,17 @@ fn main() -> Result<()> {
const SOURCE_PATH: &str = "assets/themes/src/vscode"; const SOURCE_PATH: &str = "assets/themes/src/vscode";
const OUT_PATH: &str = "crates/theme2/src/themes"; const OUT_PATH: &str = "crates/theme2/src/themes";
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger"); let log_config = simplelog::ConfigBuilder::new()
.set_level_color(log::Level::Trace, simplelog::Color::Cyan)
.set_level_color(log::Level::Info, simplelog::Color::Blue)
.set_level_color(log::Level::Warn, simplelog::Color::Yellow)
.set_level_color(log::Level::Error, simplelog::Color::Red)
.build();
println!("Loading themes source..."); TermLogger::init(LevelFilter::Trace, log_config, TerminalMode::Mixed)
.expect("could not initialize logger");
log::info!("Loading themes source...");
let vscode_themes_path = PathBuf::from_str(SOURCE_PATH)?; let vscode_themes_path = PathBuf::from_str(SOURCE_PATH)?;
if !vscode_themes_path.exists() { if !vscode_themes_path.exists() {
return Err(anyhow!(format!( return Err(anyhow!(format!(
@ -91,7 +99,7 @@ fn main() -> Result<()> {
let license_file_path = theme_family_dir.path().join("LICENSE"); let license_file_path = theme_family_dir.path().join("LICENSE");
if !license_file_path.exists() { if !license_file_path.exists() {
println!("Skipping theme family '{}' because it does not have a LICENSE file. This theme will only be imported once a LICENSE file is provided.", theme_family_slug); log::info!("Skipping theme family '{}' because it does not have a LICENSE file. This theme will only be imported once a LICENSE file is provided.", theme_family_slug);
continue; continue;
} }
@ -103,12 +111,14 @@ fn main() -> Result<()> {
let mut themes = Vec::new(); let mut themes = Vec::new();
for theme_metadata in family_metadata.themes { for theme_metadata in family_metadata.themes {
log::info!("Converting '{}' theme", &theme_metadata.name);
let theme_file_path = theme_family_dir.path().join(&theme_metadata.file_name); let theme_file_path = theme_family_dir.path().join(&theme_metadata.file_name);
let theme_file = match File::open(&theme_file_path) { let theme_file = match File::open(&theme_file_path) {
Ok(file) => file, Ok(file) => file,
Err(_) => { Err(_) => {
println!("Failed to open file at path: {:?}", theme_file_path); log::info!("Failed to open file at path: {:?}", theme_file_path);
continue; continue;
} }
}; };
@ -136,7 +146,7 @@ fn main() -> Result<()> {
let themes_output_path = PathBuf::from_str(OUT_PATH)?; let themes_output_path = PathBuf::from_str(OUT_PATH)?;
if !themes_output_path.exists() { if !themes_output_path.exists() {
println!("Creating directory: {:?}", themes_output_path); log::info!("Creating directory: {:?}", themes_output_path);
fs::create_dir_all(&themes_output_path)?; fs::create_dir_all(&themes_output_path)?;
} }
@ -149,7 +159,7 @@ fn main() -> Result<()> {
let mut output_file = let mut output_file =
File::create(themes_output_path.join(format!("{theme_family_slug}.rs")))?; File::create(themes_output_path.join(format!("{theme_family_slug}.rs")))?;
println!( log::info!(
"Creating file: {:?}", "Creating file: {:?}",
themes_output_path.join(format!("{theme_family_slug}.rs")) themes_output_path.join(format!("{theme_family_slug}.rs"))
); );
@ -220,17 +230,17 @@ fn main() -> Result<()> {
mod_rs_file.write_all(mod_rs_contents.as_bytes())?; mod_rs_file.write_all(mod_rs_contents.as_bytes())?;
println!("Formatting themes..."); log::info!("Formatting themes...");
let format_result = format_themes_crate() let format_result = format_themes_crate()
// We need to format a second time to catch all of the formatting issues. // We need to format a second time to catch all of the formatting issues.
.and_then(|_| format_themes_crate()); .and_then(|_| format_themes_crate());
if let Err(err) = format_result { if let Err(err) = format_result {
eprintln!("Failed to format themes: {}", err); log::error!("Failed to format themes: {}", err);
} }
println!("Done!"); log::info!("Done!");
Ok(()) Ok(())
} }

View file

@ -275,20 +275,31 @@ impl VsCodeThemeConverter {
let mut highlight_styles = IndexMap::new(); let mut highlight_styles = IndexMap::new();
for syntax_token in ZedSyntaxToken::iter() { for syntax_token in ZedSyntaxToken::iter() {
let multimatch_scopes = syntax_token.to_vscode(); let best_match = syntax_token
.find_best_token_color_match(&self.theme.token_colors)
.or_else(|| {
syntax_token.fallbacks().iter().find_map(|fallback| {
fallback.find_best_token_color_match(&self.theme.token_colors)
})
});
let token_color = self.theme.token_colors.iter().find(|token_color| { let Some(token_color) = best_match else {
token_color log::warn!("No matching token color found for '{syntax_token}'");
.scope
.as_ref()
.map(|scope| scope.multimatch(&multimatch_scopes))
.unwrap_or(false)
});
let Some(token_color) = token_color else {
continue; continue;
}; };
log::info!(
"Matched '{syntax_token}' to '{}'",
token_color
.name
.clone()
.or_else(|| token_color
.scope
.as_ref()
.map(|scope| format!("{:?}", scope)))
.unwrap_or_else(|| "no identifier".to_string())
);
let highlight_style = UserHighlightStyle { let highlight_style = UserHighlightStyle {
color: token_color color: token_color
.settings .settings

View file

@ -1,3 +1,4 @@
use indexmap::IndexMap;
use serde::Deserialize; use serde::Deserialize;
use strum::EnumIter; use strum::EnumIter;
@ -8,19 +9,9 @@ pub enum VsCodeTokenScope {
Many(Vec<String>), 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)] #[derive(Debug, Deserialize)]
pub struct VsCodeTokenColor { pub struct VsCodeTokenColor {
pub name: Option<String>,
pub scope: Option<VsCodeTokenScope>, pub scope: Option<VsCodeTokenScope>,
pub settings: VsCodeTokenColorSettings, pub settings: VsCodeTokenColorSettings,
} }
@ -127,6 +118,60 @@ impl std::fmt::Display for ZedSyntaxToken {
} }
impl ZedSyntaxToken { impl ZedSyntaxToken {
pub fn find_best_token_color_match<'a>(
&self,
token_colors: &'a [VsCodeTokenColor],
) -> Option<&'a VsCodeTokenColor> {
let mut ranked_matches = IndexMap::new();
for (ix, token_color) in token_colors.iter().enumerate() {
if token_color.settings.foreground.is_none() {
continue;
}
let Some(rank) = self.rank_match(token_color) else {
continue;
};
if rank > 0 {
ranked_matches.insert(ix, rank);
}
}
ranked_matches
.into_iter()
.max_by_key(|(_, rank)| *rank)
.map(|(ix, _)| &token_colors[ix])
}
fn rank_match(&self, token_color: &VsCodeTokenColor) -> Option<u32> {
let candidate_scopes = match token_color.scope.as_ref()? {
VsCodeTokenScope::One(scope) => vec![scope],
VsCodeTokenScope::Many(scopes) => scopes.iter().collect(),
}
.iter()
.map(|scope| scope.as_str())
.collect::<Vec<_>>();
let mut matches = 0;
for scope in self.to_vscode() {
if candidate_scopes.contains(&scope) {
matches += 1;
}
}
Some(matches)
}
pub fn fallbacks(&self) -> &[Self] {
match self {
ZedSyntaxToken::CommentDoc => &[ZedSyntaxToken::Comment],
ZedSyntaxToken::VariableSpecial => &[ZedSyntaxToken::Variable],
_ => &[],
}
}
pub fn to_vscode(&self) -> Vec<&'static str> { pub fn to_vscode(&self) -> Vec<&'static str> {
match self { match self {
ZedSyntaxToken::Attribute => vec!["entity.other.attribute-name"], ZedSyntaxToken::Attribute => vec!["entity.other.attribute-name"],
@ -150,7 +195,15 @@ impl ZedSyntaxToken {
"variable.function", "variable.function",
"support.function", "support.function",
], ],
ZedSyntaxToken::Keyword => vec!["keyword"], ZedSyntaxToken::Hint => vec![],
ZedSyntaxToken::Keyword => vec![
"keyword",
"keyword.control",
"keyword.control.fun",
"keyword.other.fn.rust",
"punctuation.accessor",
"entity.name.tag",
],
ZedSyntaxToken::Label => vec![ ZedSyntaxToken::Label => vec![
"label", "label",
"entity.name", "entity.name",
@ -161,7 +214,9 @@ impl ZedSyntaxToken {
ZedSyntaxToken::LinkUri => vec!["markup.underline.link", "string.other.link"], ZedSyntaxToken::LinkUri => vec!["markup.underline.link", "string.other.link"],
ZedSyntaxToken::Number => vec!["constant.numeric", "number"], ZedSyntaxToken::Number => vec!["constant.numeric", "number"],
ZedSyntaxToken::Operator => vec!["operator", "keyword.operator"], ZedSyntaxToken::Operator => vec!["operator", "keyword.operator"],
ZedSyntaxToken::Predictive => vec![],
ZedSyntaxToken::Preproc => vec!["preproc"], ZedSyntaxToken::Preproc => vec!["preproc"],
ZedSyntaxToken::Primary => vec![],
ZedSyntaxToken::Property => vec![ ZedSyntaxToken::Property => vec![
"variable.member", "variable.member",
"support.type.property-name", "support.type.property-name",
@ -202,11 +257,20 @@ impl ZedSyntaxToken {
ZedSyntaxToken::Tag => vec!["tag", "entity.name.tag", "meta.tag.sgml"], ZedSyntaxToken::Tag => vec!["tag", "entity.name.tag", "meta.tag.sgml"],
ZedSyntaxToken::TextLiteral => vec!["text.literal", "string"], ZedSyntaxToken::TextLiteral => vec!["text.literal", "string"],
ZedSyntaxToken::Title => vec!["title", "entity.name"], ZedSyntaxToken::Title => vec!["title", "entity.name"],
ZedSyntaxToken::Type => vec!["entity.name.type", "support.type", "support.class"], ZedSyntaxToken::Type => vec![
"entity.name.type",
"entity.name.type.primitive",
"entity.name.type.numeric",
"keyword.type",
"support.type",
"support.type.primitive",
"support.class",
],
ZedSyntaxToken::Variable => vec![ ZedSyntaxToken::Variable => vec![
"variable", "variable",
"variable.language", "variable.language",
"variable.member", "variable.member",
"variable.parameter",
"variable.parameter.function-call", "variable.parameter.function-call",
], ],
ZedSyntaxToken::VariableSpecial => vec![ ZedSyntaxToken::VariableSpecial => vec![
@ -216,7 +280,6 @@ impl ZedSyntaxToken {
"variable.language", "variable.language",
], ],
ZedSyntaxToken::Variant => vec!["variant"], ZedSyntaxToken::Variant => vec!["variant"],
_ => vec![],
} }
} }
} }