diff options
author | Ilya Sovtsov | 2023-06-07 08:51:29 +0000 |
---|---|---|
committer | GitHub | 2023-06-07 08:51:29 +0000 |
commit | 77e9a22aff13a12cb17d67dbd1bc47aa5d5072f4 (patch) | |
tree | 0f790cbf2dfac5b74ab220cb107c6e1a43623339 /helix-core/src/syntax.rs | |
parent | 204bac1706badaf562304b67a4beb63102560e40 (diff) |
Add check for a non-zero value for tab width (#7178)
Diffstat (limited to 'helix-core/src/syntax.rs')
-rw-r--r-- | helix-core/src/syntax.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index c2dd3310..2a5bb974 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -48,6 +48,21 @@ where .transpose() } +fn deserialize_tab_width<'de, D>(deserializer: D) -> Result<usize, D::Error> +where + D: serde::Deserializer<'de>, +{ + usize::deserialize(deserializer).and_then(|n| { + if n > 0 && n <= 16 { + Ok(n) + } else { + Err(serde::de::Error::custom( + "tab width must be a value from 1 to 16 inclusive", + )) + } + }) +} + pub fn deserialize_auto_pairs<'de, D>(deserializer: D) -> Result<Option<AutoPairs>, D::Error> where D: serde::Deserializer<'de>, @@ -424,6 +439,7 @@ pub struct DebuggerQuirks { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct IndentationConfiguration { + #[serde(deserialize_with = "deserialize_tab_width")] pub tab_width: usize, pub unit: String, } |