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