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 folds: bool,
137}
138
139/// Forcefully enable or disable the scrollbar for each axis
140#[derive(Copy, Clone, Debug, PartialEq, Eq)]
141pub struct ScrollbarAxes {
142 /// When false, forcefully disables the horizontal scrollbar. Otherwise, obey other settings.
143 ///
144 /// Default: true
145 pub horizontal: bool,
146
147 /// When false, forcefully disables the vertical scrollbar. Otherwise, obey other settings.
148 ///
149 /// Default: true
150 pub vertical: bool,
151}
152
153/// Whether to allow drag and drop text selection in buffer.
154#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
155pub struct DragAndDropSelection {
156 /// When true, enables drag and drop text selection in buffer.
157 ///
158 /// Default: true
159 pub enabled: bool,
160
161 /// The delay in milliseconds that must elapse before drag and drop is allowed. Otherwise, a new text selection is created.
162 ///
163 /// Default: 300
164 pub delay: DelayMs,
165}
166
167/// Default options for buffer and project search items.
168#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
169pub struct SearchSettings {
170 /// Whether to show the project search button in the status bar.
171 pub button: bool,
172 /// Whether to only match on whole words.
173 pub whole_word: bool,
174 /// Whether to match case sensitively.
175 pub case_sensitive: bool,
176 /// Whether to include gitignored files in search results.
177 pub include_ignored: bool,
178 /// Whether to interpret the search query as a regular expression.
179 pub regex: bool,
180 /// Whether to center the cursor on each search match when navigating.
181 pub center_on_match: bool,
182}
183
184impl EditorSettings {
185 pub fn jupyter_enabled(cx: &App) -> bool {
186 EditorSettings::get_global(cx).jupyter.enabled
187 }
188}
189
190impl Settings for EditorSettings {
191 fn from_settings(content: &settings::SettingsContent) -> Self {
192 let editor = content.editor.clone();
193 let scrollbar = editor.scrollbar.unwrap();
194 let minimap = editor.minimap.unwrap();
195 let gutter = editor.gutter.unwrap();
196 let axes = scrollbar.axes.unwrap();
197 let toolbar = editor.toolbar.unwrap();
198 let search = editor.search.unwrap();
199 let drag_and_drop_selection = editor.drag_and_drop_selection.unwrap();
200 let sticky_scroll = editor.sticky_scroll.unwrap();
201 Self {
202 cursor_blink: editor.cursor_blink.unwrap(),
203 cursor_shape: editor.cursor_shape.map(Into::into),
204 current_line_highlight: editor.current_line_highlight.unwrap(),
205 selection_highlight: editor.selection_highlight.unwrap(),
206 rounded_selection: editor.rounded_selection.unwrap(),
207 lsp_highlight_debounce: editor.lsp_highlight_debounce.unwrap(),
208 hover_popover_enabled: editor.hover_popover_enabled.unwrap(),
209 hover_popover_delay: editor.hover_popover_delay.unwrap(),
210 hover_popover_sticky: editor.hover_popover_sticky.unwrap(),
211 hover_popover_hiding_delay: editor.hover_popover_hiding_delay.unwrap(),
212 toolbar: Toolbar {
213 breadcrumbs: toolbar.breadcrumbs.unwrap(),
214 quick_actions: toolbar.quick_actions.unwrap(),
215 selections_menu: toolbar.selections_menu.unwrap(),
216 agent_review: toolbar.agent_review.unwrap(),
217 code_actions: toolbar.code_actions.unwrap(),
218 },
219 scrollbar: Scrollbar {
220 show: scrollbar.show.map(ui_scrollbar_settings_from_raw).unwrap(),
221 git_diff: scrollbar.git_diff.unwrap()
222 && content
223 .git
224 .as_ref()
225 .unwrap()
226 .enabled
227 .unwrap()
228 .is_git_diff_enabled(),
229 selected_text: scrollbar.selected_text.unwrap(),
230 selected_symbol: scrollbar.selected_symbol.unwrap(),
231 search_results: scrollbar.search_results.unwrap(),
232 diagnostics: scrollbar.diagnostics.unwrap(),
233 cursors: scrollbar.cursors.unwrap(),
234 axes: ScrollbarAxes {
235 horizontal: axes.horizontal.unwrap(),
236 vertical: axes.vertical.unwrap(),
237 },
238 },
239 minimap: Minimap {
240 show: minimap.show.unwrap(),
241 display_in: minimap.display_in.unwrap(),
242 thumb: minimap.thumb.unwrap(),
243 thumb_border: minimap.thumb_border.unwrap(),
244 current_line_highlight: minimap.current_line_highlight,
245 max_width_columns: minimap.max_width_columns.unwrap(),
246 },
247 gutter: Gutter {
248 min_line_number_digits: gutter.min_line_number_digits.unwrap(),
249 line_numbers: gutter.line_numbers.unwrap(),
250 runnables: gutter.runnables.unwrap(),
251 breakpoints: gutter.breakpoints.unwrap(),
252 folds: gutter.folds.unwrap(),
253 },
254 scroll_beyond_last_line: editor.scroll_beyond_last_line.unwrap(),
255 vertical_scroll_margin: editor.vertical_scroll_margin.unwrap() as f64,
256 autoscroll_on_clicks: editor.autoscroll_on_clicks.unwrap(),
257 horizontal_scroll_margin: editor.horizontal_scroll_margin.unwrap(),
258 scroll_sensitivity: editor.scroll_sensitivity.unwrap(),
259 mouse_wheel_zoom: editor.mouse_wheel_zoom.unwrap(),
260 fast_scroll_sensitivity: editor.fast_scroll_sensitivity.unwrap(),
261 sticky_scroll: StickyScroll {
262 enabled: sticky_scroll.enabled.unwrap(),
263 },
264 relative_line_numbers: editor.relative_line_numbers.unwrap(),
265 seed_search_query_from_cursor: editor.seed_search_query_from_cursor.unwrap(),
266 use_smartcase_search: editor.use_smartcase_search.unwrap(),
267 multi_cursor_modifier: editor.multi_cursor_modifier.unwrap(),
268 redact_private_values: editor.redact_private_values.unwrap(),
269 expand_excerpt_lines: editor.expand_excerpt_lines.unwrap(),
270 excerpt_context_lines: editor.excerpt_context_lines.unwrap(),
271 middle_click_paste: editor.middle_click_paste.unwrap(),
272 double_click_in_multibuffer: editor.double_click_in_multibuffer.unwrap(),
273 search_wrap: editor.search_wrap.unwrap(),
274 search: SearchSettings {
275 button: search.button.unwrap(),
276 whole_word: search.whole_word.unwrap(),
277 case_sensitive: search.case_sensitive.unwrap(),
278 include_ignored: search.include_ignored.unwrap(),
279 regex: search.regex.unwrap(),
280 center_on_match: search.center_on_match.unwrap(),
281 },
282 auto_signature_help: editor.auto_signature_help.unwrap(),
283 show_signature_help_after_edits: editor.show_signature_help_after_edits.unwrap(),
284 go_to_definition_fallback: editor.go_to_definition_fallback.unwrap(),
285 jupyter: Jupyter {
286 enabled: editor.jupyter.unwrap().enabled.unwrap(),
287 },
288 hide_mouse: editor.hide_mouse,
289 snippet_sort_order: editor.snippet_sort_order.unwrap(),
290 diagnostics_max_severity: editor.diagnostics_max_severity.map(Into::into),
291 inline_code_actions: editor.inline_code_actions.unwrap(),
292 drag_and_drop_selection: DragAndDropSelection {
293 enabled: drag_and_drop_selection.enabled.unwrap(),
294 delay: drag_and_drop_selection.delay.unwrap(),
295 },
296 lsp_document_colors: editor.lsp_document_colors.unwrap(),
297 minimum_contrast_for_highlights: editor.minimum_contrast_for_highlights.unwrap().0,
298 completion_menu_scrollbar: editor
299 .completion_menu_scrollbar
300 .map(ui_scrollbar_settings_from_raw)
301 .unwrap(),
302 completion_detail_alignment: editor.completion_detail_alignment.unwrap(),
303 diff_view_style: editor.diff_view_style.unwrap(),
304 minimum_split_diff_width: editor.minimum_split_diff_width.unwrap(),
305 }
306 }
307}
308
309#[derive(Default)]
310pub struct EditorSettingsScrollbarProxy;
311
312impl ui::scrollbars::ScrollbarVisibility for EditorSettingsScrollbarProxy {
313 fn visibility(&self, cx: &App) -> ShowScrollbar {
314 EditorSettings::get_global(cx).scrollbar.show
315 }
316}
317
318pub fn ui_scrollbar_settings_from_raw(
319 value: settings::ShowScrollbar,
320) -> ui::scrollbars::ShowScrollbar {
321 match value {
322 settings::ShowScrollbar::Auto => ShowScrollbar::Auto,
323 settings::ShowScrollbar::System => ShowScrollbar::System,
324 settings::ShowScrollbar::Always => ShowScrollbar::Always,
325 settings::ShowScrollbar::Never => ShowScrollbar::Never,
326 }
327}