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        OpenLicenses,
 39        OpenTelemetryLog,
 40    ]
 41);
 42
 43#[derive(PartialEq, Clone, Copy, Debug, Deserialize, JsonSchema)]
 44#[serde(rename_all = "snake_case")]
 45pub enum ExtensionCategoryFilter {
 46    Themes,
 47    IconThemes,
 48    Languages,
 49    Grammars,
 50    LanguageServers,
 51    ContextServers,
 52    SlashCommands,
 53    IndexedDocsProviders,
 54    Snippets,
 55}
 56
 57#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 58pub struct Extensions {
 59    /// Filters the extensions page down to extensions that are in the specified category.
 60    #[serde(default)]
 61    pub category_filter: Option<ExtensionCategoryFilter>,
 62}
 63
 64#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 65pub struct DecreaseBufferFontSize {
 66    #[serde(default)]
 67    pub persist: bool,
 68}
 69
 70#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 71pub struct IncreaseBufferFontSize {
 72    #[serde(default)]
 73    pub persist: bool,
 74}
 75
 76#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 77pub struct ResetBufferFontSize {
 78    #[serde(default)]
 79    pub persist: bool,
 80}
 81
 82#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 83pub struct DecreaseUiFontSize {
 84    #[serde(default)]
 85    pub persist: bool,
 86}
 87
 88#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 89pub struct IncreaseUiFontSize {
 90    #[serde(default)]
 91    pub persist: bool,
 92}
 93
 94#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
 95pub struct ResetUiFontSize {
 96    #[serde(default)]
 97    pub persist: bool,
 98}
 99
100impl_actions!(
101    zed,
102    [
103        Extensions,
104        DecreaseBufferFontSize,
105        IncreaseBufferFontSize,
106        ResetBufferFontSize,
107        DecreaseUiFontSize,
108        IncreaseUiFontSize,
109        ResetUiFontSize,
110    ]
111);
112
113pub mod workspace {
114    use gpui::action_with_deprecated_aliases;
115
116    action_with_deprecated_aliases!(
117        workspace,
118        CopyPath,
119        [
120            "editor::CopyPath",
121            "outline_panel::CopyPath",
122            "project_panel::CopyPath"
123        ]
124    );
125
126    action_with_deprecated_aliases!(
127        workspace,
128        CopyRelativePath,
129        [
130            "editor::CopyRelativePath",
131            "outline_panel::CopyRelativePath",
132            "project_panel::CopyRelativePath"
133        ]
134    );
135}
136
137pub mod git {
138    use gpui::{action_with_deprecated_aliases, actions};
139
140    actions!(git, [CheckoutBranch, Switch, SelectRepo]);
141    action_with_deprecated_aliases!(git, Branch, ["branches::OpenRecent"]);
142}
143
144pub mod command_palette {
145    use gpui::actions;
146
147    actions!(command_palette, [Toggle]);
148}
149
150pub mod feedback {
151    use gpui::actions;
152
153    actions!(feedback, [FileBugReport, GiveFeedback]);
154}
155
156pub mod theme_selector {
157    use gpui::impl_actions;
158    use schemars::JsonSchema;
159    use serde::Deserialize;
160
161    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
162    #[serde(deny_unknown_fields)]
163    pub struct Toggle {
164        /// A list of theme names to filter the theme selector down to.
165        pub themes_filter: Option<Vec<String>>,
166    }
167
168    impl_actions!(theme_selector, [Toggle]);
169}
170
171pub mod icon_theme_selector {
172    use gpui::impl_actions;
173    use schemars::JsonSchema;
174    use serde::Deserialize;
175
176    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
177    #[serde(deny_unknown_fields)]
178    pub struct Toggle {
179        /// A list of icon theme names to filter the theme selector down to.
180        pub themes_filter: Option<Vec<String>>,
181    }
182
183    impl_actions!(icon_theme_selector, [Toggle]);
184}
185
186pub mod agent {
187    use gpui::actions;
188
189    actions!(agent, [OpenConfiguration]);
190}
191
192pub mod assistant {
193    use gpui::{
194        action_with_deprecated_aliases, actions, impl_action_with_deprecated_aliases, impl_actions,
195    };
196    use schemars::JsonSchema;
197    use serde::Deserialize;
198    use uuid::Uuid;
199
200    action_with_deprecated_aliases!(agent, ToggleFocus, ["assistant::ToggleFocus"]);
201
202    actions!(assistant, [ShowConfiguration]);
203
204    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
205    #[serde(deny_unknown_fields)]
206    pub struct OpenRulesLibrary {
207        #[serde(skip)]
208        pub prompt_to_select: Option<Uuid>,
209    }
210
211    impl_action_with_deprecated_aliases!(
212        agent,
213        OpenRulesLibrary,
214        [
215            "assistant::OpenRulesLibrary",
216            "assistant::DeployPromptLibrary"
217        ]
218    );
219
220    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)]
221    #[serde(deny_unknown_fields)]
222    pub struct InlineAssist {
223        pub prompt: Option<String>,
224    }
225
226    impl_actions!(assistant, [InlineAssist]);
227}
228
229#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
230#[serde(deny_unknown_fields)]
231pub struct OpenRecent {
232    #[serde(default)]
233    pub create_new_window: bool,
234}
235
236impl_actions!(projects, [OpenRecent]);
237actions!(projects, [OpenRemote]);
238
239/// Where to spawn the task in the UI.
240#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
241#[serde(rename_all = "snake_case")]
242pub enum RevealTarget {
243    /// In the central pane group, "main" editor area.
244    Center,
245    /// In the terminal dock, "regular" terminal items' place.
246    #[default]
247    Dock,
248}
249
250/// Spawn a task with name or open tasks modal.
251#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema)]
252#[serde(untagged)]
253pub enum Spawn {
254    /// Spawns a task by the name given.
255    ByName {
256        task_name: String,
257        #[serde(default)]
258        reveal_target: Option<RevealTarget>,
259    },
260    /// Spawns a task by the name given.
261    ByTag {
262        task_tag: String,
263        #[serde(default)]
264        reveal_target: Option<RevealTarget>,
265    },
266    /// Spawns a task via modal's selection.
267    ViaModal {
268        /// Selected task's `reveal_target` property override.
269        #[serde(default)]
270        reveal_target: Option<RevealTarget>,
271    },
272}
273
274impl Spawn {
275    pub fn modal() -> Self {
276        Self::ViaModal {
277            reveal_target: None,
278        }
279    }
280}
281
282/// Rerun the last task.
283#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
284#[serde(deny_unknown_fields)]
285pub struct Rerun {
286    /// Controls whether the task context is reevaluated prior to execution of a task.
287    /// 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
288    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
289    /// default: false
290    #[serde(default)]
291    pub reevaluate_context: bool,
292    /// Overrides `allow_concurrent_runs` property of the task being reran.
293    /// Default: null
294    #[serde(default)]
295    pub allow_concurrent_runs: Option<bool>,
296    /// Overrides `use_new_terminal` property of the task being reran.
297    /// Default: null
298    #[serde(default)]
299    pub use_new_terminal: Option<bool>,
300
301    /// If present, rerun the task with this ID, otherwise rerun the last task.
302    #[serde(skip)]
303    pub task_id: Option<String>,
304}
305
306impl_actions!(task, [Spawn, Rerun]);
307
308pub mod outline {
309    use std::sync::OnceLock;
310
311    use gpui::{AnyView, App, Window, action_as};
312
313    action_as!(outline, ToggleOutline as Toggle);
314    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
315    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
316}
317
318actions!(zed_predict_onboarding, [OpenZedPredictOnboarding]);
319actions!(git_onboarding, [OpenGitIntegrationOnboarding]);