Skip to content

Commit

Permalink
Add check for a non-zero value for tab width (#7178)
Browse files Browse the repository at this point in the history
  • Loading branch information
bo1led-owl committed Jun 7, 2023
1 parent 204bac1 commit 77e9a22
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 77e9a22

Please sign in to comment.