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