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