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