diff options
author | Philipp Mildenberger | 2023-03-19 22:37:41 +0000 |
---|---|---|
committer | Philipp Mildenberger | 2023-05-18 19:48:32 +0000 |
commit | 2eeac10755e6b88e3d5861dee7e2016a10c01c9f (patch) | |
tree | 81d338cb10f0718e3bbf280015ecf4a96dc460c7 /helix-core/src | |
parent | b1199c552be39eec8cb428310c8bb2a952454b04 (diff) |
Refactor doc language servers to a HashMap, and the config to use a Vec to retain order
Diffstat (limited to 'helix-core/src')
-rw-r--r-- | helix-core/src/syntax.rs | 34 |
1 files changed, 17 insertions, 17 deletions
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<String, LanguageServerFeatures>, + pub language_servers: Vec<LanguageServerFeatures>, #[serde(skip_serializing_if = "Option::is_none")] pub indent: Option<IndentationConfiguration>, @@ -282,19 +282,20 @@ enum LanguageServerFeatureConfiguration { #[derive(Debug, Default)] pub struct LanguageServerFeatures { + pub name: String, pub only: HashSet<LanguageServerFeature>, pub excluded: HashSet<LanguageServerFeature>, } 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<HashMap<String, LanguageServerFeatures>, D::Error> +) -> Result<Vec<LanguageServerFeatures>, 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<S>( - map: &HashMap<String, LanguageServerFeatures>, + map: &Vec<LanguageServerFeatures>, serializer: S, ) -> Result<S::Ok, S::Error> 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)?; |