From 3a69943df3ec54e001557a9fec72a36ad11c2b56 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 6 Jun 2022 09:18:44 +0200 Subject: [PATCH] Require that `PartialEq` is implemented for `Action` --- crates/client/src/user.rs | 2 +- .../src/contact_notification.rs | 4 ++-- crates/contacts_panel/src/contacts_panel.rs | 8 +++---- crates/diagnostics/src/diagnostics.rs | 2 +- crates/editor/src/editor.rs | 22 +++++++++---------- crates/gpui/src/app/action.rs | 9 ++++++++ crates/gpui/src/views/select.rs | 2 +- crates/menu/src/menu.rs | 2 +- crates/project_panel/src/project_panel.rs | 6 ++--- crates/search/src/buffer_search.rs | 4 ++-- crates/search/src/search.rs | 4 ++-- crates/vim/src/motion.rs | 6 ++--- crates/vim/src/normal/change.rs | 2 +- crates/vim/src/vim.rs | 4 ++-- crates/workspace/src/pane.rs | 10 ++++----- crates/workspace/src/pane_group.rs | 2 +- crates/workspace/src/sidebar.rs | 6 ++--- crates/workspace/src/workspace.rs | 10 ++++----- crates/zed/src/zed.rs | 2 +- 19 files changed, 58 insertions(+), 49 deletions(-) diff --git a/crates/client/src/user.rs b/crates/client/src/user.rs index 803fcf370361d38b2637659484ad1050367f97fd..c84af7c9f860dae24cc7f9758773430188ba8648 100644 --- a/crates/client/src/user.rs +++ b/crates/client/src/user.rs @@ -35,7 +35,7 @@ impl PartialEq for User { impl Eq for User {} -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub struct Contact { pub user: Arc, pub online: bool, diff --git a/crates/contacts_panel/src/contact_notification.rs b/crates/contacts_panel/src/contact_notification.rs index a1eeb365f56d753f0e26141b0c5a0b369a4f6ae0..c608346d7991c974ee02647586f29c5a8b28eb28 100644 --- a/crates/contacts_panel/src/contact_notification.rs +++ b/crates/contacts_panel/src/contact_notification.rs @@ -21,10 +21,10 @@ pub struct ContactNotification { kind: client::ContactEventKind, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] struct Dismiss(u64); -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct RespondToContactRequest { pub user_id: u64, pub accept: bool, diff --git a/crates/contacts_panel/src/contacts_panel.rs b/crates/contacts_panel/src/contacts_panel.rs index 261a95c5ed884f6ea8927bb3e8a587002bb9fb15..e1838f9a1cb9aef17e56a0c0d8c1dd5c8ffcbdf1 100644 --- a/crates/contacts_panel/src/contacts_panel.rs +++ b/crates/contacts_panel/src/contacts_panel.rs @@ -48,7 +48,7 @@ enum ContactEntry { OfflineProject(WeakModelHandle), } -#[derive(Clone)] +#[derive(Clone, PartialEq)] struct ToggleExpanded(Section); pub struct ContactsPanel { @@ -63,13 +63,13 @@ pub struct ContactsPanel { _maintain_contacts: Subscription, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct RequestContact(pub u64); -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct RemoveContact(pub u64); -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct RespondToContactRequest { pub user_id: u64, pub accept: bool, diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index f39eab68adccb650fcf2d7aba173bc3e2250af6f..c42d813468494d5c957772d2e73718c8621ac0d7 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -60,7 +60,7 @@ struct PathState { diagnostic_groups: Vec, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] struct Jump { path: ProjectPath, position: Point, diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 32773c9d28ac010c39e9b05a8183df96a202e3fb..db287fe65af736f0ed46a5c071fe0b1a75a2efc7 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -65,49 +65,49 @@ const MAX_LINE_LEN: usize = 1024; const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10; const MAX_SELECTION_HISTORY_LEN: usize = 1024; -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct SelectNext { #[serde(default)] pub replace_newest: bool, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct GoToDiagnostic(pub Direction); -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct Scroll(pub Vector2F); -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct Select(pub SelectPhase); -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct Input(pub String); -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct SelectToBeginningOfLine { #[serde(default)] stop_at_soft_wraps: bool, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct SelectToEndOfLine { #[serde(default)] stop_at_soft_wraps: bool, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct ToggleCodeActions { #[serde(default)] pub deployed_from_indicator: bool, } -#[derive(Clone, Default, Deserialize)] +#[derive(Clone, Default, Deserialize, PartialEq)] pub struct ConfirmCompletion { #[serde(default)] pub item_ix: Option, } -#[derive(Clone, Default, Deserialize)] +#[derive(Clone, Default, Deserialize, PartialEq)] pub struct ConfirmCodeAction { #[serde(default)] pub item_ix: Option, @@ -307,7 +307,7 @@ trait InvalidationRegion { fn ranges(&self) -> &[Range]; } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum SelectPhase { Begin { position: DisplayPoint, diff --git a/crates/gpui/src/app/action.rs b/crates/gpui/src/app/action.rs index fc5bd616eef5581f739f452ffb53a2843f18245b..069cdebd5d6ec67ebe38ef5a1b669386e8dfc53f 100644 --- a/crates/gpui/src/app/action.rs +++ b/crates/gpui/src/app/action.rs @@ -5,6 +5,7 @@ pub trait Action: 'static { fn name(&self) -> &'static str; fn as_any(&self) -> &dyn Any; fn boxed_clone(&self) -> Box; + fn eq(&self, other: &dyn Action) -> bool; fn qualified_name() -> &'static str where @@ -103,6 +104,14 @@ macro_rules! __impl_action { Box::new(self.clone()) } + fn eq(&self, other: &dyn $crate::Action) -> bool { + if let Some(other) = other.as_any().downcast_ref::() { + self == other + } else { + false + } + } + $from_json_fn } }; diff --git a/crates/gpui/src/views/select.rs b/crates/gpui/src/views/select.rs index 80c3ba28847e616e5727a3fd040af50976420568..21527a1f2ccda29de56feee600d261e2d05d1edb 100644 --- a/crates/gpui/src/views/select.rs +++ b/crates/gpui/src/views/select.rs @@ -27,7 +27,7 @@ pub enum ItemType { Unselected, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct SelectItem(pub usize); actions!(select, [ToggleSelect]); diff --git a/crates/menu/src/menu.rs b/crates/menu/src/menu.rs index c37ad530bbfb13d0b2c9cc18e50b7f6ff62e1369..227e6c6c285a342232a6952f39692e1843d25170 100644 --- a/crates/menu/src/menu.rs +++ b/crates/menu/src/menu.rs @@ -1,4 +1,4 @@ -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct SelectIndex(pub usize); gpui::actions!( diff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rs index cf8fd1d0c8708dae4103a8320926e40f9140a138..48901043f2cd5b7fb0fb026b6fda22e47ec48253 100644 --- a/crates/project_panel/src/project_panel.rs +++ b/crates/project_panel/src/project_panel.rs @@ -81,16 +81,16 @@ struct EntryDetails { is_cut: bool, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct ToggleExpanded(pub ProjectEntryId); -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct Open { pub entry_id: ProjectEntryId, pub change_focus: bool, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct DeployContextMenu { pub position: Vector2F, pub entry_id: Option, diff --git a/crates/search/src/buffer_search.rs b/crates/search/src/buffer_search.rs index 94b6261a0f11c3b4ba56333a22365fdf6fb3a79a..b5c7e7622d361bcf5436ed5caf6c2b27b140ff2a 100644 --- a/crates/search/src/buffer_search.rs +++ b/crates/search/src/buffer_search.rs @@ -16,12 +16,12 @@ use settings::Settings; use std::ops::Range; use workspace::{ItemHandle, Pane, ToolbarItemLocation, ToolbarItemView}; -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct Deploy { pub focus: bool, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct ToggleSearchOption(pub SearchOption); actions!(buffer_search, [Dismiss, FocusEditor]); diff --git a/crates/search/src/search.rs b/crates/search/src/search.rs index 48cf24b1f340f700b9e42b76952eff6e84463a76..e4623c29677577648fceaf2bc094bbb09646ebe9 100644 --- a/crates/search/src/search.rs +++ b/crates/search/src/search.rs @@ -15,13 +15,13 @@ pub fn init(cx: &mut MutableAppContext) { project_search::init(cx); } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct ToggleSearchOption(pub SearchOption); actions!(search, [SelectNextMatch, SelectPrevMatch]); impl_internal_actions!(search, [ToggleSearchOption]); -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq)] pub enum SearchOption { WholeWord, CaseSensitive, diff --git a/crates/vim/src/motion.rs b/crates/vim/src/motion.rs index 221898c056220246cfd59d56b50f23639ce5953e..30c6c78c05d292012c527baf03fd25c3bd611d32 100644 --- a/crates/vim/src/motion.rs +++ b/crates/vim/src/motion.rs @@ -32,21 +32,21 @@ pub enum Motion { EndOfDocument, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] struct NextWordStart { #[serde(default)] ignore_punctuation: bool, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] struct NextWordEnd { #[serde(default)] ignore_punctuation: bool, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] struct PreviousWordStart { #[serde(default)] diff --git a/crates/vim/src/normal/change.rs b/crates/vim/src/normal/change.rs index 7f417fd31ed3167097e6eeeff52f14fc9024b690..9f526744d017fae5c31f0e5381475ee8dc331e61 100644 --- a/crates/vim/src/normal/change.rs +++ b/crates/vim/src/normal/change.rs @@ -4,7 +4,7 @@ use gpui::{impl_actions, MutableAppContext, ViewContext}; use serde::Deserialize; use workspace::Workspace; -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] #[serde(rename_all = "camelCase")] struct ChangeWord { #[serde(default)] diff --git a/crates/vim/src/vim.rs b/crates/vim/src/vim.rs index 89647b56e29f3e83c8174309e731850f9656f961..a767f87d8dc161123b6ed3d215516fa766c43a56 100644 --- a/crates/vim/src/vim.rs +++ b/crates/vim/src/vim.rs @@ -18,10 +18,10 @@ use settings::Settings; use state::{Mode, Operator, VimState}; use workspace::{self, Workspace}; -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct SwitchMode(pub Mode); -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct PushOperator(pub Operator); impl_actions!(vim, [SwitchMode, PushOperator]); diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index e712b4a1fb83ac2ba565e1b21604d39ce10a8d2c..25d992121e9dd092b06b6a2c2d8c770565ba269b 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -28,25 +28,25 @@ actions!( ] ); -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct Split(pub SplitDirection); -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct CloseItem { pub item_id: usize, pub pane: WeakViewHandle, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct ActivateItem(pub usize); -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct GoBack { #[serde(skip_deserializing)] pub pane: Option>, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct GoForward { #[serde(skip_deserializing)] pub pane: Option>, diff --git a/crates/workspace/src/pane_group.rs b/crates/workspace/src/pane_group.rs index a17805822f75cb351d519727b283d2f6e1f349d6..025d561f61d1fa40344b0aa22a2d0991f888b7b1 100644 --- a/crates/workspace/src/pane_group.rs +++ b/crates/workspace/src/pane_group.rs @@ -255,7 +255,7 @@ impl PaneAxis { } } -#[derive(Clone, Copy, Debug, Deserialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq)] pub enum SplitDirection { Up, Down, diff --git a/crates/workspace/src/sidebar.rs b/crates/workspace/src/sidebar.rs index 9aaf2b832ab49d6f44ca5fd3293c15f12574aa7f..7eec00fc4c01ae097990be24ea2eea95df3eb406 100644 --- a/crates/workspace/src/sidebar.rs +++ b/crates/workspace/src/sidebar.rs @@ -60,7 +60,7 @@ pub struct Sidebar { custom_width: Rc>, } -#[derive(Clone, Copy, Debug, Deserialize)] +#[derive(Clone, Copy, Debug, Deserialize, PartialEq)] pub enum Side { Left, Right, @@ -76,13 +76,13 @@ pub struct SidebarButtons { sidebar: ViewHandle, } -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize, PartialEq)] pub struct ToggleSidebarItem { pub side: Side, pub item_index: usize, } -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize, PartialEq)] pub struct ToggleSidebarItemFocus { pub side: Side, pub item_index: usize, diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index 7d4f451771e5e0a2ce237417bed3f31c5cbfe032..1c4f703be9013971207c517d5b67c3397c5ad143 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -73,7 +73,7 @@ type FollowableItemBuilders = HashMap< ), >; -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct RemoveFolderFromProject(pub WorktreeId); actions!( @@ -94,21 +94,21 @@ actions!( ] ); -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct OpenPaths { pub paths: Vec, } -#[derive(Clone, Deserialize)] +#[derive(Clone, Deserialize, PartialEq)] pub struct ToggleProjectOnline { #[serde(skip_deserializing)] pub project: Option>, } -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct ToggleFollow(pub PeerId); -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct JoinProject { pub contact: Arc, pub project_index: usize, diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 5261d191a3316b8ce61a53210119255629dc77af..b913e4621d109f603c27a3d92dae9063db949bbb 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -35,7 +35,7 @@ use util::ResultExt; pub use workspace; use workspace::{AppState, Workspace}; -#[derive(Deserialize, Clone)] +#[derive(Deserialize, Clone, PartialEq)] struct OpenBrowser { url: Arc, }