From 2eeac10755e6b88e3d5861dee7e2016a10c01c9f Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sun, 19 Mar 2023 23:37:41 +0100 Subject: Refactor doc language servers to a HashMap, and the config to use a Vec to retain order --- helix-core/src/syntax.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'helix-core') diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index ce26a1bc..3fa7994d 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -112,11 +112,11 @@ pub struct LanguageConfiguration { // tags_config OnceCell<> https://github.com/tree-sitter/tree-sitter/pull/583 #[serde( default, - skip_serializing_if = "HashMap::is_empty", + skip_serializing_if = "Vec::is_empty", serialize_with = "serialize_lang_features", deserialize_with = "deserialize_lang_features" )] - pub language_servers: HashMap, + pub language_servers: Vec, #[serde(skip_serializing_if = "Option::is_none")] pub indent: Option, @@ -282,19 +282,20 @@ enum LanguageServerFeatureConfiguration { #[derive(Debug, Default)] pub struct LanguageServerFeatures { + pub name: String, pub only: HashSet, pub excluded: HashSet, } impl LanguageServerFeatures { pub fn has_feature(&self, feature: LanguageServerFeature) -> bool { - self.only.is_empty() || self.only.contains(&feature) && !self.excluded.contains(&feature) + (self.only.is_empty() || self.only.contains(&feature)) && !self.excluded.contains(&feature) } } fn deserialize_lang_features<'de, D>( deserializer: D, -) -> Result, D::Error> +) -> Result, D::Error> where D: serde::Deserializer<'de>, { @@ -302,40 +303,39 @@ where let res = raw .into_iter() .map(|config| match config { - LanguageServerFeatureConfiguration::Simple(name) => { - (name, LanguageServerFeatures::default()) - } + LanguageServerFeatureConfiguration::Simple(name) => LanguageServerFeatures { + name, + ..Default::default() + }, LanguageServerFeatureConfiguration::Features { only_features, except_features, name, - } => ( + } => LanguageServerFeatures { name, - LanguageServerFeatures { - only: only_features, - excluded: except_features, - }, - ), + only: only_features, + excluded: except_features, + }, }) .collect(); Ok(res) } fn serialize_lang_features( - map: &HashMap, + map: &Vec, serializer: S, ) -> Result where S: serde::Serializer, { let mut serializer = serializer.serialize_seq(Some(map.len()))?; - for (name, features) in map { + for features in map { let features = if features.only.is_empty() && features.excluded.is_empty() { - LanguageServerFeatureConfiguration::Simple(name.to_owned()) + LanguageServerFeatureConfiguration::Simple(features.name.to_owned()) } else { LanguageServerFeatureConfiguration::Features { only_features: features.only.clone(), except_features: features.excluded.clone(), - name: name.to_owned(), + name: features.name.to_owned(), } }; serializer.serialize_element(&features)?; -- cgit v1.2.3-70-g09d2