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