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