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 use_on_type_format: bool,
12 pub scrollbar: Scrollbar,
13 pub relative_line_numbers: bool,
14 pub seed_search_query_from_cursor: SeedQuerySetting,
15}
16
17/// When to populate a new search's query based on the text under the cursor.
18#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
19#[serde(rename_all = "snake_case")]
20pub enum SeedQuerySetting {
21 /// Always populate the search query with the word under the cursor.
22 Always,
23 /// Only populate the search query when there is text selected.
24 Selection,
25 /// Never populate the search query
26 Never,
27}
28
29#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
30pub struct Scrollbar {
31 pub show: ShowScrollbar,
32 pub git_diff: bool,
33 pub selections: bool,
34}
35
36/// When to show the scrollbar in the editor.
37///
38/// Default: auto
39#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
40#[serde(rename_all = "snake_case")]
41pub enum ShowScrollbar {
42 /// Show the scrollbar if there's important information or
43 /// follow the system's configured behavior.
44 Auto,
45 /// Match the system's configured behavior.
46 System,
47 /// Always show the scrollbar.
48 Always,
49 /// Never show the scrollbar.
50 Never,
51}
52
53#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
54pub struct EditorSettingsContent {
55 /// Whether the cursor blinks in the editor.
56 ///
57 /// Default: true
58 pub cursor_blink: Option<bool>,
59 /// Whether to show the informational hover box when moving the mouse
60 /// over symbols in the editor.
61 ///
62 /// Default: true
63 pub hover_popover_enabled: Option<bool>,
64 /// Whether to pop the completions menu while typing in an editor without
65 /// explicitly requesting it.
66 ///
67 /// Default: true
68 pub show_completions_on_input: Option<bool>,
69 /// Whether to display inline and alongside documentation for items in the
70 /// completions menu.
71 ///
72 /// Default: true
73 pub show_completion_documentation: Option<bool>,
74 /// Whether to use additional LSP queries to format (and amend) the code after
75 /// every "trigger" symbol input, defined by LSP server capabilities.
76 ///
77 /// Default: true
78 pub use_on_type_format: Option<bool>,
79 /// Scrollbar related settings
80 pub scrollbar: Option<ScrollbarContent>,
81 /// Whether the line numbers on editors gutter are relative or not.
82 ///
83 /// Default: false
84 pub relative_line_numbers: Option<bool>,
85 /// When to populate a new search's query based on the text under the cursor.
86 ///
87 /// Default: always
88 pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
89}
90
91/// Scrollbar related settings
92#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
93pub struct ScrollbarContent {
94 /// When to show the scrollbar in the editor.
95 ///
96 /// Default: auto
97 pub show: Option<ShowScrollbar>,
98 /// Whether to show git diff indicators in the scrollbar.
99 ///
100 /// Default: true
101 pub git_diff: Option<bool>,
102 /// Whether to show buffer search result markers in the scrollbar.
103 ///
104 /// Default: true
105 pub selections: Option<bool>,
106}
107
108impl Settings for EditorSettings {
109 const KEY: Option<&'static str> = None;
110
111 type FileContent = EditorSettingsContent;
112
113 fn load(
114 default_value: &Self::FileContent,
115 user_values: &[&Self::FileContent],
116 _: &mut gpui::AppContext,
117 ) -> anyhow::Result<Self> {
118 Self::load_via_json_merge(default_value, user_values)
119 }
120}