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 803fcf3703..c84af7c9f8 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 a1eeb365f5..c608346d79 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 261a95c5ed..e1838f9a1c 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 f39eab68ad..c42d813468 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 32773c9d28..db287fe65a 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 fc5bd616ee..069cdebd5d 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 80c3ba2884..21527a1f2c 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 c37ad530bb..227e6c6c28 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 cf8fd1d0c8..48901043f2 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 94b6261a0f..b5c7e7622d 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 48cf24b1f3..e4623c2967 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 221898c056..30c6c78c05 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 7f417fd31e..9f526744d0 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 89647b56e2..a767f87d8d 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 e712b4a1fb..25d992121e 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 a17805822f..025d561f61 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 9aaf2b832a..7eec00fc4c 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 7d4f451771..1c4f703be9 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 5261d191a3..b913e4621d 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, }