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