editor_settings.rs

  1use schemars::JsonSchema;
  2use serde::{Deserialize, Serialize};
  3use settings::Settings;
  4
  5#[derive(Deserialize, Clone)]
  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 toolbar: Toolbar,
 14    pub scrollbar: Scrollbar,
 15    pub gutter: Gutter,
 16    pub vertical_scroll_margin: f32,
 17    pub relative_line_numbers: bool,
 18    pub seed_search_query_from_cursor: SeedQuerySetting,
 19    pub multi_cursor_modifier: MultiCursorModifier,
 20    pub redact_private_values: bool,
 21    #[serde(default)]
 22    pub double_click_in_multibuffer: DoubleClickInMultibuffer,
 23}
 24
 25/// When to populate a new search's query based on the text under the cursor.
 26#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 27#[serde(rename_all = "snake_case")]
 28pub enum SeedQuerySetting {
 29    /// Always populate the search query with the word under the cursor.
 30    Always,
 31    /// Only populate the search query when there is text selected.
 32    Selection,
 33    /// Never populate the search query
 34    Never,
 35}
 36
 37/// What to do when multibuffer is double clicked in some of its excerpts (parts of singleton buffers).
 38#[derive(Default, Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
 39#[serde(rename_all = "snake_case")]
 40pub enum DoubleClickInMultibuffer {
 41    /// Behave as a regular buffer and select the whole word.
 42    #[default]
 43    Select,
 44    /// Open the excerpt clicked as a new buffer in the new tab, if no `alt` modifier was pressed during double click.
 45    /// Otherwise, behave as a regular buffer and select the whole word.
 46    Open,
 47}
 48
 49#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 50pub struct Toolbar {
 51    pub breadcrumbs: bool,
 52    pub quick_actions: bool,
 53}
 54
 55#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 56pub struct Scrollbar {
 57    pub show: ShowScrollbar,
 58    pub git_diff: bool,
 59    pub selections: bool,
 60    pub symbols_selections: bool,
 61    pub diagnostics: bool,
 62}
 63
 64#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 65pub struct Gutter {
 66    pub line_numbers: bool,
 67    pub code_actions: bool,
 68    pub folds: bool,
 69}
 70
 71/// When to show the scrollbar in the editor.
 72///
 73/// Default: auto
 74#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 75#[serde(rename_all = "snake_case")]
 76pub enum ShowScrollbar {
 77    /// Show the scrollbar if there's important information or
 78    /// follow the system's configured behavior.
 79    Auto,
 80    /// Match the system's configured behavior.
 81    System,
 82    /// Always show the scrollbar.
 83    Always,
 84    /// Never show the scrollbar.
 85    Never,
 86}
 87
 88/// The key to use for adding multiple cursors
 89///
 90/// Default: alt
 91#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
 92#[serde(rename_all = "snake_case")]
 93pub enum MultiCursorModifier {
 94    Alt,
 95    Cmd,
 96}
 97
 98#[derive(Clone, Default, Serialize, Deserialize, JsonSchema)]
 99pub struct EditorSettingsContent {
100    /// Whether the cursor blinks in the editor.
101    ///
102    /// Default: true
103    pub cursor_blink: Option<bool>,
104    /// Whether to show the informational hover box when moving the mouse
105    /// over symbols in the editor.
106    ///
107    /// Default: true
108    pub hover_popover_enabled: Option<bool>,
109    /// Whether to pop the completions menu while typing in an editor without
110    /// explicitly requesting it.
111    ///
112    /// Default: true
113    pub show_completions_on_input: Option<bool>,
114    /// Whether to display inline and alongside documentation for items in the
115    /// completions menu.
116    ///
117    /// Default: true
118    pub show_completion_documentation: Option<bool>,
119    /// The debounce delay before re-querying the language server for completion
120    /// documentation when not included in original completion list.
121    ///
122    /// Default: 300 ms
123    pub completion_documentation_secondary_query_debounce: Option<u64>,
124    /// Whether to use additional LSP queries to format (and amend) the code after
125    /// every "trigger" symbol input, defined by LSP server capabilities.
126    ///
127    /// Default: true
128    pub use_on_type_format: Option<bool>,
129    /// Toolbar related settings
130    pub toolbar: Option<ToolbarContent>,
131    /// Scrollbar related settings
132    pub scrollbar: Option<ScrollbarContent>,
133    /// Gutter related settings
134    pub gutter: Option<GutterContent>,
135    /// The number of lines to keep above/below the cursor when auto-scrolling.
136    ///
137    /// Default: 3.
138    pub vertical_scroll_margin: Option<f32>,
139    /// Whether the line numbers on editors gutter are relative or not.
140    ///
141    /// Default: false
142    pub relative_line_numbers: Option<bool>,
143    /// When to populate a new search's query based on the text under the cursor.
144    ///
145    /// Default: always
146    pub seed_search_query_from_cursor: Option<SeedQuerySetting>,
147    /// The key to use for adding multiple cursors
148    ///
149    /// Default: alt
150    pub multi_cursor_modifier: Option<MultiCursorModifier>,
151    /// Hide the values of variables in `private` files, as defined by the
152    /// private_files setting. This only changes the visual representation,
153    /// the values are still present in the file and can be selected / copied / pasted
154    ///
155    /// Default: false
156    pub redact_private_values: Option<bool>,
157
158    /// What to do when multibuffer is double clicked in some of its excerpts
159    /// (parts of singleton buffers).
160    ///
161    /// Default: select
162    pub double_click_in_multibuffer: Option<DoubleClickInMultibuffer>,
163}
164
165// Toolbar related settings
166#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
167pub struct ToolbarContent {
168    /// Whether to display breadcrumbs in the editor toolbar.
169    ///
170    /// Default: true
171    pub breadcrumbs: Option<bool>,
172    /// Whether to display quik action buttons in the editor toolbar.
173    ///
174    /// Default: true
175    pub quick_actions: Option<bool>,
176}
177
178/// Scrollbar related settings
179#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
180pub struct ScrollbarContent {
181    /// When to show the scrollbar in the editor.
182    ///
183    /// Default: auto
184    pub show: Option<ShowScrollbar>,
185    /// Whether to show git diff indicators in the scrollbar.
186    ///
187    /// Default: true
188    pub git_diff: Option<bool>,
189    /// Whether to show buffer search result markers in the scrollbar.
190    ///
191    /// Default: true
192    pub selections: Option<bool>,
193    /// Whether to show symbols highlighted markers in the scrollbar.
194    ///
195    /// Default: true
196    pub symbols_selections: Option<bool>,
197    /// Whether to show diagnostic indicators in the scrollbar.
198    ///
199    /// Default: true
200    pub diagnostics: Option<bool>,
201}
202
203/// Gutter related settings
204#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
205pub struct GutterContent {
206    /// Whether to show line numbers in the gutter.
207    ///
208    /// Default: true
209    pub line_numbers: Option<bool>,
210    /// Whether to show code action buttons in the gutter.
211    ///
212    /// Default: true
213    pub code_actions: Option<bool>,
214    /// Whether to show fold buttons in the gutter.
215    ///
216    /// Default: true
217    pub folds: Option<bool>,
218}
219
220impl Settings for EditorSettings {
221    const KEY: Option<&'static str> = None;
222
223    type FileContent = EditorSettingsContent;
224
225    fn load(
226        default_value: &Self::FileContent,
227        user_values: &[&Self::FileContent],
228        _: &mut gpui::AppContext,
229    ) -> anyhow::Result<Self> {
230        Self::load_via_json_merge(default_value, user_values)
231    }
232}