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 workspace {
 93    use gpui::action_with_deprecated_aliases;
 94
 95    action_with_deprecated_aliases!(
 96        workspace,
 97        CopyPath,
 98        [
 99            "editor::CopyPath",
100            "outline_panel::CopyPath",
101            "project_panel::CopyPath"
102        ]
103    );
104
105    action_with_deprecated_aliases!(
106        workspace,
107        CopyRelativePath,
108        [
109            "editor::CopyRelativePath",
110            "outline_panel::CopyRelativePath",
111            "project_panel::CopyRelativePath"
112        ]
113    );
114}
115
116pub mod git {
117    use gpui::action_with_deprecated_aliases;
118
119    action_with_deprecated_aliases!(git, Branch, ["branches::OpenRecent"]);
120}
121
122pub mod command_palette {
123    use gpui::actions;
124
125    actions!(command_palette, [Toggle]);
126}
127
128pub mod feedback {
129    use gpui::actions;
130
131    actions!(feedback, [GiveFeedback]);
132}
133
134pub mod theme_selector {
135    use gpui::impl_actions;
136    use schemars::JsonSchema;
137    use serde::Deserialize;
138
139    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
140    #[serde(deny_unknown_fields)]
141    pub struct Toggle {
142        /// A list of theme names to filter the theme selector down to.
143        pub themes_filter: Option<Vec<String>>,
144    }
145
146    impl_actions!(theme_selector, [Toggle]);
147}
148
149pub mod icon_theme_selector {
150    use gpui::impl_actions;
151    use schemars::JsonSchema;
152    use serde::Deserialize;
153
154    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
155    #[serde(deny_unknown_fields)]
156    pub struct Toggle {
157        /// A list of icon theme names to filter the theme selector down to.
158        pub themes_filter: Option<Vec<String>>,
159    }
160
161    impl_actions!(icon_theme_selector, [Toggle]);
162}
163
164pub mod assistant {
165    use gpui::{actions, impl_actions};
166    use schemars::JsonSchema;
167    use serde::Deserialize;
168
169    actions!(assistant, [ToggleFocus, DeployPromptLibrary]);
170
171    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)]
172    #[serde(deny_unknown_fields)]
173    pub struct InlineAssist {
174        pub prompt: Option<String>,
175    }
176
177    impl_actions!(assistant, [InlineAssist]);
178}
179
180#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
181#[serde(deny_unknown_fields)]
182pub struct OpenRecent {
183    #[serde(default)]
184    pub create_new_window: bool,
185}
186
187impl_actions!(projects, [OpenRecent]);
188actions!(projects, [OpenRemote]);
189
190/// Where to spawn the task in the UI.
191#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
192#[serde(rename_all = "snake_case")]
193pub enum RevealTarget {
194    /// In the central pane group, "main" editor area.
195    Center,
196    /// In the terminal dock, "regular" terminal items' place.
197    #[default]
198    Dock,
199}
200
201/// Spawn a task with name or open tasks modal.
202#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema)]
203#[serde(untagged)]
204pub enum Spawn {
205    /// Spawns a task by the name given.
206    ByName {
207        task_name: String,
208        #[serde(default)]
209        reveal_target: Option<RevealTarget>,
210    },
211    /// Spawns a task via modal's selection.
212    ViaModal {
213        /// Selected task's `reveal_target` property override.
214        #[serde(default)]
215        reveal_target: Option<RevealTarget>,
216    },
217}
218
219impl Spawn {
220    pub fn modal() -> Self {
221        Self::ViaModal {
222            reveal_target: None,
223        }
224    }
225}
226
227/// Rerun the last task.
228#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
229#[serde(deny_unknown_fields)]
230pub struct Rerun {
231    /// Controls whether the task context is reevaluated prior to execution of a task.
232    /// 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
233    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
234    /// default: false
235    #[serde(default)]
236    pub reevaluate_context: bool,
237    /// Overrides `allow_concurrent_runs` property of the task being reran.
238    /// Default: null
239    #[serde(default)]
240    pub allow_concurrent_runs: Option<bool>,
241    /// Overrides `use_new_terminal` property of the task being reran.
242    /// Default: null
243    #[serde(default)]
244    pub use_new_terminal: Option<bool>,
245
246    /// If present, rerun the task with this ID, otherwise rerun the last task.
247    #[serde(skip)]
248    pub task_id: Option<String>,
249}
250
251impl_actions!(task, [Spawn, Rerun]);
252
253pub mod outline {
254    use std::sync::OnceLock;
255
256    use gpui::{action_as, AnyView, App, Window};
257
258    action_as!(outline, ToggleOutline as Toggle);
259    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
260    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
261}
262
263actions!(zed_predict_onboarding, [OpenZedPredictOnboarding]);