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