Skip to content

Commit 77e9a22

Browse files
authored
Add check for a non-zero value for tab width (#7178)
1 parent 204bac1 commit 77e9a22

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

helix-core/src/syntax.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ where
4848
.transpose()
4949
}
5050

51+
fn deserialize_tab_width<'de, D>(deserializer: D) -> Result<usize, D::Error>
52+
where
53+
D: serde::Deserializer<'de>,
54+
{
55+
usize::deserialize(deserializer).and_then(|n| {
56+
if n > 0 && n <= 16 {
57+
Ok(n)
58+
} else {
59+
Err(serde::de::Error::custom(
60+
"tab width must be a value from 1 to 16 inclusive",
61+
))
62+
}
63+
})
64+
}
65+
5166
pub fn deserialize_auto_pairs<'de, D>(deserializer: D) -> Result<Option<AutoPairs>, D::Error>
5267
where
5368
D: serde::Deserializer<'de>,
@@ -424,6 +439,7 @@ pub struct DebuggerQuirks {
424439
#[derive(Debug, Serialize, Deserialize)]
425440
#[serde(rename_all = "kebab-case")]
426441
pub struct IndentationConfiguration {
442+
#[serde(deserialize_with = "deserialize_tab_width")]
427443
pub tab_width: usize,
428444
pub unit: String,
429445
}

0 commit comments

Comments
 (0)