From 58e9952d7b2ac81299778c03fc6d232045fe4c5e Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:07:45 +0200 Subject: [PATCH] tasks: Allow disabling runnables in the gutter (#13329) Runnables can now be disabled with: ``` "gutter": { "runnables": false } ``` Fixes #13280 Release Notes: - Added `gutter.runnables` setting that controls whether runnable indicators are displayed in the gutter. --- assets/settings/default.json | 2 ++ crates/editor/src/editor.rs | 7 ++++++- crates/editor/src/editor_settings.rs | 5 +++++ crates/editor/src/element.rs | 20 ++++++++++++-------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/assets/settings/default.json b/assets/settings/default.json index 1c759c615434c7e4b864ace197e3f427a71d3414..72e7ea6fea55e8d939a8bd24fb0f49764fb25f39 100644 --- a/assets/settings/default.json +++ b/assets/settings/default.json @@ -231,6 +231,8 @@ "line_numbers": true, // Whether to show code action buttons in the gutter. "code_actions": true, + // Whether to show runnables buttons in the gutter. + "runnables": true, // Whether to show fold buttons in the gutter. "folds": true }, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a1c344d88673bc979a7e04e39ace4ca2c1281f39..298b51d7bd2711e5af6fb5ab727d2139946e48cf 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -8247,6 +8247,10 @@ impl Editor { } fn refresh_runnables(&mut self, cx: &mut ViewContext) -> Task<()> { + if !EditorSettings::get_global(cx).gutter.runnables { + self.clear_tasks(); + return Task::ready(()); + } let project = self.project.clone(); cx.spawn(|this, mut cx| async move { let Ok(display_snapshot) = this.update(&mut cx, |this, cx| { @@ -11017,6 +11021,7 @@ impl Editor { } fn settings_changed(&mut self, cx: &mut ViewContext) { + self.tasks_update_task = Some(self.refresh_runnables(cx)); self.refresh_inline_completion(true, cx); self.refresh_inlay_hints( InlayHintRefreshReason::SettingsChange(inlay_hint_settings( @@ -11790,7 +11795,7 @@ impl EditorSnapshot { .then_some(em_width * GIT_BLAME_GUTTER_WIDTH_CHARS); let mut left_padding = git_blame_entries_width.unwrap_or(Pixels::ZERO); - left_padding += if show_code_actions { + left_padding += if show_code_actions || gutter_settings.runnables { em_width * 3.0 } else if show_git_gutter && show_line_numbers { em_width * 2.0 diff --git a/crates/editor/src/editor_settings.rs b/crates/editor/src/editor_settings.rs index 3aa407d6a028a9ecb30511cce99e19f2230be717..8a2226483823038dd0f74caaf1c974b95397b350 100644 --- a/crates/editor/src/editor_settings.rs +++ b/crates/editor/src/editor_settings.rs @@ -84,6 +84,7 @@ pub struct Scrollbar { pub struct Gutter { pub line_numbers: bool, pub code_actions: bool, + pub runnables: bool, pub folds: bool, } @@ -255,6 +256,10 @@ pub struct GutterContent { /// /// Default: true pub code_actions: Option, + /// Whether to show runnable buttons in the gutter. + /// + /// Default: true + pub runnables: Option, /// Whether to show fold buttons in the gutter. /// /// Default: true diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 7716325f31e532ac3edaaf133700f08df03f96c3..592f6a43744bbcbb207955cf28ce14b6f51b4415 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -4931,14 +4931,18 @@ impl Element for EditorElement { } } - let test_indicators = self.layout_run_indicators( - line_height, - scroll_pixel_position, - &gutter_dimensions, - &gutter_hitbox, - &snapshot, - cx, - ); + let test_indicators = if gutter_settings.runnables { + self.layout_run_indicators( + line_height, + scroll_pixel_position, + &gutter_dimensions, + &gutter_hitbox, + &snapshot, + cx, + ) + } else { + vec![] + }; if !cx.has_active_drag() { self.layout_hover_popovers(