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