lib.rs

  1use gpui::{Action, 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/// Opens a URL in the system's default web browser.
 15#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
 16#[action(namespace = zed)]
 17#[serde(deny_unknown_fields)]
 18pub struct OpenBrowser {
 19    pub url: String,
 20}
 21
 22/// Opens a zed:// URL within the application.
 23#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
 24#[action(namespace = zed)]
 25#[serde(deny_unknown_fields)]
 26pub struct OpenZedUrl {
 27    pub url: String,
 28}
 29
 30actions!(
 31    zed,
 32    [
 33        /// Opens the settings JSON file.
 34        OpenSettings,
 35        /// Opens the settings editor.
 36        OpenSettingsEditor,
 37        /// Opens the default keymap file.
 38        OpenDefaultKeymap,
 39        /// Opens account settings.
 40        OpenAccountSettings,
 41        /// Opens the keymap editor.
 42        OpenKeymapEditor,
 43        /// Opens server settings.
 44        OpenServerSettings,
 45        /// Quits the application.
 46        Quit,
 47        /// Opens the user keymap file.
 48        OpenKeymap,
 49        /// Shows information about Zed.
 50        About,
 51        /// Opens the documentation website.
 52        OpenDocs,
 53        /// Views open source licenses.
 54        OpenLicenses,
 55        /// Opens the telemetry log.
 56        OpenTelemetryLog,
 57    ]
 58);
 59
 60#[derive(PartialEq, Clone, Copy, Debug, Deserialize, JsonSchema)]
 61#[serde(rename_all = "snake_case")]
 62pub enum ExtensionCategoryFilter {
 63    Themes,
 64    IconThemes,
 65    Languages,
 66    Grammars,
 67    LanguageServers,
 68    ContextServers,
 69    SlashCommands,
 70    IndexedDocsProviders,
 71    Snippets,
 72    DebugAdapters,
 73}
 74
 75/// Opens the extensions management interface.
 76#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 77#[action(namespace = zed)]
 78#[serde(deny_unknown_fields)]
 79pub struct Extensions {
 80    /// Filters the extensions page down to extensions that are in the specified category.
 81    #[serde(default)]
 82    pub category_filter: Option<ExtensionCategoryFilter>,
 83    /// Focuses just the extension with the specified ID.
 84    #[serde(default)]
 85    pub id: Option<String>,
 86}
 87
 88/// Decreases the font size in the editor buffer.
 89#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 90#[action(namespace = zed)]
 91#[serde(deny_unknown_fields)]
 92pub struct DecreaseBufferFontSize {
 93    #[serde(default)]
 94    pub persist: bool,
 95}
 96
 97/// Increases the font size in the editor buffer.
 98#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 99#[action(namespace = zed)]
100#[serde(deny_unknown_fields)]
101pub struct IncreaseBufferFontSize {
102    #[serde(default)]
103    pub persist: bool,
104}
105
106/// Resets the buffer font size to the default value.
107#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
108#[action(namespace = zed)]
109#[serde(deny_unknown_fields)]
110pub struct ResetBufferFontSize {
111    #[serde(default)]
112    pub persist: bool,
113}
114
115/// Decreases the font size of the user interface.
116#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
117#[action(namespace = zed)]
118#[serde(deny_unknown_fields)]
119pub struct DecreaseUiFontSize {
120    #[serde(default)]
121    pub persist: bool,
122}
123
124/// Increases the font size of the user interface.
125#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
126#[action(namespace = zed)]
127#[serde(deny_unknown_fields)]
128pub struct IncreaseUiFontSize {
129    #[serde(default)]
130    pub persist: bool,
131}
132
133/// Resets the UI font size to the default value.
134#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
135#[action(namespace = zed)]
136#[serde(deny_unknown_fields)]
137pub struct ResetUiFontSize {
138    #[serde(default)]
139    pub persist: bool,
140}
141
142pub mod dev {
143    use gpui::actions;
144
145    actions!(
146        dev,
147        [
148            /// Toggles the developer inspector for debugging UI elements.
149            ToggleInspector
150        ]
151    );
152}
153
154pub mod workspace {
155    use gpui::actions;
156
157    actions!(
158        workspace,
159        [
160            #[action(deprecated_aliases = ["editor::CopyPath", "outline_panel::CopyPath", "project_panel::CopyPath"])]
161            CopyPath,
162            #[action(deprecated_aliases = ["editor::CopyRelativePath", "outline_panel::CopyRelativePath", "project_panel::CopyRelativePath"])]
163            CopyRelativePath,
164            /// Opens the selected file with the system's default application.
165            #[action(deprecated_aliases = ["project_panel::OpenWithSystem"])]
166            OpenWithSystem,
167        ]
168    );
169}
170
171pub mod git {
172    use gpui::actions;
173
174    actions!(
175        git,
176        [
177            /// Checks out a different git branch.
178            CheckoutBranch,
179            /// Switches to a different git branch.
180            Switch,
181            /// Selects a different repository.
182            SelectRepo,
183            /// Opens the git branch selector.
184            #[action(deprecated_aliases = ["branches::OpenRecent"])]
185            Branch,
186            /// Opens the git stash selector.
187            ViewStash
188        ]
189    );
190}
191
192pub mod toast {
193    use gpui::actions;
194
195    actions!(
196        toast,
197        [
198            /// Runs the action associated with a toast notification.
199            RunAction
200        ]
201    );
202}
203
204pub mod command_palette {
205    use gpui::actions;
206
207    actions!(
208        command_palette,
209        [
210            /// Toggles the command palette.
211            Toggle
212        ]
213    );
214}
215
216pub mod feedback {
217    use gpui::actions;
218
219    actions!(
220        feedback,
221        [
222            /// Opens email client to send feedback to Zed support.
223            EmailZed,
224            /// Opens the bug report form.
225            FileBugReport,
226            /// Opens the feature request form.
227            RequestFeature
228        ]
229    );
230}
231
232pub mod theme_selector {
233    use gpui::Action;
234    use schemars::JsonSchema;
235    use serde::Deserialize;
236
237    /// Toggles the theme selector interface.
238    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
239    #[action(namespace = theme_selector)]
240    #[serde(deny_unknown_fields)]
241    pub struct Toggle {
242        /// A list of theme names to filter the theme selector down to.
243        pub themes_filter: Option<Vec<String>>,
244    }
245}
246
247pub mod icon_theme_selector {
248    use gpui::Action;
249    use schemars::JsonSchema;
250    use serde::Deserialize;
251
252    /// Toggles the icon theme selector interface.
253    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
254    #[action(namespace = icon_theme_selector)]
255    #[serde(deny_unknown_fields)]
256    pub struct Toggle {
257        /// A list of icon theme names to filter the theme selector down to.
258        pub themes_filter: Option<Vec<String>>,
259    }
260}
261
262pub mod settings_profile_selector {
263    use gpui::Action;
264    use schemars::JsonSchema;
265    use serde::Deserialize;
266
267    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
268    #[action(namespace = settings_profile_selector)]
269    pub struct Toggle;
270}
271
272pub mod agent {
273    use gpui::actions;
274
275    actions!(
276        agent,
277        [
278            /// Opens the agent settings panel.
279            #[action(deprecated_aliases = ["agent::OpenConfiguration"])]
280            OpenSettings,
281            /// Opens the agent onboarding modal.
282            OpenOnboardingModal,
283            /// Opens the ACP onboarding modal.
284            OpenAcpOnboardingModal,
285            /// Opens the Claude Code onboarding modal.
286            OpenClaudeCodeOnboardingModal,
287            /// Resets the agent onboarding state.
288            ResetOnboarding,
289            /// Starts a chat conversation with the agent.
290            Chat,
291            /// Toggles the language model selector dropdown.
292            #[action(deprecated_aliases = ["assistant::ToggleModelSelector", "assistant2::ToggleModelSelector"])]
293            ToggleModelSelector,
294            /// Triggers re-authentication on Gemini
295            ReauthenticateAgent
296        ]
297    );
298}
299
300pub mod assistant {
301    use gpui::{Action, actions};
302    use schemars::JsonSchema;
303    use serde::Deserialize;
304    use uuid::Uuid;
305
306    actions!(
307        agent,
308        [
309            #[action(deprecated_aliases = ["assistant::ToggleFocus"])]
310            ToggleFocus
311        ]
312    );
313
314    actions!(
315        assistant,
316        [
317            /// Shows the assistant configuration panel.
318            ShowConfiguration
319        ]
320    );
321
322    /// Opens the rules library for managing agent rules and prompts.
323    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
324    #[action(namespace = agent, deprecated_aliases = ["assistant::OpenRulesLibrary", "assistant::DeployPromptLibrary"])]
325    #[serde(deny_unknown_fields)]
326    pub struct OpenRulesLibrary {
327        #[serde(skip)]
328        pub prompt_to_select: Option<Uuid>,
329    }
330
331    /// Deploys the assistant interface with the specified configuration.
332    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema, Action)]
333    #[action(namespace = assistant)]
334    #[serde(deny_unknown_fields)]
335    pub struct InlineAssist {
336        pub prompt: Option<String>,
337    }
338}
339
340pub mod debugger {
341    use gpui::actions;
342
343    actions!(
344        debugger,
345        [
346            /// Opens the debugger onboarding modal.
347            OpenOnboardingModal,
348            /// Resets the debugger onboarding state.
349            ResetOnboarding
350        ]
351    );
352}
353
354/// Opens the recent projects interface.
355#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
356#[action(namespace = projects)]
357#[serde(deny_unknown_fields)]
358pub struct OpenRecent {
359    #[serde(default)]
360    pub create_new_window: bool,
361}
362
363/// Creates a project from a selected template.
364#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
365#[action(namespace = projects)]
366#[serde(deny_unknown_fields)]
367pub struct OpenRemote {
368    #[serde(default)]
369    pub from_existing_connection: bool,
370    #[serde(default)]
371    pub create_new_window: bool,
372}
373
374/// Where to spawn the task in the UI.
375#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
376#[serde(rename_all = "snake_case")]
377pub enum RevealTarget {
378    /// In the central pane group, "main" editor area.
379    Center,
380    /// In the terminal dock, "regular" terminal items' place.
381    #[default]
382    Dock,
383}
384
385/// Spawns a task with name or opens tasks modal.
386#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema, Action)]
387#[action(namespace = task)]
388#[serde(untagged)]
389pub enum Spawn {
390    /// Spawns a task by the name given.
391    ByName {
392        task_name: String,
393        #[serde(default)]
394        reveal_target: Option<RevealTarget>,
395    },
396    /// Spawns a task by the name given.
397    ByTag {
398        task_tag: String,
399        #[serde(default)]
400        reveal_target: Option<RevealTarget>,
401    },
402    /// Spawns a task via modal's selection.
403    ViaModal {
404        /// Selected task's `reveal_target` property override.
405        #[serde(default)]
406        reveal_target: Option<RevealTarget>,
407    },
408}
409
410impl Spawn {
411    pub fn modal() -> Self {
412        Self::ViaModal {
413            reveal_target: None,
414        }
415    }
416}
417
418/// Reruns the last task.
419#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
420#[action(namespace = task)]
421#[serde(deny_unknown_fields)]
422pub struct Rerun {
423    /// Controls whether the task context is reevaluated prior to execution of a task.
424    /// 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
425    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
426    /// default: false
427    #[serde(default)]
428    pub reevaluate_context: bool,
429    /// Overrides `allow_concurrent_runs` property of the task being reran.
430    /// Default: null
431    #[serde(default)]
432    pub allow_concurrent_runs: Option<bool>,
433    /// Overrides `use_new_terminal` property of the task being reran.
434    /// Default: null
435    #[serde(default)]
436    pub use_new_terminal: Option<bool>,
437
438    /// If present, rerun the task with this ID, otherwise rerun the last task.
439    #[serde(skip)]
440    pub task_id: Option<String>,
441}
442
443pub mod outline {
444    use std::sync::OnceLock;
445
446    use gpui::{AnyView, App, Window, actions};
447
448    actions!(
449        outline,
450        [
451            #[action(name = "Toggle")]
452            ToggleOutline
453        ]
454    );
455    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
456    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
457}
458
459actions!(
460    zed_predict_onboarding,
461    [
462        /// Opens the Zed Predict onboarding modal.
463        OpenZedPredictOnboarding
464    ]
465);
466actions!(
467    git_onboarding,
468    [
469        /// Opens the git integration onboarding modal.
470        OpenGitIntegrationOnboarding
471    ]
472);
473
474actions!(
475    debug_panel,
476    [
477        /// Toggles focus on the debug panel.
478        ToggleFocus
479    ]
480);
481actions!(
482    debugger,
483    [
484        /// Toggles the enabled state of a breakpoint.
485        ToggleEnableBreakpoint,
486        /// Removes a breakpoint.
487        UnsetBreakpoint,
488        /// Opens the project debug tasks configuration.
489        OpenProjectDebugTasks,
490    ]
491);
492
493#[cfg(target_os = "windows")]
494pub mod wsl_actions {
495    use gpui::Action;
496    use schemars::JsonSchema;
497    use serde::Deserialize;
498
499    /// Opens a folder inside Wsl.
500    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
501    #[action(namespace = projects)]
502    #[serde(deny_unknown_fields)]
503    pub struct OpenFolderInWsl {
504        #[serde(default)]
505        pub create_new_window: bool,
506    }
507
508    /// Open a wsl distro.
509    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
510    #[action(namespace = projects)]
511    #[serde(deny_unknown_fields)]
512    pub struct OpenWsl {
513        #[serde(default)]
514        pub create_new_window: bool,
515    }
516}