editor_settings.rs

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