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