lib.rs

  1use gpui::{actions, impl_actions};
  2use schemars::JsonSchema;
  3use serde::{Deserialize, Serialize};
  4
  5// If the zed binary doesn't use anything in this crate, it will be optimized away
  6// and the actions won't initialize. So we just provide an empty initialization function
  7// to be called from main.
  8//
  9// These may provide relevant context:
 10// https://github.com/rust-lang/rust/issues/47384
 11// https://github.com/mmastrac/rust-ctor/issues/280
 12pub fn init() {}
 13
 14#[derive(Clone, PartialEq, Deserialize, JsonSchema)]
 15#[serde(deny_unknown_fields)]
 16pub struct OpenBrowser {
 17    pub url: String,
 18}
 19
 20#[derive(Clone, PartialEq, Deserialize, JsonSchema)]
 21#[serde(deny_unknown_fields)]
 22pub struct OpenZedUrl {
 23    pub url: String,
 24}
 25
 26impl_actions!(zed, [OpenBrowser, OpenZedUrl]);
 27
 28actions!(
 29    zed,
 30    [
 31        OpenSettings,
 32        OpenDefaultKeymap,
 33        OpenAccountSettings,
 34        OpenServerSettings,
 35        Quit,
 36        OpenKeymap,
 37        About,
 38        Extensions,
 39        OpenLicenses,
 40        OpenTelemetryLog,
 41    ]
 42);
 43
 44#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 45pub struct DecreaseBufferFontSize {
 46    #[serde(default)]
 47    pub persist: bool,
 48}
 49
 50#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 51pub struct IncreaseBufferFontSize {
 52    #[serde(default)]
 53    pub persist: bool,
 54}
 55
 56#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 57pub struct ResetBufferFontSize {
 58    #[serde(default)]
 59    pub persist: bool,
 60}
 61
 62#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 63pub struct DecreaseUiFontSize {
 64    #[serde(default)]
 65    pub persist: bool,
 66}
 67
 68#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 69pub struct IncreaseUiFontSize {
 70    #[serde(default)]
 71    pub persist: bool,
 72}
 73
 74#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 75pub struct ResetUiFontSize {
 76    #[serde(default)]
 77    pub persist: bool,
 78}
 79
 80impl_actions!(
 81    zed,
 82    [
 83        DecreaseBufferFontSize,
 84        IncreaseBufferFontSize,
 85        ResetBufferFontSize,
 86        DecreaseUiFontSize,
 87        IncreaseUiFontSize,
 88        ResetUiFontSize
 89    ]
 90);
 91
 92pub mod git {
 93    use gpui::action_with_deprecated_aliases;
 94
 95    action_with_deprecated_aliases!(git, Branch, ["branches::OpenRecent"]);
 96}
 97
 98pub mod command_palette {
 99    use gpui::actions;
100
101    actions!(command_palette, [Toggle]);
102}
103
104pub mod feedback {
105    use gpui::actions;
106
107    actions!(feedback, [GiveFeedback]);
108}
109
110pub mod theme_selector {
111    use gpui::impl_actions;
112    use schemars::JsonSchema;
113    use serde::Deserialize;
114
115    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
116    #[serde(deny_unknown_fields)]
117    pub struct Toggle {
118        /// A list of theme names to filter the theme selector down to.
119        pub themes_filter: Option<Vec<String>>,
120    }
121
122    impl_actions!(theme_selector, [Toggle]);
123}
124
125pub mod icon_theme_selector {
126    use gpui::impl_actions;
127    use schemars::JsonSchema;
128    use serde::Deserialize;
129
130    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
131    #[serde(deny_unknown_fields)]
132    pub struct Toggle {
133        /// A list of icon theme names to filter the theme selector down to.
134        pub themes_filter: Option<Vec<String>>,
135    }
136
137    impl_actions!(icon_theme_selector, [Toggle]);
138}
139
140pub mod assistant {
141    use gpui::{actions, impl_actions};
142    use schemars::JsonSchema;
143    use serde::Deserialize;
144
145    actions!(assistant, [ToggleFocus, DeployPromptLibrary]);
146
147    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)]
148    #[serde(deny_unknown_fields)]
149    pub struct InlineAssist {
150        pub prompt: Option<String>,
151    }
152
153    impl_actions!(assistant, [InlineAssist]);
154}
155
156#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
157#[serde(deny_unknown_fields)]
158pub struct OpenRecent {
159    #[serde(default)]
160    pub create_new_window: bool,
161}
162
163impl_actions!(projects, [OpenRecent]);
164actions!(projects, [OpenRemote]);
165
166/// Where to spawn the task in the UI.
167#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
168#[serde(rename_all = "snake_case")]
169pub enum RevealTarget {
170    /// In the central pane group, "main" editor area.
171    Center,
172    /// In the terminal dock, "regular" terminal items' place.
173    #[default]
174    Dock,
175}
176
177/// Spawn a task with name or open tasks modal.
178#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema)]
179#[serde(untagged)]
180pub enum Spawn {
181    /// Spawns a task by the name given.
182    ByName {
183        task_name: String,
184        #[serde(default)]
185        reveal_target: Option<RevealTarget>,
186    },
187    /// Spawns a task via modal's selection.
188    ViaModal {
189        /// Selected task's `reveal_target` property override.
190        #[serde(default)]
191        reveal_target: Option<RevealTarget>,
192    },
193}
194
195impl Spawn {
196    pub fn modal() -> Self {
197        Self::ViaModal {
198            reveal_target: None,
199        }
200    }
201}
202
203/// Rerun the last task.
204#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
205#[serde(deny_unknown_fields)]
206pub struct Rerun {
207    /// Controls whether the task context is reevaluated prior to execution of a task.
208    /// If it is not, environment variables such as ZED_COLUMN, ZED_FILE are gonna be the same as in the last execution of a task
209    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
210    /// default: false
211    #[serde(default)]
212    pub reevaluate_context: bool,
213    /// Overrides `allow_concurrent_runs` property of the task being reran.
214    /// Default: null
215    #[serde(default)]
216    pub allow_concurrent_runs: Option<bool>,
217    /// Overrides `use_new_terminal` property of the task being reran.
218    /// Default: null
219    #[serde(default)]
220    pub use_new_terminal: Option<bool>,
221
222    /// If present, rerun the task with this ID, otherwise rerun the last task.
223    #[serde(skip)]
224    pub task_id: Option<String>,
225}
226
227impl_actions!(task, [Spawn, Rerun]);
228
229pub mod outline {
230    use std::sync::OnceLock;
231
232    use gpui::{action_as, AnyView, App, Window};
233
234    action_as!(outline, ToggleOutline as Toggle);
235    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
236    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
237}
238
239actions!(zed_predict_onboarding, [OpenZedPredictOnboarding]);