Add DelayMs type for settings (#40659)
Closes #40610 Release Notes: - N/A
This commit is contained in:
@@ -985,3 +985,33 @@ impl merge_from::MergeFrom for SaturatingBool {
|
||||
self.0 |= other.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Copy,
|
||||
Clone,
|
||||
Default,
|
||||
Debug,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
MergeFrom,
|
||||
JsonSchema,
|
||||
derive_more::FromStr,
|
||||
)]
|
||||
#[serde(transparent)]
|
||||
pub struct DelayMs(pub u64);
|
||||
|
||||
impl From<u64> for DelayMs {
|
||||
fn from(n: u64) -> Self {
|
||||
Self(n)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for DelayMs {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}ms", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use settings_macros::MergeFrom;
|
||||
|
||||
use crate::{DiagnosticSeverityContent, ShowScrollbar};
|
||||
use crate::{DelayMs, DiagnosticSeverityContent, ShowScrollbar};
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize, JsonSchema, MergeFrom)]
|
||||
@@ -45,7 +45,7 @@ pub struct EditorSettingsContent {
|
||||
/// server based on the current cursor location.
|
||||
///
|
||||
/// Default: 75
|
||||
pub lsp_highlight_debounce: Option<u64>,
|
||||
pub lsp_highlight_debounce: Option<DelayMs>,
|
||||
/// Whether to show the informational hover box when moving the mouse
|
||||
/// over symbols in the editor.
|
||||
///
|
||||
@@ -54,7 +54,7 @@ pub struct EditorSettingsContent {
|
||||
/// Time to wait in milliseconds before showing the informational hover box.
|
||||
///
|
||||
/// Default: 300
|
||||
pub hover_popover_delay: Option<u64>,
|
||||
pub hover_popover_delay: Option<DelayMs>,
|
||||
/// Toolbar related settings
|
||||
pub toolbar: Option<ToolbarContent>,
|
||||
/// Scrollbar related settings
|
||||
@@ -722,7 +722,7 @@ pub struct DragAndDropSelectionContent {
|
||||
/// The delay in milliseconds that must elapse before drag and drop is allowed. Otherwise, a new text selection is created.
|
||||
///
|
||||
/// Default: 300
|
||||
pub delay: Option<u64>,
|
||||
pub delay: Option<DelayMs>,
|
||||
}
|
||||
|
||||
/// When to show the minimap in the editor.
|
||||
@@ -804,6 +804,12 @@ impl Display for MinimumContrast {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f32> for MinimumContrast {
|
||||
fn from(x: f32) -> Self {
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
/// Opacity of the inactive panes. 0 means transparent, 1 means opaque.
|
||||
///
|
||||
/// Valid range: 0.0 to 1.0
|
||||
@@ -828,3 +834,9 @@ impl Display for InactiveOpacity {
|
||||
write!(f, "{:.1}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f32> for InactiveOpacity {
|
||||
fn from(x: f32) -> Self {
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ use settings_macros::MergeFrom;
|
||||
use util::serde::default_true;
|
||||
|
||||
use crate::{
|
||||
AllLanguageSettingsContent, ExtendingVec, ProjectTerminalSettingsContent, SlashCommandSettings,
|
||||
AllLanguageSettingsContent, DelayMs, ExtendingVec, ProjectTerminalSettingsContent,
|
||||
SlashCommandSettings,
|
||||
};
|
||||
|
||||
#[skip_serializing_none]
|
||||
@@ -310,7 +311,7 @@ pub struct InlineBlameSettings {
|
||||
/// after a delay once the cursor stops moving.
|
||||
///
|
||||
/// Default: 0
|
||||
pub delay_ms: Option<u64>,
|
||||
pub delay_ms: Option<DelayMs>,
|
||||
/// The amount of padding between the end of the source line and the start
|
||||
/// of the inline blame in units of columns.
|
||||
///
|
||||
@@ -397,7 +398,7 @@ pub struct LspPullDiagnosticsSettingsContent {
|
||||
/// 0 turns the debounce off.
|
||||
///
|
||||
/// Default: 50
|
||||
pub debounce_ms: Option<u64>,
|
||||
pub debounce_ms: Option<DelayMs>,
|
||||
}
|
||||
|
||||
#[skip_serializing_none]
|
||||
@@ -413,7 +414,7 @@ pub struct InlineDiagnosticsSettingsContent {
|
||||
/// last editor event.
|
||||
///
|
||||
/// Default: 150
|
||||
pub update_debounce_ms: Option<u64>,
|
||||
pub update_debounce_ms: Option<DelayMs>,
|
||||
/// The amount of padding between the end of the source line and the start
|
||||
/// of the inline diagnostic in units of columns.
|
||||
///
|
||||
|
||||
@@ -112,6 +112,12 @@ impl Display for CodeFade {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<f32> for CodeFade {
|
||||
fn from(x: f32) -> Self {
|
||||
Self(x)
|
||||
}
|
||||
}
|
||||
|
||||
fn default_font_features() -> Option<FontFeatures> {
|
||||
Some(FontFeatures::default())
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ use serde::{Deserialize, Serialize};
|
||||
use serde_with::skip_serializing_none;
|
||||
use settings_macros::MergeFrom;
|
||||
|
||||
use crate::{DockPosition, DockSide, InactiveOpacity, ScrollbarSettingsContent, ShowIndentGuides};
|
||||
use crate::{
|
||||
DelayMs, DockPosition, DockSide, InactiveOpacity, ScrollbarSettingsContent, ShowIndentGuides,
|
||||
};
|
||||
|
||||
#[skip_serializing_none]
|
||||
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize, JsonSchema, MergeFrom)]
|
||||
@@ -386,7 +388,7 @@ pub enum AutosaveSetting {
|
||||
/// Disable autosave.
|
||||
Off,
|
||||
/// Save after inactivity period of `milliseconds`.
|
||||
AfterDelay { milliseconds: u64 },
|
||||
AfterDelay { milliseconds: DelayMs },
|
||||
/// Autosave when focus changes.
|
||||
OnFocusChange,
|
||||
/// Autosave when the active window changes.
|
||||
|
||||
@@ -259,7 +259,7 @@ impl VsCodeSettings {
|
||||
gutter: self.gutter_content(),
|
||||
hide_mouse: None,
|
||||
horizontal_scroll_margin: None,
|
||||
hover_popover_delay: self.read_u64("editor.hover.delay"),
|
||||
hover_popover_delay: self.read_u64("editor.hover.delay").map(Into::into),
|
||||
hover_popover_enabled: self.read_bool("editor.hover.enabled"),
|
||||
inline_code_actions: None,
|
||||
jupyter: None,
|
||||
@@ -791,7 +791,8 @@ impl VsCodeSettings {
|
||||
milliseconds: self
|
||||
.read_value("files.autoSaveDelay")
|
||||
.and_then(|v| v.as_u64())
|
||||
.unwrap_or(1000),
|
||||
.unwrap_or(1000)
|
||||
.into(),
|
||||
}),
|
||||
"onFocusChange" => Some(AutosaveSetting::OnFocusChange),
|
||||
"onWindowChange" => Some(AutosaveSetting::OnWindowChange),
|
||||
|
||||
Reference in New Issue
Block a user