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