Make highlighting more deterministic when themes are ambiguous

This commit is contained in:
Paul Gey 2025-04-03 21:49:28 +02:00 committed by Will Lillis
parent 92c5d3b8e2
commit b341073192

View file

@ -1,5 +1,5 @@
use std::{
collections::{HashMap, HashSet},
collections::HashSet,
fmt::Write,
fs,
io::{self, Write as _},
@ -12,6 +12,7 @@ use std::{
use ansi_colours::{ansi256_from_rgb, rgb_from_ansi256};
use anstyle::{Ansi256Color, AnsiColor, Color, Effects, RgbColor};
use anyhow::Result;
use indexmap::IndexMap;
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
use serde_json::{json, Value};
use tree_sitter_highlight::{HighlightConfiguration, HighlightEvent, Highlighter, HtmlRenderer};
@ -82,7 +83,7 @@ impl<'de> Deserialize<'de> for Theme {
{
let mut styles = Vec::new();
let mut highlight_names = Vec::new();
if let Ok(colors) = HashMap::<String, Value>::deserialize(deserializer) {
if let Ok(colors) = IndexMap::<String, Value>::deserialize(deserializer) {
highlight_names.reserve(colors.len());
styles.reserve(colors.len());
for (name, style_value) in colors {
@ -127,7 +128,7 @@ impl Serialize for Theme {
|| effects.contains(Effects::ITALIC)
|| effects.contains(Effects::UNDERLINE)
{
let mut style_json = HashMap::new();
let mut style_json = IndexMap::new();
if let Some(color) = color {
style_json.insert("color", color);
}