Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T02:32:58.746Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

editor_settings.rs

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