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