summaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorGokul Soumya2022-03-15 08:04:22 +0000
committerGitHub2022-03-15 08:04:22 +0000
commit2b0835b295bbf57a171210be967e039a1bddf823 (patch)
treef9a61e0458d9015da85bacf1a1ad4e433b8db38c /helix-view/src
parent0902ede7b1d4c7edb8b039235456d552aaf44679 (diff)
Refactor :set to parse by deserializing values (#1799)
* Refactor :set to parse by deserializing values * Implement serialize for idle_timeout config
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/editor.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 0eb61308..adf0cdf3 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -38,7 +38,7 @@ use helix_core::{
use helix_core::{Position, Selection};
use helix_dap as dap;
-use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize};
+use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
fn deserialize_duration_millis<'de, D>(deserializer: D) -> Result<Duration, D::Error>
where
@@ -48,6 +48,18 @@ where
Ok(Duration::from_millis(millis))
}
+fn serialize_duration_millis<S>(duration: &Duration, serializer: S) -> Result<S::Ok, S::Error>
+where
+ S: Serializer,
+{
+ serializer.serialize_u64(
+ duration
+ .as_millis()
+ .try_into()
+ .map_err(|_| serde::ser::Error::custom("duration value overflowed u64"))?,
+ )
+}
+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct FilePickerConfig {
@@ -109,8 +121,12 @@ pub struct Config {
pub auto_pairs: AutoPairConfig,
/// Automatic auto-completion, automatically pop up without user trigger. Defaults to true.
pub auto_completion: bool,
- /// Time in milliseconds since last keypress before idle timers trigger. Used for autocompletion, set to 0 for instant. Defaults to 400ms.
- #[serde(skip_serializing, deserialize_with = "deserialize_duration_millis")]
+ /// Time in milliseconds since last keypress before idle timers trigger.
+ /// Used for autocompletion, set to 0 for instant. Defaults to 400ms.
+ #[serde(
+ serialize_with = "serialize_duration_millis",
+ deserialize_with = "deserialize_duration_millis"
+ )]
pub idle_timeout: Duration,
pub completion_trigger_len: u8,
/// Whether to display infoboxes. Defaults to true.