1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use settings::Settings;
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 show_completion_documentation: bool,
11 pub completion_documentation_secondary_query_debounce: u64,
12 pub use_on_type_format: bool,
13 pub scrollbar: Scrollbar,
14 pub vertical_scroll_margin: f32,
15 pub relative_line_numbers: bool,
16 pub seed_search_query_from_cursor: SeedQuerySetting,
17 pub redact_private_values: bool,
18}
19
20/// When to populate a new search's query based on the text under the cursor.
21#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
22#[serde(rename_all = "snake_case")]
23pub enum SeedQuerySetting {
24 /// Always populate the search query with the word under the cursor.
25 Always,
26 /// Only populate the search query when there is text selected.
27 Selection,
28 /// Never populate the search query
29 Never,
30}
31
32#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
33pub struct Scrollbar {
34 pub show: ShowScrollbar,
35 pub git_diff: bool,
36 pub selections: bool,
37 pub symbols_selections: bool,
38 pub diagnostics: bool,
39}
40
41/// When to show the scrollbar in the editor.
42///
43/// Default: auto
44#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
45#[serde(rename_all = "snake_case")]
46pub enum ShowScrollbar {
47 /// Show the scrollbar if there's important information or
48 /// follow the system's configured behavior.
49 Auto,
50 /// Match the system's configured behavior.
51 System,
52 /// Always show the scrollbar.
53 Always,
54 /// Never show the scrollbar.
55 Never,
56}
57
58#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
59pub struct EditorSettingsContent {
60 /// Whether the cursor blinks in the editor.
61 ///
62 /// Default: true
63 pub cursor_blink: Option<bool>,
64 /// Whether to show the informational hover box when moving the mouse
65 /// over symbols in the editor.
66 ///
67 /// Default: true
68 pub hover_popover_enabled: Option<bool>,
69 /// Whether to pop the completions menu while typing in an editor without
70 /// explicitly requesting it.
71 ///
72 /// Default: true
73 pub show_completions_on_input: Option<bool>,
74 /// Whether to display inline and alongside documentation for items in the
75 /// completions menu.
76 ///
77 /// Default: true
78 pub show_completion_documentation: Option<bool>,
79 /// The debounce delay before re-querying the language server for completion
80 /// documentation when not included in original completion list.
81 ///
82 /// Default: 300 ms
83 pub completion_documentation_secondary_query_debounce: Option<u64>,
84 /// Whether to use additional LSP queries to format (and amend) the code after
85 /// every "trigger" symbol input, defined by LSP server capabilities.
86 ///
87 /// Default: true
88 pub use_on_type_format: Option<bool>,
89 /// Scrollbar related settings
90 pub scrollbar: Option<ScrollbarContent>,
91
92 /// The number of lines to keep above/below the cursor when auto-scrolling.
93 ///
94 /// Default: 3.
95 pub vertical_scroll_margin: Option<f32>,
96 /// Whether the line numbers on editors gutter are relative or not.
97 ///
98 /// Default: false
99 pub relative_line_numbers: Option<bool>,
100 /// When to populate a new search's query based on the text under the cursor.
101 ///
102 /// Default: always
103 pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
104
105 /// Hide the values of variables in `private` files, as defined by the
106 /// private_files setting. This only changes the visual representation,
107 /// the values are still present in the file and can be selected / copied / pasted
108 ///
109 /// Default: false
110 pub redact_private_values: Option<bool>,
111}
112
113/// Scrollbar related settings
114#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
115pub struct ScrollbarContent {
116 /// When to show the scrollbar in the editor.
117 ///
118 /// Default: auto
119 pub show: Option<ShowScrollbar>,
120 /// Whether to show git diff indicators in the scrollbar.
121 ///
122 /// Default: true
123 pub git_diff: Option<bool>,
124 /// Whether to show buffer search result markers in the scrollbar.
125 ///
126 /// Default: true
127 pub selections: Option<bool>,
128 /// Whether to show symbols highlighted markers in the scrollbar.
129 ///
130 /// Default: true
131 pub symbols_selections: Option<bool>,
132 /// Whether to show diagnostic indicators in the scrollbar.
133 ///
134 /// Default: true
135 pub diagnostics: Option<bool>,
136}
137
138impl Settings for EditorSettings {
139 const KEY: Option<&'static str> = None;
140
141 type FileContent = EditorSettingsContent;
142
143 fn load(
144 default_value: &Self::FileContent,
145 user_values: &[&Self::FileContent],
146 _: &mut gpui::AppContext,
147 ) -> anyhow::Result<Self> {
148 Self::load_via_json_merge(default_value, user_values)
149 }
150}