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
 30/// Opens the keymap to either add a keybinding or change an existing one
 31#[derive(PartialEq, Clone, Default, Action, JsonSchema, Serialize, Deserialize)]
 32#[action(namespace = zed, no_json, no_register)]
 33pub struct ChangeKeybinding {
 34    pub action: String,
 35}
 36
 37actions!(
 38    zed,
 39    [
 40        /// Opens the settings editor.
 41        #[action(deprecated_aliases = ["zed_actions::OpenSettingsEditor"])]
 42        OpenSettings,
 43        /// Opens the settings JSON file.
 44        #[action(deprecated_aliases = ["zed_actions::OpenSettings"])]
 45        OpenSettingsFile,
 46        /// Opens project-specific settings.
 47        #[action(deprecated_aliases = ["zed_actions::OpenProjectSettings"])]
 48        OpenProjectSettings,
 49        /// Opens the default keymap file.
 50        OpenDefaultKeymap,
 51        /// Opens the user keymap file.
 52        #[action(deprecated_aliases = ["zed_actions::OpenKeymap"])]
 53        OpenKeymapFile,
 54        /// Opens the keymap editor.
 55        #[action(deprecated_aliases = ["zed_actions::OpenKeymapEditor"])]
 56        OpenKeymap,
 57        /// Opens account settings.
 58        OpenAccountSettings,
 59        /// Opens server settings.
 60        OpenServerSettings,
 61        /// Quits the application.
 62        Quit,
 63        /// Shows information about Zed.
 64        About,
 65        /// Opens the documentation website.
 66        OpenDocs,
 67        /// Views open source licenses.
 68        OpenLicenses,
 69        /// Opens the telemetry log.
 70        OpenTelemetryLog,
 71        /// Opens the performance profiler.
 72        OpenPerformanceProfiler,
 73        /// Opens the onboarding view.
 74        OpenOnboarding,
 75    ]
 76);
 77
 78#[derive(PartialEq, Clone, Copy, Debug, Deserialize, JsonSchema)]
 79#[serde(rename_all = "snake_case")]
 80pub enum ExtensionCategoryFilter {
 81    Themes,
 82    IconThemes,
 83    Languages,
 84    Grammars,
 85    LanguageServers,
 86    ContextServers,
 87    AgentServers,
 88    SlashCommands,
 89    IndexedDocsProviders,
 90    Snippets,
 91    DebugAdapters,
 92}
 93
 94/// Opens the extensions management interface.
 95#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 96#[action(namespace = zed)]
 97#[serde(deny_unknown_fields)]
 98pub struct Extensions {
 99    /// Filters the extensions page down to extensions that are in the specified category.
100    #[serde(default)]
101    pub category_filter: Option<ExtensionCategoryFilter>,
102    /// Focuses just the extension with the specified ID.
103    #[serde(default)]
104    pub id: Option<String>,
105}
106
107/// Opens the ACP registry.
108#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
109#[action(namespace = zed)]
110#[serde(deny_unknown_fields)]
111pub struct AcpRegistry;
112
113/// Decreases the font size in the editor buffer.
114#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
115#[action(namespace = zed)]
116#[serde(deny_unknown_fields)]
117pub struct DecreaseBufferFontSize {
118    #[serde(default)]
119    pub persist: bool,
120}
121
122/// Increases the font size in the editor buffer.
123#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
124#[action(namespace = zed)]
125#[serde(deny_unknown_fields)]
126pub struct IncreaseBufferFontSize {
127    #[serde(default)]
128    pub persist: bool,
129}
130
131/// Opens the settings editor at a specific path.
132#[derive(PartialEq, Clone, Debug, Deserialize, JsonSchema, Action)]
133#[action(namespace = zed)]
134#[serde(deny_unknown_fields)]
135pub struct OpenSettingsAt {
136    /// A path to a specific setting (e.g. `theme.mode`)
137    pub path: String,
138}
139
140/// Resets the buffer font size to the default value.
141#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
142#[action(namespace = zed)]
143#[serde(deny_unknown_fields)]
144pub struct ResetBufferFontSize {
145    #[serde(default)]
146    pub persist: bool,
147}
148
149/// Decreases the font size of the user interface.
150#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
151#[action(namespace = zed)]
152#[serde(deny_unknown_fields)]
153pub struct DecreaseUiFontSize {
154    #[serde(default)]
155    pub persist: bool,
156}
157
158/// Increases the font size of the user interface.
159#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
160#[action(namespace = zed)]
161#[serde(deny_unknown_fields)]
162pub struct IncreaseUiFontSize {
163    #[serde(default)]
164    pub persist: bool,
165}
166
167/// Resets the UI font size to the default value.
168#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
169#[action(namespace = zed)]
170#[serde(deny_unknown_fields)]
171pub struct ResetUiFontSize {
172    #[serde(default)]
173    pub persist: bool,
174}
175
176/// Resets all zoom levels (UI and buffer font sizes, including in the agent panel) to their default values.
177#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
178#[action(namespace = zed)]
179#[serde(deny_unknown_fields)]
180pub struct ResetAllZoom {
181    #[serde(default)]
182    pub persist: bool,
183}
184
185pub mod editor {
186    use gpui::actions;
187    actions!(
188        editor,
189        [
190            /// Moves cursor up.
191            MoveUp,
192            /// Moves cursor down.
193            MoveDown,
194        ]
195    );
196}
197
198pub mod dev {
199    use gpui::actions;
200
201    actions!(
202        dev,
203        [
204            /// Toggles the developer inspector for debugging UI elements.
205            ToggleInspector
206        ]
207    );
208}
209
210pub mod remote_debug {
211    use gpui::actions;
212
213    actions!(
214        remote_debug,
215        [
216            /// Simulates a disconnection from the remote server for testing purposes.
217            /// This will trigger the reconnection logic.
218            SimulateDisconnect,
219            /// Simulates a timeout/slow connection to the remote server for testing purposes.
220            /// This will cause heartbeat failures and trigger reconnection.
221            SimulateTimeout,
222            /// Simulates a timeout/slow connection to the remote server for testing purposes.
223            /// This will cause heartbeat failures and attempting a reconnection while having exhausted all attempts.
224            SimulateTimeoutExhausted,
225        ]
226    );
227}
228
229pub mod workspace {
230    use gpui::actions;
231
232    actions!(
233        workspace,
234        [
235            #[action(deprecated_aliases = ["editor::CopyPath", "outline_panel::CopyPath", "project_panel::CopyPath"])]
236            CopyPath,
237            #[action(deprecated_aliases = ["editor::CopyRelativePath", "outline_panel::CopyRelativePath", "project_panel::CopyRelativePath"])]
238            CopyRelativePath,
239            /// Opens the selected file with the system's default application.
240            #[action(deprecated_aliases = ["project_panel::OpenWithSystem"])]
241            OpenWithSystem,
242        ]
243    );
244}
245
246pub mod git {
247    use gpui::actions;
248
249    actions!(
250        git,
251        [
252            /// Checks out a different git branch.
253            CheckoutBranch,
254            /// Switches to a different git branch.
255            Switch,
256            /// Selects a different repository.
257            SelectRepo,
258            /// Filter remotes.
259            FilterRemotes,
260            /// Create a git remote.
261            CreateRemote,
262            /// Opens the git branch selector.
263            #[action(deprecated_aliases = ["branches::OpenRecent"])]
264            Branch,
265            /// Opens the git stash selector.
266            ViewStash,
267            /// Opens the git worktree selector.
268            Worktree,
269            /// Creates a pull request for the current branch.
270            CreatePullRequest
271        ]
272    );
273}
274
275pub mod toast {
276    use gpui::actions;
277
278    actions!(
279        toast,
280        [
281            /// Runs the action associated with a toast notification.
282            RunAction
283        ]
284    );
285}
286
287pub mod command_palette {
288    use gpui::actions;
289
290    actions!(
291        command_palette,
292        [
293            /// Toggles the command palette.
294            Toggle,
295        ]
296    );
297}
298
299pub mod project_panel {
300    use gpui::actions;
301
302    actions!(
303        project_panel,
304        [
305            /// Toggles the project panel.
306            Toggle,
307            /// Toggles focus on the project panel.
308            ToggleFocus
309        ]
310    );
311}
312pub mod feedback {
313    use gpui::actions;
314
315    actions!(
316        feedback,
317        [
318            /// Opens email client to send feedback to Zed support.
319            EmailZed,
320            /// Opens the bug report form.
321            FileBugReport,
322            /// Opens the feature request form.
323            RequestFeature
324        ]
325    );
326}
327
328pub mod theme_selector {
329    use gpui::Action;
330    use schemars::JsonSchema;
331    use serde::Deserialize;
332
333    /// Toggles the theme selector interface.
334    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
335    #[action(namespace = theme_selector)]
336    #[serde(deny_unknown_fields)]
337    pub struct Toggle {
338        /// A list of theme names to filter the theme selector down to.
339        pub themes_filter: Option<Vec<String>>,
340    }
341}
342
343pub mod icon_theme_selector {
344    use gpui::Action;
345    use schemars::JsonSchema;
346    use serde::Deserialize;
347
348    /// Toggles the icon theme selector interface.
349    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
350    #[action(namespace = icon_theme_selector)]
351    #[serde(deny_unknown_fields)]
352    pub struct Toggle {
353        /// A list of icon theme names to filter the theme selector down to.
354        pub themes_filter: Option<Vec<String>>,
355    }
356}
357
358pub mod search {
359    use gpui::actions;
360    actions!(
361        search,
362        [
363            /// Toggles searching in ignored files.
364            ToggleIncludeIgnored
365        ]
366    );
367}
368pub mod buffer_search {
369    use gpui::{Action, actions};
370    use schemars::JsonSchema;
371    use serde::Deserialize;
372
373    /// Opens the buffer search interface with the specified configuration.
374    #[derive(PartialEq, Clone, Deserialize, JsonSchema, Action)]
375    #[action(namespace = buffer_search)]
376    #[serde(deny_unknown_fields)]
377    pub struct Deploy {
378        #[serde(default = "util::serde::default_true")]
379        pub focus: bool,
380        #[serde(default)]
381        pub replace_enabled: bool,
382        #[serde(default)]
383        pub selection_search_enabled: bool,
384    }
385
386    impl Deploy {
387        pub fn find() -> Self {
388            Self {
389                focus: true,
390                replace_enabled: false,
391                selection_search_enabled: false,
392            }
393        }
394
395        pub fn replace() -> Self {
396            Self {
397                focus: true,
398                replace_enabled: true,
399                selection_search_enabled: false,
400            }
401        }
402    }
403
404    actions!(
405        buffer_search,
406        [
407            /// Deploys the search and replace interface.
408            DeployReplace,
409            /// Dismisses the search bar.
410            Dismiss,
411            /// Focuses back on the editor.
412            FocusEditor
413        ]
414    );
415}
416pub mod settings_profile_selector {
417    use gpui::Action;
418    use schemars::JsonSchema;
419    use serde::Deserialize;
420
421    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
422    #[action(namespace = settings_profile_selector)]
423    pub struct Toggle;
424}
425
426pub mod agent {
427    use gpui::{Action, SharedString, actions};
428    use schemars::JsonSchema;
429    use serde::Deserialize;
430
431    actions!(
432        agent,
433        [
434            /// Opens the agent settings panel.
435            #[action(deprecated_aliases = ["agent::OpenConfiguration"])]
436            OpenSettings,
437            /// Opens the agent onboarding modal.
438            OpenOnboardingModal,
439            /// Opens the ACP onboarding modal.
440            OpenAcpOnboardingModal,
441            /// Opens the Claude Agent onboarding modal.
442            OpenClaudeAgentOnboardingModal,
443            /// Resets the agent onboarding state.
444            ResetOnboarding,
445            /// Starts a chat conversation with the agent.
446            Chat,
447            /// Toggles the language model selector dropdown.
448            #[action(deprecated_aliases = ["assistant::ToggleModelSelector", "assistant2::ToggleModelSelector"])]
449            ToggleModelSelector,
450            /// Triggers re-authentication on Gemini
451            ReauthenticateAgent,
452            /// Add the current selection as context for threads in the agent panel.
453            #[action(deprecated_aliases = ["assistant::QuoteSelection", "agent::QuoteSelection"])]
454            AddSelectionToThread,
455            /// Resets the agent panel zoom levels (agent UI and buffer font sizes).
456            ResetAgentZoom,
457            /// Pastes clipboard content without any formatting.
458            PasteRaw,
459        ]
460    );
461
462    /// Opens a new agent thread with the provided branch diff for review.
463    #[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
464    #[action(namespace = agent)]
465    #[serde(deny_unknown_fields)]
466    pub struct ReviewBranchDiff {
467        /// The full text of the diff to review.
468        pub diff_text: SharedString,
469        /// The base ref that the diff was computed against (e.g. "main").
470        pub base_ref: SharedString,
471    }
472}
473
474pub mod assistant {
475    use gpui::{Action, actions};
476    use schemars::JsonSchema;
477    use serde::Deserialize;
478    use uuid::Uuid;
479
480    actions!(
481        agent,
482        [
483            /// Toggles the agent panel.
484            Toggle,
485            #[action(deprecated_aliases = ["assistant::ToggleFocus"])]
486            ToggleFocus
487        ]
488    );
489
490    actions!(
491        assistant,
492        [
493            /// Shows the assistant configuration panel.
494            ShowConfiguration
495        ]
496    );
497
498    /// Opens the rules library for managing agent rules and prompts.
499    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
500    #[action(namespace = agent, deprecated_aliases = ["assistant::OpenRulesLibrary", "assistant::DeployPromptLibrary"])]
501    #[serde(deny_unknown_fields)]
502    pub struct OpenRulesLibrary {
503        #[serde(skip)]
504        pub prompt_to_select: Option<Uuid>,
505    }
506
507    /// Deploys the assistant interface with the specified configuration.
508    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema, Action)]
509    #[action(namespace = assistant)]
510    #[serde(deny_unknown_fields)]
511    pub struct InlineAssist {
512        pub prompt: Option<String>,
513    }
514}
515
516/// Opens the recent projects interface.
517#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
518#[action(namespace = projects)]
519#[serde(deny_unknown_fields)]
520pub struct OpenRecent {
521    #[serde(default)]
522    pub create_new_window: bool,
523}
524
525/// Creates a project from a selected template.
526#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
527#[action(namespace = projects)]
528#[serde(deny_unknown_fields)]
529pub struct OpenRemote {
530    #[serde(default)]
531    pub from_existing_connection: bool,
532    #[serde(default)]
533    pub create_new_window: bool,
534}
535
536/// Opens the dev container connection modal.
537#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
538#[action(namespace = projects)]
539#[serde(deny_unknown_fields)]
540pub struct OpenDevContainer;
541
542/// Where to spawn the task in the UI.
543#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
544#[serde(rename_all = "snake_case")]
545pub enum RevealTarget {
546    /// In the central pane group, "main" editor area.
547    Center,
548    /// In the terminal dock, "regular" terminal items' place.
549    #[default]
550    Dock,
551}
552
553/// Spawns a task with name or opens tasks modal.
554#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema, Action)]
555#[action(namespace = task)]
556#[serde(untagged)]
557pub enum Spawn {
558    /// Spawns a task by the name given.
559    ByName {
560        task_name: String,
561        #[serde(default)]
562        reveal_target: Option<RevealTarget>,
563    },
564    /// Spawns a task by the tag given.
565    ByTag {
566        task_tag: String,
567        #[serde(default)]
568        reveal_target: Option<RevealTarget>,
569    },
570    /// Spawns a task via modal's selection.
571    ViaModal {
572        /// Selected task's `reveal_target` property override.
573        #[serde(default)]
574        reveal_target: Option<RevealTarget>,
575    },
576}
577
578impl Spawn {
579    pub fn modal() -> Self {
580        Self::ViaModal {
581            reveal_target: None,
582        }
583    }
584}
585
586/// Reruns the last task.
587#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
588#[action(namespace = task)]
589#[serde(deny_unknown_fields)]
590pub struct Rerun {
591    /// Controls whether the task context is reevaluated prior to execution of a task.
592    /// 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
593    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
594    /// default: false
595    #[serde(default)]
596    pub reevaluate_context: bool,
597    /// Overrides `allow_concurrent_runs` property of the task being reran.
598    /// Default: null
599    #[serde(default)]
600    pub allow_concurrent_runs: Option<bool>,
601    /// Overrides `use_new_terminal` property of the task being reran.
602    /// Default: null
603    #[serde(default)]
604    pub use_new_terminal: Option<bool>,
605
606    /// If present, rerun the task with this ID, otherwise rerun the last task.
607    #[serde(skip)]
608    pub task_id: Option<String>,
609}
610
611pub mod outline {
612    use std::sync::OnceLock;
613
614    use gpui::{AnyView, App, Window, actions};
615
616    actions!(
617        outline,
618        [
619            #[action(name = "Toggle")]
620            ToggleOutline
621        ]
622    );
623    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
624    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
625}
626
627actions!(
628    zed_predict_onboarding,
629    [
630        /// Opens the Zed Predict onboarding modal.
631        OpenZedPredictOnboarding
632    ]
633);
634actions!(
635    git_onboarding,
636    [
637        /// Opens the git integration onboarding modal.
638        OpenGitIntegrationOnboarding
639    ]
640);
641
642pub mod debug_panel {
643    use gpui::actions;
644    actions!(
645        debug_panel,
646        [
647            /// Toggles the debug panel.
648            Toggle,
649            /// Toggles focus on the debug panel.
650            ToggleFocus
651        ]
652    );
653}
654
655actions!(
656    debugger,
657    [
658        /// Toggles the enabled state of a breakpoint.
659        ToggleEnableBreakpoint,
660        /// Removes a breakpoint.
661        UnsetBreakpoint,
662        /// Opens the project debug tasks configuration.
663        OpenProjectDebugTasks,
664    ]
665);
666
667pub mod vim {
668    use gpui::actions;
669
670    actions!(
671        vim,
672        [
673            /// Opens the default keymap file.
674            OpenDefaultKeymap
675        ]
676    );
677}
678
679#[derive(Debug, Clone, PartialEq, Eq, Hash)]
680pub struct WslConnectionOptions {
681    pub distro_name: String,
682    pub user: Option<String>,
683}
684
685#[cfg(target_os = "windows")]
686pub mod wsl_actions {
687    use gpui::Action;
688    use schemars::JsonSchema;
689    use serde::Deserialize;
690
691    /// Opens a folder inside Wsl.
692    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
693    #[action(namespace = projects)]
694    #[serde(deny_unknown_fields)]
695    pub struct OpenFolderInWsl {
696        #[serde(default)]
697        pub create_new_window: bool,
698    }
699
700    /// Open a wsl distro.
701    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
702    #[action(namespace = projects)]
703    #[serde(deny_unknown_fields)]
704    pub struct OpenWsl {
705        #[serde(default)]
706        pub create_new_window: bool,
707    }
708}
709
710pub mod preview {
711    pub mod markdown {
712        use gpui::actions;
713
714        actions!(
715            markdown,
716            [
717                /// Opens a markdown preview for the current file.
718                OpenPreview,
719                /// Opens a markdown preview in a split pane.
720                OpenPreviewToTheSide,
721            ]
722        );
723    }
724
725    pub mod svg {
726        use gpui::actions;
727
728        actions!(
729            svg,
730            [
731                /// Opens an SVG preview for the current file.
732                OpenPreview,
733                /// Opens an SVG preview in a split pane.
734                OpenPreviewToTheSide,
735            ]
736        );
737    }
738}
739
740pub mod notebook {
741    use gpui::actions;
742
743    actions!(
744        notebook,
745        [
746            /// Move to down in cells
747            NotebookMoveDown,
748            /// Move to up in cells
749            NotebookMoveUp,
750        ]
751    );
752}