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 focus on the project panel.
306            ToggleFocus
307        ]
308    );
309}
310pub mod feedback {
311    use gpui::actions;
312
313    actions!(
314        feedback,
315        [
316            /// Opens email client to send feedback to Zed support.
317            EmailZed,
318            /// Opens the bug report form.
319            FileBugReport,
320            /// Opens the feature request form.
321            RequestFeature
322        ]
323    );
324}
325
326pub mod theme_selector {
327    use gpui::Action;
328    use schemars::JsonSchema;
329    use serde::Deserialize;
330
331    /// Toggles the theme selector interface.
332    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
333    #[action(namespace = theme_selector)]
334    #[serde(deny_unknown_fields)]
335    pub struct Toggle {
336        /// A list of theme names to filter the theme selector down to.
337        pub themes_filter: Option<Vec<String>>,
338    }
339}
340
341pub mod icon_theme_selector {
342    use gpui::Action;
343    use schemars::JsonSchema;
344    use serde::Deserialize;
345
346    /// Toggles the icon theme selector interface.
347    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
348    #[action(namespace = icon_theme_selector)]
349    #[serde(deny_unknown_fields)]
350    pub struct Toggle {
351        /// A list of icon theme names to filter the theme selector down to.
352        pub themes_filter: Option<Vec<String>>,
353    }
354}
355
356pub mod search {
357    use gpui::actions;
358    actions!(
359        search,
360        [
361            /// Toggles searching in ignored files.
362            ToggleIncludeIgnored
363        ]
364    );
365}
366pub mod buffer_search {
367    use gpui::{Action, actions};
368    use schemars::JsonSchema;
369    use serde::Deserialize;
370
371    /// Opens the buffer search interface with the specified configuration.
372    #[derive(PartialEq, Clone, Deserialize, JsonSchema, Action)]
373    #[action(namespace = buffer_search)]
374    #[serde(deny_unknown_fields)]
375    pub struct Deploy {
376        #[serde(default = "util::serde::default_true")]
377        pub focus: bool,
378        #[serde(default)]
379        pub replace_enabled: bool,
380        #[serde(default)]
381        pub selection_search_enabled: bool,
382    }
383
384    impl Deploy {
385        pub fn find() -> Self {
386            Self {
387                focus: true,
388                replace_enabled: false,
389                selection_search_enabled: false,
390            }
391        }
392
393        pub fn replace() -> Self {
394            Self {
395                focus: true,
396                replace_enabled: true,
397                selection_search_enabled: false,
398            }
399        }
400    }
401
402    actions!(
403        buffer_search,
404        [
405            /// Deploys the search and replace interface.
406            DeployReplace,
407            /// Dismisses the search bar.
408            Dismiss,
409            /// Focuses back on the editor.
410            FocusEditor
411        ]
412    );
413}
414pub mod settings_profile_selector {
415    use gpui::Action;
416    use schemars::JsonSchema;
417    use serde::Deserialize;
418
419    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
420    #[action(namespace = settings_profile_selector)]
421    pub struct Toggle;
422}
423
424pub mod agent {
425    use gpui::actions;
426
427    actions!(
428        agent,
429        [
430            /// Opens the agent settings panel.
431            #[action(deprecated_aliases = ["agent::OpenConfiguration"])]
432            OpenSettings,
433            /// Opens the agent onboarding modal.
434            OpenOnboardingModal,
435            /// Opens the ACP onboarding modal.
436            OpenAcpOnboardingModal,
437            /// Opens the Claude Agent onboarding modal.
438            OpenClaudeAgentOnboardingModal,
439            /// Resets the agent onboarding state.
440            ResetOnboarding,
441            /// Starts a chat conversation with the agent.
442            Chat,
443            /// Toggles the language model selector dropdown.
444            #[action(deprecated_aliases = ["assistant::ToggleModelSelector", "assistant2::ToggleModelSelector"])]
445            ToggleModelSelector,
446            /// Triggers re-authentication on Gemini
447            ReauthenticateAgent,
448            /// Add the current selection as context for threads in the agent panel.
449            #[action(deprecated_aliases = ["assistant::QuoteSelection", "agent::QuoteSelection"])]
450            AddSelectionToThread,
451            /// Resets the agent panel zoom levels (agent UI and buffer font sizes).
452            ResetAgentZoom,
453            /// Toggles the utility/agent pane open/closed state.
454            ToggleAgentPane,
455            /// Pastes clipboard content without any formatting.
456            PasteRaw,
457        ]
458    );
459}
460
461pub mod assistant {
462    use gpui::{Action, actions};
463    use schemars::JsonSchema;
464    use serde::Deserialize;
465    use uuid::Uuid;
466
467    actions!(
468        agent,
469        [
470            #[action(deprecated_aliases = ["assistant::ToggleFocus"])]
471            ToggleFocus
472        ]
473    );
474
475    actions!(
476        assistant,
477        [
478            /// Shows the assistant configuration panel.
479            ShowConfiguration
480        ]
481    );
482
483    /// Opens the rules library for managing agent rules and prompts.
484    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
485    #[action(namespace = agent, deprecated_aliases = ["assistant::OpenRulesLibrary", "assistant::DeployPromptLibrary"])]
486    #[serde(deny_unknown_fields)]
487    pub struct OpenRulesLibrary {
488        #[serde(skip)]
489        pub prompt_to_select: Option<Uuid>,
490    }
491
492    /// Deploys the assistant interface with the specified configuration.
493    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema, Action)]
494    #[action(namespace = assistant)]
495    #[serde(deny_unknown_fields)]
496    pub struct InlineAssist {
497        pub prompt: Option<String>,
498    }
499}
500
501pub mod debugger {
502    use gpui::actions;
503
504    actions!(
505        debugger,
506        [
507            /// Opens the debugger onboarding modal.
508            OpenOnboardingModal,
509            /// Resets the debugger onboarding state.
510            ResetOnboarding
511        ]
512    );
513}
514
515/// Opens the recent projects interface.
516#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
517#[action(namespace = projects)]
518#[serde(deny_unknown_fields)]
519pub struct OpenRecent {
520    #[serde(default)]
521    pub create_new_window: bool,
522}
523
524/// Creates a project from a selected template.
525#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
526#[action(namespace = projects)]
527#[serde(deny_unknown_fields)]
528pub struct OpenRemote {
529    #[serde(default)]
530    pub from_existing_connection: bool,
531    #[serde(default)]
532    pub create_new_window: bool,
533}
534
535/// Opens the dev container connection modal.
536#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
537#[action(namespace = projects)]
538#[serde(deny_unknown_fields)]
539pub struct OpenDevContainer;
540
541/// Where to spawn the task in the UI.
542#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
543#[serde(rename_all = "snake_case")]
544pub enum RevealTarget {
545    /// In the central pane group, "main" editor area.
546    Center,
547    /// In the terminal dock, "regular" terminal items' place.
548    #[default]
549    Dock,
550}
551
552/// Spawns a task with name or opens tasks modal.
553#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema, Action)]
554#[action(namespace = task)]
555#[serde(untagged)]
556pub enum Spawn {
557    /// Spawns a task by the name given.
558    ByName {
559        task_name: String,
560        #[serde(default)]
561        reveal_target: Option<RevealTarget>,
562    },
563    /// Spawns a task by the tag given.
564    ByTag {
565        task_tag: String,
566        #[serde(default)]
567        reveal_target: Option<RevealTarget>,
568    },
569    /// Spawns a task via modal's selection.
570    ViaModal {
571        /// Selected task's `reveal_target` property override.
572        #[serde(default)]
573        reveal_target: Option<RevealTarget>,
574    },
575}
576
577impl Spawn {
578    pub fn modal() -> Self {
579        Self::ViaModal {
580            reveal_target: None,
581        }
582    }
583}
584
585/// Reruns the last task.
586#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
587#[action(namespace = task)]
588#[serde(deny_unknown_fields)]
589pub struct Rerun {
590    /// Controls whether the task context is reevaluated prior to execution of a task.
591    /// 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
592    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
593    /// default: false
594    #[serde(default)]
595    pub reevaluate_context: bool,
596    /// Overrides `allow_concurrent_runs` property of the task being reran.
597    /// Default: null
598    #[serde(default)]
599    pub allow_concurrent_runs: Option<bool>,
600    /// Overrides `use_new_terminal` property of the task being reran.
601    /// Default: null
602    #[serde(default)]
603    pub use_new_terminal: Option<bool>,
604
605    /// If present, rerun the task with this ID, otherwise rerun the last task.
606    #[serde(skip)]
607    pub task_id: Option<String>,
608}
609
610pub mod outline {
611    use std::sync::OnceLock;
612
613    use gpui::{AnyView, App, Window, actions};
614
615    actions!(
616        outline,
617        [
618            #[action(name = "Toggle")]
619            ToggleOutline
620        ]
621    );
622    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
623    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
624}
625
626actions!(
627    zed_predict_onboarding,
628    [
629        /// Opens the Zed Predict onboarding modal.
630        OpenZedPredictOnboarding
631    ]
632);
633actions!(
634    git_onboarding,
635    [
636        /// Opens the git integration onboarding modal.
637        OpenGitIntegrationOnboarding
638    ]
639);
640
641actions!(
642    debug_panel,
643    [
644        /// Toggles focus on the debug panel.
645        ToggleFocus
646    ]
647);
648actions!(
649    debugger,
650    [
651        /// Toggles the enabled state of a breakpoint.
652        ToggleEnableBreakpoint,
653        /// Removes a breakpoint.
654        UnsetBreakpoint,
655        /// Opens the project debug tasks configuration.
656        OpenProjectDebugTasks,
657    ]
658);
659
660pub mod vim {
661    use gpui::actions;
662
663    actions!(
664        vim,
665        [
666            /// Opens the default keymap file.
667            OpenDefaultKeymap
668        ]
669    );
670}
671
672#[derive(Debug, Clone, PartialEq, Eq, Hash)]
673pub struct WslConnectionOptions {
674    pub distro_name: String,
675    pub user: Option<String>,
676}
677
678#[cfg(target_os = "windows")]
679pub mod wsl_actions {
680    use gpui::Action;
681    use schemars::JsonSchema;
682    use serde::Deserialize;
683
684    /// Opens a folder inside Wsl.
685    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
686    #[action(namespace = projects)]
687    #[serde(deny_unknown_fields)]
688    pub struct OpenFolderInWsl {
689        #[serde(default)]
690        pub create_new_window: bool,
691    }
692
693    /// Open a wsl distro.
694    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
695    #[action(namespace = projects)]
696    #[serde(deny_unknown_fields)]
697    pub struct OpenWsl {
698        #[serde(default)]
699        pub create_new_window: bool,
700    }
701}
702
703pub mod preview {
704    pub mod markdown {
705        use gpui::actions;
706
707        actions!(
708            markdown,
709            [
710                /// Opens a markdown preview for the current file.
711                OpenPreview,
712                /// Opens a markdown preview in a split pane.
713                OpenPreviewToTheSide,
714            ]
715        );
716    }
717
718    pub mod svg {
719        use gpui::actions;
720
721        actions!(
722            svg,
723            [
724                /// Opens an SVG preview for the current file.
725                OpenPreview,
726                /// Opens an SVG preview in a split pane.
727                OpenPreviewToTheSide,
728            ]
729        );
730    }
731}