Restore namespace parameter to actions!

This does not yet fix `derive(Action)`, but will conflict with a lot so
wanted to merge quickly.
This commit is contained in:
Conrad Irwin 2023-12-09 13:25:15 -07:00
parent 188d727d31
commit 4290c67b6a
43 changed files with 399 additions and 304 deletions

View file

@ -14,7 +14,7 @@ use ui::h_stack;
use util::ResultExt; use util::ResultExt;
use workspace::{item::ItemHandle, StatusItemView, Workspace}; use workspace::{item::ItemHandle, StatusItemView, Workspace};
actions!(ShowErrorMessage); actions!(activity_indicator, [ShowErrorMessage]);
const DOWNLOAD_ICON: &str = "icons/download.svg"; const DOWNLOAD_ICON: &str = "icons/download.svg";
const WARNING_ICON: &str = "icons/warning.svg"; const WARNING_ICON: &str = "icons/warning.svg";

View file

@ -19,6 +19,8 @@ use std::{cmp::Reverse, ffi::OsStr, path::PathBuf, sync::Arc};
use util::paths::CONVERSATIONS_DIR; use util::paths::CONVERSATIONS_DIR;
actions!( actions!(
assistant,
[
NewConversation, NewConversation,
Assist, Assist,
Split, Split,
@ -29,6 +31,7 @@ actions!(
InlineAssist, InlineAssist,
ToggleIncludeConversation, ToggleIncludeConversation,
ToggleRetrieveContext, ToggleRetrieveContext,
]
); );
#[derive( #[derive(

View file

@ -26,10 +26,13 @@ const POLL_INTERVAL: Duration = Duration::from_secs(60 * 60);
//todo!(remove CheckThatAutoUpdaterWorks) //todo!(remove CheckThatAutoUpdaterWorks)
actions!( actions!(
auto_update,
[
Check, Check,
DismissErrorMessage, DismissErrorMessage,
ViewReleaseNotes, ViewReleaseNotes,
CheckThatAutoUpdaterWorks CheckThatAutoUpdaterWorks
]
); );
#[derive(Serialize)] #[derive(Serialize)]

View file

@ -70,7 +70,7 @@ pub const ZED_SECRET_CLIENT_TOKEN: &str = "618033988749894";
pub const INITIAL_RECONNECTION_DELAY: Duration = Duration::from_millis(100); pub const INITIAL_RECONNECTION_DELAY: Duration = Duration::from_millis(100);
pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(5); pub const CONNECTION_TIMEOUT: Duration = Duration::from_secs(5);
actions!(SignIn, SignOut, Reconnect); actions!(client, [SignIn, SignOut, Reconnect]);
pub fn init_settings(cx: &mut AppContext) { pub fn init_settings(cx: &mut AppContext) {
TelemetrySettings::register(cx); TelemetrySettings::register(cx);

View file

@ -26,7 +26,7 @@ use workspace::{
ItemNavHistory, Pane, SaveIntent, ViewId, Workspace, WorkspaceId, ItemNavHistory, Pane, SaveIntent, ViewId, Workspace, WorkspaceId,
}; };
actions!(Deploy); actions!(collab, [Deploy]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
register_followable_item::<ChannelView>(cx) register_followable_item::<ChannelView>(cx)

View file

@ -75,7 +75,7 @@ pub enum Event {
Dismissed, Dismissed,
} }
actions!(ToggleFocus); actions!(chat_panel, [ToggleFocus]);
impl ChatPanel { impl ChatPanel {
pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> { pub fn new(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {

View file

@ -123,6 +123,8 @@ pub struct OpenChannelNotes {
// } // }
actions!( actions!(
collab_panel,
[
ToggleFocus, ToggleFocus,
Remove, Remove,
Secondary, Secondary,
@ -131,6 +133,7 @@ actions!(
StartMoveChannel, StartMoveChannel,
MoveSelected, MoveSelected,
InsertSpace, InsertSpace,
]
); );
// impl_actions!( // impl_actions!(

View file

@ -16,10 +16,13 @@ use util::TryFutureExt;
use workspace::ModalView; use workspace::ModalView;
actions!( actions!(
channel_modal,
[
SelectNextControl, SelectNextControl,
ToggleMode, ToggleMode,
ToggleMemberAdmin, ToggleMemberAdmin,
RemoveMember RemoveMember
]
); );
// pub fn init(cx: &mut AppContext) { // pub fn init(cx: &mut AppContext) {

View file

@ -20,11 +20,14 @@ const MAX_PROJECT_NAME_LENGTH: usize = 40;
const MAX_BRANCH_NAME_LENGTH: usize = 40; const MAX_BRANCH_NAME_LENGTH: usize = 40;
actions!( actions!(
collab,
[
ShareProject, ShareProject,
UnshareProject, UnshareProject,
ToggleUserMenu, ToggleUserMenu,
ToggleProjectMenu, ToggleProjectMenu,
SwitchBranch SwitchBranch
]
); );
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {

View file

@ -24,7 +24,10 @@ use settings::Settings;
use util::ResultExt; use util::ResultExt;
use workspace::AppState; use workspace::AppState;
actions!(ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall); actions!(
collab,
[ToggleScreenSharing, ToggleMute, ToggleDeafen, LeaveCall]
);
pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) { pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {
CollaborationPanelSettings::register(cx); CollaborationPanelSettings::register(cx);

View file

@ -19,7 +19,7 @@ use util::{
use workspace::{ModalView, Workspace}; use workspace::{ModalView, Workspace};
use zed_actions::OpenZedURL; use zed_actions::OpenZedURL;
actions!(Toggle); actions!(command_palette, [Toggle]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.set_global(HitCounts::default()); cx.set_global(HitCounts::default());

View file

@ -34,12 +34,15 @@ use util::{
}; };
actions!( actions!(
copilot,
[
Suggest, Suggest,
NextSuggestion, NextSuggestion,
PreviousSuggestion, PreviousSuggestion,
Reinstall, Reinstall,
SignIn, SignIn,
SignOut SignOut
]
); );
pub fn init( pub fn init(

View file

@ -43,7 +43,7 @@ use workspace::{
ItemNavHistory, Pane, ToolbarItemLocation, Workspace, ItemNavHistory, Pane, ToolbarItemLocation, Workspace,
}; };
actions!(Deploy, ToggleWarnings); actions!(diagnostics, [Deploy, ToggleWarnings]);
const CONTEXT_LINE_COUNT: u32 = 1; const CONTEXT_LINE_COUNT: u32 = 1;

View file

@ -277,6 +277,8 @@ impl InlayId {
} }
actions!( actions!(
editor,
[
AddSelectionAbove, AddSelectionAbove,
AddSelectionBelow, AddSelectionBelow,
Backspace, Backspace,
@ -392,6 +394,7 @@ actions!(
Undo, Undo,
UndoSelection, UndoSelection,
UnfoldLines, UnfoldLines,
]
); );
enum DocumentHighlightRead {} enum DocumentHighlightRead {}

View file

@ -26,7 +26,7 @@ pub const MIN_POPOVER_CHARACTER_WIDTH: f32 = 20.;
pub const MIN_POPOVER_LINE_HEIGHT: Pixels = px(4.); pub const MIN_POPOVER_LINE_HEIGHT: Pixels = px(4.);
pub const HOVER_POPOVER_GAP: Pixels = px(10.); pub const HOVER_POPOVER_GAP: Pixels = px(10.);
actions!(Hover); actions!(editor, [Hover]);
/// Bindable action which uses the most recent selection head to trigger a hover /// Bindable action which uses the most recent selection head to trigger a hover
pub fn hover(editor: &mut Editor, _: &Hover, cx: &mut ViewContext<Editor>) { pub fn hover(editor: &mut Editor, _: &Hover, cx: &mut ViewContext<Editor>) {

View file

@ -5,15 +5,18 @@ use workspace::Workspace;
pub mod deploy_feedback_button; pub mod deploy_feedback_button;
pub mod feedback_modal; pub mod feedback_modal;
actions!(GiveFeedback, SubmitFeedback); actions!(feedback, [GiveFeedback, SubmitFeedback]);
mod system_specs; mod system_specs;
actions!( actions!(
zed,
[
CopySystemSpecsIntoClipboard, CopySystemSpecsIntoClipboard,
FileBugReport, FileBugReport,
RequestFeature, RequestFeature,
OpenZedCommunityRepo OpenZedCommunityRepo
]
); );
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {

View file

@ -19,7 +19,7 @@ use ui::{prelude::*, HighlightedLabel, ListItem};
use util::{paths::PathLikeWithPosition, post_inc, ResultExt}; use util::{paths::PathLikeWithPosition, post_inc, ResultExt};
use workspace::{ModalView, Workspace}; use workspace::{ModalView, Workspace};
actions!(Toggle); actions!(file_finder, [Toggle]);
impl ModalView for FileFinder {} impl ModalView for FileFinder {}

View file

@ -10,7 +10,7 @@ use ui::{h_stack, prelude::*, v_stack, Label};
use util::paths::FILE_ROW_COLUMN_DELIMITER; use util::paths::FILE_ROW_COLUMN_DELIMITER;
use workspace::ModalView; use workspace::ModalView;
actions!(Toggle); actions!(go_to_line, [Toggle]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(GoToLine::register).detach(); cx.observe_new_views(GoToLine::register).detach();

View file

@ -22,7 +22,7 @@ Actions are frequently unit structs, for which we have a macro. The above could
```rust ```rust
mod menu { mod menu {
actions!(MoveUp, MoveDown); actions!(gpui, [MoveUp, MoveDown]);
} }
``` ```

View file

@ -158,17 +158,65 @@ impl ActionRegistry {
/// To use more complex data types as actions, annotate your type with the #[action] macro. /// To use more complex data types as actions, annotate your type with the #[action] macro.
#[macro_export] #[macro_export]
macro_rules! actions { macro_rules! actions {
() => {}; ($namespace:path, [ $($name:ident),* $(,)? ]) => {
$(
( $name:ident ) => { #[derive(::std::cmp::PartialEq, ::std::clone::Clone, ::std::default::Default, gpui::serde_derive::Deserialize)]
#[derive(::std::cmp::PartialEq, ::std::clone::Clone, ::std::default::Default, gpui::serde_derive::Deserialize, gpui::Action)]
#[serde(crate = "gpui::serde")] #[serde(crate = "gpui::serde")]
#[gpui::register_action]
pub struct $name; pub struct $name;
};
( $name:ident, $($rest:tt)* ) => { gpui::__impl_action!($namespace, $name,
actions!($name); fn build(_: gpui::serde_json::Value) -> gpui::Result<::std::boxed::Box<dyn gpui::Action>> {
actions!($($rest)*); Ok(Box::new(Self))
}
);
)*
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __impl_action {
($namespace:path, $name:ident, $build:item) => {
impl gpui::Action for $name {
fn name(&self) -> &'static str
{
concat!(
stringify!($namespace),
"::",
stringify!($name),
)
}
// todo!() why is this needed in addition to name?
fn debug_name() -> &'static str
where
Self: ::std::marker::Sized
{
concat!(
stringify!($namespace),
"::",
stringify!($name),
)
}
$build
fn partial_eq(&self, action: &dyn gpui::Action) -> bool {
action
.as_any()
.downcast_ref::<Self>()
.map_or(false, |a| self == a)
}
fn boxed_clone(&self) -> std::boxed::Box<dyn gpui::Action> {
::std::boxed::Box::new(self.clone())
}
fn as_any(&self) -> &dyn ::std::any::Any {
self
}
}
}; };
} }
@ -186,5 +234,5 @@ pub fn remove_the_2(action_name: &str) -> String {
mod no_action { mod no_action {
use crate as gpui; use crate as gpui;
actions!(NoAction); actions!(zed, [NoAction]);
} }

View file

@ -302,7 +302,7 @@ mod test {
focus_handle: FocusHandle, focus_handle: FocusHandle,
} }
actions!(TestAction); actions!(test, [TestAction]);
impl Render for TestView { impl Render for TestView {
type Element = Stateful<Div>; type Element = Stateful<Div>;

View file

@ -293,11 +293,13 @@ mod tests {
#[test] #[test]
fn test_actions_definition() { fn test_actions_definition() {
{ {
actions!(A, B, C, D, E, F, G); actions!(test, [A, B, C, D, E, F, G]);
} }
{ {
actions!( actions!(
test,
[
A, A,
B, B,
C, C,
@ -305,6 +307,7 @@ mod tests {
E, E,
F, F,
G, // Don't wrap, test the trailing comma G, // Don't wrap, test the trailing comma
]
); );
} }
} }

View file

@ -78,7 +78,7 @@ pub(crate) fn register_action(type_name: &Ident) -> proc_macro2::TokenStream {
#[doc(hidden)] #[doc(hidden)]
fn #action_builder_fn_name() -> gpui::ActionData { fn #action_builder_fn_name() -> gpui::ActionData {
gpui::ActionData { gpui::ActionData {
name: ::std::any::type_name::<#type_name>(), name: <#type_name as gpui::Action>::debug_name(),
type_id: ::std::any::TypeId::of::<#type_name>(), type_id: ::std::any::TypeId::of::<#type_name>(),
build: <#type_name as gpui::Action>::build, build: <#type_name as gpui::Action>::build,
} }

View file

@ -3,7 +3,7 @@ use gpui::{actions, AsyncAppContext};
use std::path::Path; use std::path::Path;
use util::ResultExt; use util::ResultExt;
actions!(Install); actions!(cli, [Install]);
pub async fn install_cli(cx: &AsyncAppContext) -> Result<()> { pub async fn install_cli(cx: &AsyncAppContext) -> Result<()> {
let cli_path = cx.update(|cx| cx.path_for_auxiliary_executable("cli"))??; let cli_path = cx.update(|cx| cx.path_for_auxiliary_executable("cli"))??;

View file

@ -16,7 +16,7 @@ use ui::{prelude::*, HighlightedLabel, ListItem};
use util::ResultExt; use util::ResultExt;
use workspace::{ModalView, Workspace}; use workspace::{ModalView, Workspace};
actions!(Toggle); actions!(language_selector, [Toggle]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(LanguageSelector::register).detach(); cx.observe_new_views(LanguageSelector::register).detach();

View file

@ -10,6 +10,8 @@ use gpui::actions;
pub fn init() {} pub fn init() {}
actions!( actions!(
menu,
[
Cancel, Cancel,
Confirm, Confirm,
SecondaryConfirm, SecondaryConfirm,
@ -18,4 +20,5 @@ actions!(
SelectFirst, SelectFirst,
SelectLast, SelectLast,
ShowContextMenu ShowContextMenu
]
); );

View file

@ -22,7 +22,7 @@ use ui::{prelude::*, ListItem};
use util::ResultExt; use util::ResultExt;
use workspace::{ModalView, Workspace}; use workspace::{ModalView, Workspace};
actions!(Toggle); actions!(outline, [Toggle]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(OutlineView::register).detach(); cx.observe_new_views(OutlineView::register).detach();

View file

@ -103,6 +103,8 @@ pub struct EntryDetails {
} }
actions!( actions!(
project_panel,
[
ExpandSelectedEntry, ExpandSelectedEntry,
CollapseSelectedEntry, CollapseSelectedEntry,
CollapseAllEntries, CollapseAllEntries,
@ -120,6 +122,7 @@ actions!(
Open, Open,
ToggleFocus, ToggleFocus,
NewSearchInDirectory, NewSearchInDirectory,
]
); );
pub fn init_settings(cx: &mut AppContext) { pub fn init_settings(cx: &mut AppContext) {

View file

@ -1 +1 @@
gpui::actions!(OpenRecent); gpui::actions!(projects, [OpenRecent]);

View file

@ -31,7 +31,7 @@ pub struct Deploy {
pub focus: bool, pub focus: bool,
} }
actions!(Dismiss, FocusEditor); actions!(buffer_search, [Dismiss, FocusEditor]);
pub enum Event { pub enum Event {
UpdateLocation, UpdateLocation,

View file

@ -22,6 +22,8 @@ pub fn init(cx: &mut AppContext) {
} }
actions!( actions!(
search,
[
CycleMode, CycleMode,
ToggleWholeWord, ToggleWholeWord,
ToggleCaseSensitive, ToggleCaseSensitive,
@ -36,6 +38,7 @@ actions!(
ActivateRegexMode, ActivateRegexMode,
ReplaceAll, ReplaceAll,
ReplaceNext, ReplaceNext,
]
); );
bitflags! { bitflags! {

View file

@ -1,7 +1,7 @@
use crate::{settings_store::parse_json_with_comments, SettingsAssets}; use crate::{settings_store::parse_json_with_comments, SettingsAssets};
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use collections::BTreeMap; use collections::BTreeMap;
use gpui::{actions, Action, AppContext, KeyBinding, SharedString}; use gpui::{Action, AppContext, KeyBinding, SharedString};
use schemars::{ use schemars::{
gen::{SchemaGenerator, SchemaSettings}, gen::{SchemaGenerator, SchemaSettings},
schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation}, schema::{InstanceType, Schema, SchemaObject, SingleOrVec, SubschemaValidation},
@ -137,10 +137,8 @@ impl KeymapFile {
} }
} }
actions!(NoAction);
fn no_action() -> Box<dyn gpui::Action> { fn no_action() -> Box<dyn gpui::Action> {
NoAction.boxed_clone() gpui::NoAction.boxed_clone()
} }
#[cfg(test)] #[cfg(test)]

View file

@ -4,7 +4,7 @@ use gpui::{
}; };
use ui::prelude::*; use ui::prelude::*;
actions!(ActionA, ActionB, ActionC); actions!(focus, [ActionA, ActionB, ActionC]);
pub struct FocusStory { pub struct FocusStory {
child_1_focus: FocusHandle, child_1_focus: FocusHandle,

View file

@ -59,6 +59,8 @@ use crate::mappings::{colors::to_alac_rgb, keys::to_esc_str};
use lazy_static::lazy_static; use lazy_static::lazy_static;
actions!( actions!(
terminal,
[
Clear, Clear,
Copy, Copy,
Paste, Paste,
@ -66,6 +68,7 @@ actions!(
SearchTest, SearchTest,
SendText, SendText,
SendKeystroke, SendKeystroke,
]
); );
///Scrolling is unbearably sluggish by default. Alacritty supports a configurable ///Scrolling is unbearably sluggish by default. Alacritty supports a configurable

View file

@ -24,7 +24,7 @@ use anyhow::Result;
const TERMINAL_PANEL_KEY: &'static str = "TerminalPanel"; const TERMINAL_PANEL_KEY: &'static str = "TerminalPanel";
actions!(ToggleFocus); actions!(terminal_view, [ToggleFocus]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views( cx.observe_new_views(

View file

@ -13,7 +13,7 @@ use ui::{prelude::*, v_stack, ListItem};
use util::ResultExt; use util::ResultExt;
use workspace::{ui::HighlightedLabel, ModalView, Workspace}; use workspace::{ui::HighlightedLabel, ModalView, Workspace};
actions!(Toggle, Reload); actions!(theme_selector, [Toggle, Reload]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views( cx.observe_new_views(

View file

@ -4,7 +4,7 @@ use story::Story;
use crate::prelude::*; use crate::prelude::*;
use crate::{right_click_menu, ContextMenu, Label}; use crate::{right_click_menu, ContextMenu, Label};
actions!(PrintCurrentDate, PrintBestFood); actions!(context_menu, [PrintCurrentDate, PrintBestFood]);
fn build_menu(cx: &mut WindowContext, header: impl Into<SharedString>) -> View<ContextMenu> { fn build_menu(cx: &mut WindowContext, header: impl Into<SharedString>) -> View<ContextMenu> {
ContextMenu::build(cx, |menu, _| { ContextMenu::build(cx, |menu, _| {

View file

@ -1,4 +1,5 @@
use gpui::{actions, Div, Render}; use gpui::NoAction;
use gpui::{Div, Render};
use itertools::Itertools; use itertools::Itertools;
use story::Story; use story::Story;
@ -7,8 +8,6 @@ use crate::KeyBinding;
pub struct KeybindingStory; pub struct KeybindingStory;
actions!(NoAction);
pub fn binding(key: &str) -> gpui::KeyBinding { pub fn binding(key: &str) -> gpui::KeyBinding {
gpui::KeyBinding::new(key, NoAction {}, None) gpui::KeyBinding::new(key, NoAction {}, None)
} }

View file

@ -12,7 +12,7 @@ use ui::{prelude::*, ListItem};
use util::ResultExt; use util::ResultExt;
use workspace::{ui::HighlightedLabel, ModalView, Workspace}; use workspace::{ui::HighlightedLabel, ModalView, Workspace};
actions!(ToggleBaseKeymapSelector); actions!(welcome, [ToggleBaseKeymapSelector]);
pub fn init(cx: &mut AppContext) { pub fn init(cx: &mut AppContext) {
cx.observe_new_views(|workspace: &mut Workspace, _cx| { cx.observe_new_views(|workspace: &mut Workspace, _cx| {

View file

@ -770,7 +770,7 @@ pub mod test {
pub focus_handle: FocusHandle, pub focus_handle: FocusHandle,
pub size: f32, pub size: f32,
} }
actions!(ToggleTestPanel); actions!(test, [ToggleTestPanel]);
impl EventEmitter<PanelEvent> for TestPanel {} impl EventEmitter<PanelEvent> for TestPanel {}

View file

@ -87,8 +87,9 @@ pub struct CloseAllItems {
pub save_intent: Option<SaveIntent>, pub save_intent: Option<SaveIntent>,
} }
// todo!(These used to be under pane::{Action}. Are they now workspace::pane::{Action}?)
actions!( actions!(
pane,
[
ActivatePrevItem, ActivatePrevItem,
ActivateNextItem, ActivateNextItem,
ActivateLastItem, ActivateLastItem,
@ -103,6 +104,7 @@ actions!(
SplitUp, SplitUp,
SplitRight, SplitRight,
SplitDown, SplitDown,
]
); );
const MAX_NAVIGATION_HISTORY_LEN: usize = 1024; const MAX_NAVIGATION_HISTORY_LEN: usize = 1024;

View file

@ -91,6 +91,8 @@ lazy_static! {
pub struct RemoveWorktreeFromProject(pub WorktreeId); pub struct RemoveWorktreeFromProject(pub WorktreeId);
actions!( actions!(
workspace,
[
Open, Open,
NewFile, NewFile,
NewWindow, NewWindow,
@ -115,6 +117,7 @@ actions!(
ToggleRightDock, ToggleRightDock,
ToggleBottomDock, ToggleBottomDock,
CloseAllDocks, CloseAllDocks,
]
); );
#[derive(Clone, PartialEq)] #[derive(Clone, PartialEq)]

View file

@ -43,6 +43,8 @@ use workspace::{
use zed_actions::{OpenBrowser, OpenZedURL}; use zed_actions::{OpenBrowser, OpenZedURL};
actions!( actions!(
zed,
[
About, About,
DebugElements, DebugElements,
DecreaseBufferFontSize, DecreaseBufferFontSize,
@ -64,6 +66,7 @@ actions!(
ShowAll, ShowAll,
ToggleFullScreen, ToggleFullScreen,
Zoom, Zoom,
]
); );
pub fn build_window_options( pub fn build_window_options(