Require that PartialEq is implemented for Action

This commit is contained in:
Antonio Scandurra 2022-06-06 09:18:44 +02:00
parent eae7c2267c
commit 3a69943df3
19 changed files with 58 additions and 49 deletions

View File

@ -35,7 +35,7 @@ impl PartialEq for User {
impl Eq for User {} impl Eq for User {}
#[derive(Debug)] #[derive(Debug, PartialEq)]
pub struct Contact { pub struct Contact {
pub user: Arc<User>, pub user: Arc<User>,
pub online: bool, pub online: bool,

View File

@ -21,10 +21,10 @@ pub struct ContactNotification {
kind: client::ContactEventKind, kind: client::ContactEventKind,
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
struct Dismiss(u64); struct Dismiss(u64);
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct RespondToContactRequest { pub struct RespondToContactRequest {
pub user_id: u64, pub user_id: u64,
pub accept: bool, pub accept: bool,

View File

@ -48,7 +48,7 @@ enum ContactEntry {
OfflineProject(WeakModelHandle<Project>), OfflineProject(WeakModelHandle<Project>),
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
struct ToggleExpanded(Section); struct ToggleExpanded(Section);
pub struct ContactsPanel { pub struct ContactsPanel {
@ -63,13 +63,13 @@ pub struct ContactsPanel {
_maintain_contacts: Subscription, _maintain_contacts: Subscription,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct RequestContact(pub u64); pub struct RequestContact(pub u64);
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct RemoveContact(pub u64); pub struct RemoveContact(pub u64);
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct RespondToContactRequest { pub struct RespondToContactRequest {
pub user_id: u64, pub user_id: u64,
pub accept: bool, pub accept: bool,

View File

@ -60,7 +60,7 @@ struct PathState {
diagnostic_groups: Vec<DiagnosticGroupState>, diagnostic_groups: Vec<DiagnosticGroupState>,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq)]
struct Jump { struct Jump {
path: ProjectPath, path: ProjectPath,
position: Point, position: Point,

View File

@ -65,49 +65,49 @@ const MAX_LINE_LEN: usize = 1024;
const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10; const MIN_NAVIGATION_HISTORY_ROW_DELTA: i64 = 10;
const MAX_SELECTION_HISTORY_LEN: usize = 1024; const MAX_SELECTION_HISTORY_LEN: usize = 1024;
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct SelectNext { pub struct SelectNext {
#[serde(default)] #[serde(default)]
pub replace_newest: bool, pub replace_newest: bool,
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct GoToDiagnostic(pub Direction); pub struct GoToDiagnostic(pub Direction);
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct Scroll(pub Vector2F); pub struct Scroll(pub Vector2F);
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct Select(pub SelectPhase); pub struct Select(pub SelectPhase);
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct Input(pub String); pub struct Input(pub String);
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct SelectToBeginningOfLine { pub struct SelectToBeginningOfLine {
#[serde(default)] #[serde(default)]
stop_at_soft_wraps: bool, stop_at_soft_wraps: bool,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct SelectToEndOfLine { pub struct SelectToEndOfLine {
#[serde(default)] #[serde(default)]
stop_at_soft_wraps: bool, stop_at_soft_wraps: bool,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct ToggleCodeActions { pub struct ToggleCodeActions {
#[serde(default)] #[serde(default)]
pub deployed_from_indicator: bool, pub deployed_from_indicator: bool,
} }
#[derive(Clone, Default, Deserialize)] #[derive(Clone, Default, Deserialize, PartialEq)]
pub struct ConfirmCompletion { pub struct ConfirmCompletion {
#[serde(default)] #[serde(default)]
pub item_ix: Option<usize>, pub item_ix: Option<usize>,
} }
#[derive(Clone, Default, Deserialize)] #[derive(Clone, Default, Deserialize, PartialEq)]
pub struct ConfirmCodeAction { pub struct ConfirmCodeAction {
#[serde(default)] #[serde(default)]
pub item_ix: Option<usize>, pub item_ix: Option<usize>,
@ -307,7 +307,7 @@ trait InvalidationRegion {
fn ranges(&self) -> &[Range<Anchor>]; fn ranges(&self) -> &[Range<Anchor>];
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug, PartialEq)]
pub enum SelectPhase { pub enum SelectPhase {
Begin { Begin {
position: DisplayPoint, position: DisplayPoint,

View File

@ -5,6 +5,7 @@ pub trait Action: 'static {
fn name(&self) -> &'static str; fn name(&self) -> &'static str;
fn as_any(&self) -> &dyn Any; fn as_any(&self) -> &dyn Any;
fn boxed_clone(&self) -> Box<dyn Action>; fn boxed_clone(&self) -> Box<dyn Action>;
fn eq(&self, other: &dyn Action) -> bool;
fn qualified_name() -> &'static str fn qualified_name() -> &'static str
where where
@ -103,6 +104,14 @@ macro_rules! __impl_action {
Box::new(self.clone()) Box::new(self.clone())
} }
fn eq(&self, other: &dyn $crate::Action) -> bool {
if let Some(other) = other.as_any().downcast_ref::<Self>() {
self == other
} else {
false
}
}
$from_json_fn $from_json_fn
} }
}; };

View File

@ -27,7 +27,7 @@ pub enum ItemType {
Unselected, Unselected,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct SelectItem(pub usize); pub struct SelectItem(pub usize);
actions!(select, [ToggleSelect]); actions!(select, [ToggleSelect]);

View File

@ -1,4 +1,4 @@
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct SelectIndex(pub usize); pub struct SelectIndex(pub usize);
gpui::actions!( gpui::actions!(

View File

@ -81,16 +81,16 @@ struct EntryDetails {
is_cut: bool, is_cut: bool,
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct ToggleExpanded(pub ProjectEntryId); pub struct ToggleExpanded(pub ProjectEntryId);
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct Open { pub struct Open {
pub entry_id: ProjectEntryId, pub entry_id: ProjectEntryId,
pub change_focus: bool, pub change_focus: bool,
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct DeployContextMenu { pub struct DeployContextMenu {
pub position: Vector2F, pub position: Vector2F,
pub entry_id: Option<ProjectEntryId>, pub entry_id: Option<ProjectEntryId>,

View File

@ -16,12 +16,12 @@ use settings::Settings;
use std::ops::Range; use std::ops::Range;
use workspace::{ItemHandle, Pane, ToolbarItemLocation, ToolbarItemView}; use workspace::{ItemHandle, Pane, ToolbarItemLocation, ToolbarItemView};
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct Deploy { pub struct Deploy {
pub focus: bool, pub focus: bool,
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct ToggleSearchOption(pub SearchOption); pub struct ToggleSearchOption(pub SearchOption);
actions!(buffer_search, [Dismiss, FocusEditor]); actions!(buffer_search, [Dismiss, FocusEditor]);

View File

@ -15,13 +15,13 @@ pub fn init(cx: &mut MutableAppContext) {
project_search::init(cx); project_search::init(cx);
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct ToggleSearchOption(pub SearchOption); pub struct ToggleSearchOption(pub SearchOption);
actions!(search, [SelectNextMatch, SelectPrevMatch]); actions!(search, [SelectNextMatch, SelectPrevMatch]);
impl_internal_actions!(search, [ToggleSearchOption]); impl_internal_actions!(search, [ToggleSearchOption]);
#[derive(Clone, Copy)] #[derive(Clone, Copy, PartialEq)]
pub enum SearchOption { pub enum SearchOption {
WholeWord, WholeWord,
CaseSensitive, CaseSensitive,

View File

@ -32,21 +32,21 @@ pub enum Motion {
EndOfDocument, EndOfDocument,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct NextWordStart { struct NextWordStart {
#[serde(default)] #[serde(default)]
ignore_punctuation: bool, ignore_punctuation: bool,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct NextWordEnd { struct NextWordEnd {
#[serde(default)] #[serde(default)]
ignore_punctuation: bool, ignore_punctuation: bool,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct PreviousWordStart { struct PreviousWordStart {
#[serde(default)] #[serde(default)]

View File

@ -4,7 +4,7 @@ use gpui::{impl_actions, MutableAppContext, ViewContext};
use serde::Deserialize; use serde::Deserialize;
use workspace::Workspace; use workspace::Workspace;
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
struct ChangeWord { struct ChangeWord {
#[serde(default)] #[serde(default)]

View File

@ -18,10 +18,10 @@ use settings::Settings;
use state::{Mode, Operator, VimState}; use state::{Mode, Operator, VimState};
use workspace::{self, Workspace}; use workspace::{self, Workspace};
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct SwitchMode(pub Mode); pub struct SwitchMode(pub Mode);
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct PushOperator(pub Operator); pub struct PushOperator(pub Operator);
impl_actions!(vim, [SwitchMode, PushOperator]); impl_actions!(vim, [SwitchMode, PushOperator]);

View File

@ -28,25 +28,25 @@ actions!(
] ]
); );
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct Split(pub SplitDirection); pub struct Split(pub SplitDirection);
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct CloseItem { pub struct CloseItem {
pub item_id: usize, pub item_id: usize,
pub pane: WeakViewHandle<Pane>, pub pane: WeakViewHandle<Pane>,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct ActivateItem(pub usize); pub struct ActivateItem(pub usize);
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct GoBack { pub struct GoBack {
#[serde(skip_deserializing)] #[serde(skip_deserializing)]
pub pane: Option<WeakViewHandle<Pane>>, pub pane: Option<WeakViewHandle<Pane>>,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct GoForward { pub struct GoForward {
#[serde(skip_deserializing)] #[serde(skip_deserializing)]
pub pane: Option<WeakViewHandle<Pane>>, pub pane: Option<WeakViewHandle<Pane>>,

View File

@ -255,7 +255,7 @@ impl PaneAxis {
} }
} }
#[derive(Clone, Copy, Debug, Deserialize)] #[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
pub enum SplitDirection { pub enum SplitDirection {
Up, Up,
Down, Down,

View File

@ -60,7 +60,7 @@ pub struct Sidebar {
custom_width: Rc<RefCell<f32>>, custom_width: Rc<RefCell<f32>>,
} }
#[derive(Clone, Copy, Debug, Deserialize)] #[derive(Clone, Copy, Debug, Deserialize, PartialEq)]
pub enum Side { pub enum Side {
Left, Left,
Right, Right,
@ -76,13 +76,13 @@ pub struct SidebarButtons {
sidebar: ViewHandle<Sidebar>, sidebar: ViewHandle<Sidebar>,
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct ToggleSidebarItem { pub struct ToggleSidebarItem {
pub side: Side, pub side: Side,
pub item_index: usize, pub item_index: usize,
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize, PartialEq)]
pub struct ToggleSidebarItemFocus { pub struct ToggleSidebarItemFocus {
pub side: Side, pub side: Side,
pub item_index: usize, pub item_index: usize,

View File

@ -73,7 +73,7 @@ type FollowableItemBuilders = HashMap<
), ),
>; >;
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct RemoveFolderFromProject(pub WorktreeId); pub struct RemoveFolderFromProject(pub WorktreeId);
actions!( actions!(
@ -94,21 +94,21 @@ actions!(
] ]
); );
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct OpenPaths { pub struct OpenPaths {
pub paths: Vec<PathBuf>, pub paths: Vec<PathBuf>,
} }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize, PartialEq)]
pub struct ToggleProjectOnline { pub struct ToggleProjectOnline {
#[serde(skip_deserializing)] #[serde(skip_deserializing)]
pub project: Option<ModelHandle<Project>>, pub project: Option<ModelHandle<Project>>,
} }
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct ToggleFollow(pub PeerId); pub struct ToggleFollow(pub PeerId);
#[derive(Clone)] #[derive(Clone, PartialEq)]
pub struct JoinProject { pub struct JoinProject {
pub contact: Arc<Contact>, pub contact: Arc<Contact>,
pub project_index: usize, pub project_index: usize,

View File

@ -35,7 +35,7 @@ use util::ResultExt;
pub use workspace; pub use workspace;
use workspace::{AppState, Workspace}; use workspace::{AppState, Workspace};
#[derive(Deserialize, Clone)] #[derive(Deserialize, Clone, PartialEq)]
struct OpenBrowser { struct OpenBrowser {
url: Arc<str>, url: Arc<str>,
} }