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