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