Skip to content

Add a way to clear activity indicator (cherry-pick #30156) #30204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions crates/activity_indicator/src/activity_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct ActivityIndicator {
context_menu_handle: PopoverMenuHandle<ContextMenu>,
}

#[derive(Debug)]
struct ServerStatus {
name: SharedString,
status: BinaryStatus,
Expand Down Expand Up @@ -70,6 +71,7 @@ impl ActivityIndicator {
) -> Entity<ActivityIndicator> {
let project = workspace.project().clone();
let auto_updater = AutoUpdater::get(cx);
let workspace_handle = cx.entity();
let this = cx.new(|cx| {
let mut status_events = languages.language_server_binary_statuses();
cx.spawn(async move |this, cx| {
Expand All @@ -84,6 +86,25 @@ impl ActivityIndicator {
})
.detach();

cx.subscribe_in(
&workspace_handle,
window,
|activity_indicator, _, event, window, cx| match event {
workspace::Event::ClearActivityIndicator { .. } => {
if activity_indicator.statuses.pop().is_some() {
activity_indicator.dismiss_error_message(
&DismissErrorMessage,
window,
cx,
);
cx.notify();
}
}
_ => {}
},
)
.detach();

cx.subscribe(
&project.read(cx).lsp_store(),
|_, _, event, cx| match event {
Expand Down Expand Up @@ -115,7 +136,7 @@ impl ActivityIndicator {
}

Self {
statuses: Default::default(),
statuses: Vec::new(),
project: project.clone(),
auto_updater,
context_menu_handle: Default::default(),
Expand Down Expand Up @@ -185,11 +206,8 @@ impl ActivityIndicator {
cx: &mut Context<Self>,
) {
if let Some(updater) = &self.auto_updater {
updater.update(cx, |updater, cx| {
updater.dismiss_error(cx);
});
updater.update(cx, |updater, cx| updater.dismiss_error(cx));
}
cx.notify();
}

fn pending_language_server_work<'a>(
Expand Down
6 changes: 5 additions & 1 deletion crates/auto_update/src/auto_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,13 @@ impl AutoUpdater {
self.status.clone()
}

pub fn dismiss_error(&mut self, cx: &mut Context<Self>) {
pub fn dismiss_error(&mut self, cx: &mut Context<Self>) -> bool {
if self.status == AutoUpdateStatus::Idle {
return false;
}
self.status = AutoUpdateStatus::Idle;
cx.notify();
true
}

// If you are packaging Zed and need to override the place it downloads SSH remotes from,
Expand Down
13 changes: 11 additions & 2 deletions crates/collab_ui/src/notification_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use ui::{
Avatar, Button, Icon, IconButton, IconName, Label, Tab, Tooltip, h_flex, prelude::*, v_flex,
};
use util::{ResultExt, TryFutureExt};
use workspace::SuppressNotification;
use workspace::notifications::{
Notification as WorkspaceNotification, NotificationId, SuppressEvent,
};
Expand Down Expand Up @@ -823,11 +824,19 @@ impl Render for NotificationToast {
.child(Label::new(self.text.clone()))
.child(
IconButton::new("close", IconName::Close)
.tooltip(|window, cx| Tooltip::for_action("Close", &menu::Cancel, window, cx))
.on_click(cx.listener(|_, _, _, cx| cx.emit(DismissEvent))),
)
.child(
IconButton::new("suppress", IconName::XCircle)
.tooltip(Tooltip::text("Do not show until restart"))
IconButton::new("suppress", IconName::SquareMinus)
.tooltip(|window, cx| {
Tooltip::for_action(
"Do not show until restart",
&SuppressNotification,
window,
cx,
)
})
.on_click(cx.listener(|_, _, _, cx| cx.emit(SuppressEvent))),
)
.on_click(cx.listener(|this, _, window, cx| {
Expand Down
58 changes: 47 additions & 11 deletions crates/workspace/src/notifications.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{Toast, Workspace};
use crate::{SuppressNotification, Toast, Workspace};
use gpui::{
AnyView, App, AppContext as _, AsyncWindowContext, ClipboardItem, Context, DismissEvent,
Entity, EventEmitter, FocusHandle, Focusable, PromptLevel, Render, ScrollHandle, Task, svg,
Expand Down Expand Up @@ -290,8 +290,15 @@ impl Render for LanguageServerPrompt {
h_flex()
.gap_2()
.child(
IconButton::new("suppress", IconName::XCircle)
.tooltip(Tooltip::text("Do not show until restart"))
IconButton::new("suppress", IconName::SquareMinus)
.tooltip(|window, cx| {
Tooltip::for_action(
"Do not show until restart",
&SuppressNotification,
window,
cx,
)
})
.on_click(
cx.listener(|_, _, _, cx| cx.emit(SuppressEvent)),
),
Expand All @@ -308,9 +315,20 @@ impl Render for LanguageServerPrompt {
})
.tooltip(Tooltip::text("Copy Description")),
)
.child(IconButton::new("close", IconName::Close).on_click(
cx.listener(|_, _, _, cx| cx.emit(gpui::DismissEvent)),
)),
.child(
IconButton::new("close", IconName::Close)
.tooltip(|window, cx| {
Tooltip::for_action(
"Close",
&menu::Cancel,
window,
cx,
)
})
.on_click(cx.listener(|_, _, _, cx| {
cx.emit(gpui::DismissEvent)
})),
),
),
)
.child(Label::new(request.message.to_string()).size(LabelSize::Small))
Expand Down Expand Up @@ -443,6 +461,8 @@ pub mod simple_message_notification {
};
use ui::{Tooltip, prelude::*};

use crate::SuppressNotification;

use super::{Notification, SuppressEvent};

pub struct MessageNotification {
Expand Down Expand Up @@ -640,18 +660,34 @@ pub mod simple_message_notification {
.gap_2()
.when(self.show_suppress_button, |this| {
this.child(
IconButton::new("suppress", IconName::XCircle)
.tooltip(Tooltip::text("Do not show until restart"))
IconButton::new("suppress", IconName::SquareMinus)
.tooltip(|window, cx| {
Tooltip::for_action(
"Do not show until restart",
&SuppressNotification,
window,
cx,
)
})
.on_click(cx.listener(|_, _, _, cx| {
cx.emit(SuppressEvent);
})),
)
})
.when(self.show_close_button, |this| {
this.child(
IconButton::new("close", IconName::Close).on_click(
cx.listener(|this, _, _, cx| this.dismiss(cx)),
),
IconButton::new("close", IconName::Close)
.tooltip(|window, cx| {
Tooltip::for_action(
"Close",
&menu::Cancel,
window,
cx,
)
})
.on_click(
cx.listener(|this, _, _, cx| this.dismiss(cx)),
),
)
}),
),
Expand Down
2 changes: 2 additions & 0 deletions crates/workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ pub enum Event {
},
ZoomChanged,
ModalOpened,
ClearActivityIndicator,
}

#[derive(Debug)]
Expand Down Expand Up @@ -5496,6 +5497,7 @@ impl Workspace {
return;
}

cx.emit(Event::ClearActivityIndicator);
cx.propagate();
}
}
Expand Down
Loading