1use core::num;
2
3use gpui::App;
4use language::CursorShape;
5use project::project_settings::DiagnosticSeverity;
6pub use settings::{
7 CurrentLineHighlight, DelayMs, DisplayIn, DocumentColorsRenderMode, DoubleClickInMultibuffer,
8 GoToDefinitionFallback, HideMouseMode, MinimapThumb, MinimapThumbBorder, MultiCursorModifier,
9 ScrollBeyondLastLine, ScrollbarDiagnostics, SeedQuerySetting, ShowMinimap, SnippetSortOrder,
10};
11use settings::{RegisterSetting, RelativeLineNumbers, Settings};
12use ui::scrollbars::{ScrollbarVisibility, ShowScrollbar};
13
14/// Imports from the VSCode settings at
15/// https://code.visualstudio.com/docs/reference/default-settings
16#[derive(Clone, RegisterSetting)]
17pub struct EditorSettings {
18 pub cursor_blink: bool,
19 pub cursor_shape: Option<CursorShape>,
20 pub current_line_highlight: CurrentLineHighlight,
21 pub selection_highlight: bool,
22 pub rounded_selection: bool,
23 pub lsp_highlight_debounce: DelayMs,
24 pub hover_popover_enabled: bool,
25 pub hover_popover_delay: DelayMs,
26 pub toolbar: Toolbar,
27 pub scrollbar: Scrollbar,
28 pub minimap: Minimap,
29 pub gutter: Gutter,
30 pub scroll_beyond_last_line: ScrollBeyondLastLine,
31 pub vertical_scroll_margin: f64,
32 pub autoscroll_on_clicks: bool,
33 pub horizontal_scroll_margin: f32,
34 pub scroll_sensitivity: f32,
35 pub fast_scroll_sensitivity: f32,
36 pub sticky_scroll: StickyScroll,
37 pub relative_line_numbers: RelativeLineNumbers,
38 pub seed_search_query_from_cursor: SeedQuerySetting,
39 pub use_smartcase_search: bool,
40 pub multi_cursor_modifier: MultiCursorModifier,
41 pub redact_private_values: bool,
42 pub expand_excerpt_lines: u32,
43 pub excerpt_context_lines: u32,
44 pub middle_click_paste: bool,
45 pub double_click_in_multibuffer: DoubleClickInMultibuffer,
46 pub search_wrap: bool,
47 pub search: SearchSettings,
48 pub auto_signature_help: bool,
49 pub show_signature_help_after_edits: bool,
50 pub go_to_definition_fallback: GoToDefinitionFallback,
51 pub jupyter: Jupyter,
52 pub hide_mouse: Option<HideMouseMode>,
53 pub snippet_sort_order: SnippetSortOrder,
54 pub diagnostics_max_severity: Option<DiagnosticSeverity>,
55 pub inline_code_actions: bool,
56 pub drag_and_drop_selection: DragAndDropSelection,
57 pub lsp_document_colors: DocumentColorsRenderMode,
58 pub minimum_contrast_for_highlights: f32,
59 pub completion_menu_scrollbar: ShowScrollbar,
60}
61#[derive(Debug, Clone)]
62pub struct Jupyter {
63 /// Whether the Jupyter feature is enabled.
64 ///
65 /// Default: true
66 pub enabled: bool,
67}
68
69#[derive(Copy, Clone, Debug, PartialEq, Eq)]
70pub struct StickyScroll {
71 pub enabled: bool,
72}
73
74#[derive(Clone, Debug, PartialEq, Eq)]
75pub struct Toolbar {
76 pub breadcrumbs: bool,
77 pub quick_actions: bool,
78 pub selections_menu: bool,
79 pub agent_review: bool,
80 pub code_actions: bool,
81}
82
83#[derive(Copy, Clone, Debug, PartialEq, Eq)]
84pub struct Scrollbar {
85 pub show: ShowScrollbar,
86 pub git_diff: bool,
87 pub selected_text: bool,
88 pub selected_symbol: bool,
89 pub search_results: bool,
90 pub diagnostics: ScrollbarDiagnostics,
91 pub cursors: bool,
92 pub axes: ScrollbarAxes,
93}
94
95#[derive(Copy, Clone, Debug, PartialEq)]
96pub struct Minimap {
97 pub show: ShowMinimap,
98 pub display_in: DisplayIn,
99 pub thumb: MinimapThumb,
100 pub thumb_border: MinimapThumbBorder,
101 pub current_line_highlight: Option<CurrentLineHighlight>,
102 pub max_width_columns: num::NonZeroU32,
103}
104
105impl Minimap {
106 pub fn minimap_enabled(&self) -> bool {
107 self.show != ShowMinimap::Never
108 }
109
110 #[inline]
111 pub fn on_active_editor(&self) -> bool {
112 self.display_in == DisplayIn::ActiveEditor
113 }
114
115 pub fn with_show_override(self) -> Self {
116 Self {
117 show: ShowMinimap::Always,
118 ..self
119 }
120 }
121}
122
123#[derive(Copy, Clone, Debug, PartialEq, Eq)]
124pub struct Gutter {
125 pub min_line_number_digits: usize,
126 pub line_numbers: bool,
127 pub runnables: bool,
128 pub breakpoints: bool,
129 pub folds: bool,
130}
131
132/// Forcefully enable or disable the scrollbar for each axis
133#[derive(Copy, Clone, Debug, PartialEq, Eq)]
134pub struct ScrollbarAxes {
135 /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
136 ///
137 /// Default: true
138 pub horizontal: bool,
139
140 /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
141 ///
142 /// Default: true
143 pub vertical: bool,
144}
145
146/// Whether to allow drag and drop text selection in buffer.
147#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
148pub struct DragAndDropSelection {
149 /// When true, enables drag and drop text selection in buffer.
150 ///
151 /// Default: true
152 pub enabled: bool,
153
154 /// The delay in milliseconds that must elapse before drag and drop is allowed. Otherwise, a new text selection is created.
155 ///
156 /// Default: 300
157 pub delay: DelayMs,
158}
159
160/// Default options for buffer and project search items.
161#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
162pub struct SearchSettings {
163 /// Whether to show the project search button in the status bar.
164 pub button: bool,
165 pub whole_word: bool,
166 pub case_sensitive: bool,
167 pub include_ignored: bool,
168 pub regex: bool,
169 pub center_on_match: bool,
170}
171
172impl EditorSettings {
173 pub fn jupyter_enabled(cx: &App) -> bool {
174 EditorSettings::get_global(cx).jupyter.enabled
175 }
176}
177
178impl ScrollbarVisibility for EditorSettings {
179 fn visibility(&self, _cx: &App) -> ShowScrollbar {
180 self.scrollbar.show
181 }
182}
183
184impl Settings for EditorSettings {
185 fn from_settings(content: &settings::SettingsContent) -> Self {
186 let editor = content.editor.clone();
187 let scrollbar = editor.scrollbar.unwrap();
188 let minimap = editor.minimap.unwrap();
189 let gutter = editor.gutter.unwrap();
190 let axes = scrollbar.axes.unwrap();
191 let toolbar = editor.toolbar.unwrap();
192 let search = editor.search.unwrap();
193 let drag_and_drop_selection = editor.drag_and_drop_selection.unwrap();
194 let sticky_scroll = editor.sticky_scroll.unwrap();
195 Self {
196 cursor_blink: editor.cursor_blink.unwrap(),
197 cursor_shape: editor.cursor_shape.map(Into::into),
198 current_line_highlight: editor.current_line_highlight.unwrap(),
199 selection_highlight: editor.selection_highlight.unwrap(),
200 rounded_selection: editor.rounded_selection.unwrap(),
201 lsp_highlight_debounce: editor.lsp_highlight_debounce.unwrap(),
202 hover_popover_enabled: editor.hover_popover_enabled.unwrap(),
203 hover_popover_delay: editor.hover_popover_delay.unwrap(),
204 toolbar: Toolbar {
205 breadcrumbs: toolbar.breadcrumbs.unwrap(),
206 quick_actions: toolbar.quick_actions.unwrap(),
207 selections_menu: toolbar.selections_menu.unwrap(),
208 agent_review: toolbar.agent_review.unwrap(),
209 code_actions: toolbar.code_actions.unwrap(),
210 },
211 scrollbar: Scrollbar {
212 show: scrollbar.show.map(Into::into).unwrap(),
213 git_diff: scrollbar.git_diff.unwrap(),
214 selected_text: scrollbar.selected_text.unwrap(),
215 selected_symbol: scrollbar.selected_symbol.unwrap(),
216 search_results: scrollbar.search_results.unwrap(),
217 diagnostics: scrollbar.diagnostics.unwrap(),
218 cursors: scrollbar.cursors.unwrap(),
219 axes: ScrollbarAxes {
220 horizontal: axes.horizontal.unwrap(),
221 vertical: axes.vertical.unwrap(),
222 },
223 },
224 minimap: Minimap {
225 show: minimap.show.unwrap(),
226 display_in: minimap.display_in.unwrap(),
227 thumb: minimap.thumb.unwrap(),
228 thumb_border: minimap.thumb_border.unwrap(),
229 current_line_highlight: minimap.current_line_highlight,
230 max_width_columns: minimap.max_width_columns.unwrap(),
231 },
232 gutter: Gutter {
233 min_line_number_digits: gutter.min_line_number_digits.unwrap(),
234 line_numbers: gutter.line_numbers.unwrap(),
235 runnables: gutter.runnables.unwrap(),
236 breakpoints: gutter.breakpoints.unwrap(),
237 folds: gutter.folds.unwrap(),
238 },
239 scroll_beyond_last_line: editor.scroll_beyond_last_line.unwrap(),
240 vertical_scroll_margin: editor.vertical_scroll_margin.unwrap() as f64,
241 autoscroll_on_clicks: editor.autoscroll_on_clicks.unwrap(),
242 horizontal_scroll_margin: editor.horizontal_scroll_margin.unwrap(),
243 scroll_sensitivity: editor.scroll_sensitivity.unwrap(),
244 fast_scroll_sensitivity: editor.fast_scroll_sensitivity.unwrap(),
245 sticky_scroll: StickyScroll {
246 enabled: sticky_scroll.enabled.unwrap(),
247 },
248 relative_line_numbers: editor.relative_line_numbers.unwrap(),
249 seed_search_query_from_cursor: editor.seed_search_query_from_cursor.unwrap(),
250 use_smartcase_search: editor.use_smartcase_search.unwrap(),
251 multi_cursor_modifier: editor.multi_cursor_modifier.unwrap(),
252 redact_private_values: editor.redact_private_values.unwrap(),
253 expand_excerpt_lines: editor.expand_excerpt_lines.unwrap(),
254 excerpt_context_lines: editor.excerpt_context_lines.unwrap(),
255 middle_click_paste: editor.middle_click_paste.unwrap(),
256 double_click_in_multibuffer: editor.double_click_in_multibuffer.unwrap(),
257 search_wrap: editor.search_wrap.unwrap(),
258 search: SearchSettings {
259 button: search.button.unwrap(),
260 whole_word: search.whole_word.unwrap(),
261 case_sensitive: search.case_sensitive.unwrap(),
262 include_ignored: search.include_ignored.unwrap(),
263 regex: search.regex.unwrap(),
264 center_on_match: search.center_on_match.unwrap(),
265 },
266 auto_signature_help: editor.auto_signature_help.unwrap(),
267 show_signature_help_after_edits: editor.show_signature_help_after_edits.unwrap(),
268 go_to_definition_fallback: editor.go_to_definition_fallback.unwrap(),
269 jupyter: Jupyter {
270 enabled: editor.jupyter.unwrap().enabled.unwrap(),
271 },
272 hide_mouse: editor.hide_mouse,
273 snippet_sort_order: editor.snippet_sort_order.unwrap(),
274 diagnostics_max_severity: editor.diagnostics_max_severity.map(Into::into),
275 inline_code_actions: editor.inline_code_actions.unwrap(),
276 drag_and_drop_selection: DragAndDropSelection {
277 enabled: drag_and_drop_selection.enabled.unwrap(),
278 delay: drag_and_drop_selection.delay.unwrap(),
279 },
280 lsp_document_colors: editor.lsp_document_colors.unwrap(),
281 minimum_contrast_for_highlights: editor.minimum_contrast_for_highlights.unwrap().0,
282 completion_menu_scrollbar: editor.completion_menu_scrollbar.map(Into::into).unwrap(),
283 }
284 }
285}