editor_settings.rs

 1use schemars::JsonSchema;
 2use serde::{Deserialize, Serialize};
 3use settings::Setting;
 4
 5#[derive(Deserialize)]
 6pub struct EditorSettings {
 7    pub cursor_blink: bool,
 8    pub hover_popover_enabled: bool,
 9    pub show_completions_on_input: bool,
10    pub use_on_type_format: bool,
11    pub scrollbar: Scrollbar,
12    pub inlay_hints: InlayHints,
13}
14
15#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
16pub struct Scrollbar {
17    pub show: ShowScrollbar,
18    pub git_diff: bool,
19}
20
21#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
22pub struct InlayHints {
23    pub enabled: bool,
24    pub show_type_hints: bool,
25    pub show_parameter_hints: bool,
26    pub show_other_hints: bool,
27}
28
29#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
30#[serde(rename_all = "snake_case")]
31pub enum ShowScrollbar {
32    Auto,
33    System,
34    Always,
35    Never,
36}
37
38#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
39pub struct EditorSettingsContent {
40    pub cursor_blink: Option<bool>,
41    pub hover_popover_enabled: Option<bool>,
42    pub show_completions_on_input: Option<bool>,
43    pub use_on_type_format: Option<bool>,
44    pub scrollbar: Option<ScrollbarContent>,
45    pub inlay_hints: Option<InlayHintsContent>,
46}
47
48#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
49pub struct ScrollbarContent {
50    pub show: Option<ShowScrollbar>,
51    pub git_diff: Option<bool>,
52}
53
54#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
55pub struct InlayHintsContent {
56    pub enabled: Option<bool>,
57    pub show_type_hints: Option<bool>,
58    pub show_parameter_hints: Option<bool>,
59    pub show_other_hints: Option<bool>,
60}
61
62impl Setting for EditorSettings {
63    const KEY: Option<&'static str> = None;
64
65    type FileContent = EditorSettingsContent;
66
67    fn load(
68        default_value: &Self::FileContent,
69        user_values: &[&Self::FileContent],
70        _: &gpui::AppContext,
71    ) -> anyhow::Result<Self> {
72        Self::load_via_json_merge(default_value, user_values)
73    }
74}