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 toast {
191    use gpui::actions;
192
193    actions!(
194        toast,
195        [
196            /// Runs the action associated with a toast notification.
197            RunAction
198        ]
199    );
200}
201
202pub mod command_palette {
203    use gpui::actions;
204
205    actions!(
206        command_palette,
207        [
208            /// Toggles the command palette.
209            Toggle
210        ]
211    );
212}
213
214pub mod feedback {
215    use gpui::actions;
216
217    actions!(
218        feedback,
219        [
220            /// Opens the bug report form.
221            FileBugReport,
222            /// Opens the feedback form.
223            GiveFeedback
224        ]
225    );
226}
227
228pub mod theme_selector {
229    use gpui::Action;
230    use schemars::JsonSchema;
231    use serde::Deserialize;
232
233    /// Toggles the theme selector interface.
234    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
235    #[action(namespace = theme_selector)]
236    #[serde(deny_unknown_fields)]
237    pub struct Toggle {
238        /// A list of theme names to filter the theme selector down to.
239        pub themes_filter: Option<Vec<String>>,
240    }
241}
242
243pub mod icon_theme_selector {
244    use gpui::Action;
245    use schemars::JsonSchema;
246    use serde::Deserialize;
247
248    /// Toggles the icon theme selector interface.
249    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
250    #[action(namespace = icon_theme_selector)]
251    #[serde(deny_unknown_fields)]
252    pub struct Toggle {
253        /// A list of icon theme names to filter the theme selector down to.
254        pub themes_filter: Option<Vec<String>>,
255    }
256}
257
258pub mod settings_profile_selector {
259    use gpui::Action;
260    use schemars::JsonSchema;
261    use serde::Deserialize;
262
263    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
264    #[action(namespace = settings_profile_selector)]
265    pub struct Toggle;
266}
267
268pub mod agent {
269    use gpui::actions;
270
271    actions!(
272        agent,
273        [
274            /// Opens the agent settings panel.
275            #[action(deprecated_aliases = ["agent::OpenConfiguration"])]
276            OpenSettings,
277            /// Opens the agent onboarding modal.
278            OpenOnboardingModal,
279            /// Opens the ACP onboarding modal.
280            OpenAcpOnboardingModal,
281            /// Opens the Claude Code onboarding modal.
282            OpenClaudeCodeOnboardingModal,
283            /// Resets the agent onboarding state.
284            ResetOnboarding,
285            /// Starts a chat conversation with the agent.
286            Chat,
287            /// Toggles the language model selector dropdown.
288            #[action(deprecated_aliases = ["assistant::ToggleModelSelector", "assistant2::ToggleModelSelector"])]
289            ToggleModelSelector,
290            /// Triggers re-authentication on Gemini
291            ReauthenticateAgent
292        ]
293    );
294}
295
296pub mod assistant {
297    use gpui::{Action, actions};
298    use schemars::JsonSchema;
299    use serde::Deserialize;
300    use uuid::Uuid;
301
302    actions!(
303        agent,
304        [
305            #[action(deprecated_aliases = ["assistant::ToggleFocus"])]
306            ToggleFocus
307        ]
308    );
309
310    actions!(
311        assistant,
312        [
313            /// Shows the assistant configuration panel.
314            ShowConfiguration
315        ]
316    );
317
318    /// Opens the rules library for managing agent rules and prompts.
319    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
320    #[action(namespace = agent, deprecated_aliases = ["assistant::OpenRulesLibrary", "assistant::DeployPromptLibrary"])]
321    #[serde(deny_unknown_fields)]
322    pub struct OpenRulesLibrary {
323        #[serde(skip)]
324        pub prompt_to_select: Option<Uuid>,
325    }
326
327    /// Deploys the assistant interface with the specified configuration.
328    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema, Action)]
329    #[action(namespace = assistant)]
330    #[serde(deny_unknown_fields)]
331    pub struct InlineAssist {
332        pub prompt: Option<String>,
333    }
334}
335
336pub mod debugger {
337    use gpui::actions;
338
339    actions!(
340        debugger,
341        [
342            /// Opens the debugger onboarding modal.
343            OpenOnboardingModal,
344            /// Resets the debugger onboarding state.
345            ResetOnboarding
346        ]
347    );
348}
349
350/// Opens the recent projects interface.
351#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
352#[action(namespace = projects)]
353#[serde(deny_unknown_fields)]
354pub struct OpenRecent {
355    #[serde(default)]
356    pub create_new_window: bool,
357}
358
359/// Creates a project from a selected template.
360#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
361#[action(namespace = projects)]
362#[serde(deny_unknown_fields)]
363pub struct OpenRemote {
364    #[serde(default)]
365    pub from_existing_connection: bool,
366    #[serde(default)]
367    pub create_new_window: bool,
368}
369
370/// Where to spawn the task in the UI.
371#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
372#[serde(rename_all = "snake_case")]
373pub enum RevealTarget {
374    /// In the central pane group, "main" editor area.
375    Center,
376    /// In the terminal dock, "regular" terminal items' place.
377    #[default]
378    Dock,
379}
380
381/// Spawns a task with name or opens tasks modal.
382#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema, Action)]
383#[action(namespace = task)]
384#[serde(untagged)]
385pub enum Spawn {
386    /// Spawns a task by the name given.
387    ByName {
388        task_name: String,
389        #[serde(default)]
390        reveal_target: Option<RevealTarget>,
391    },
392    /// Spawns a task by the name given.
393    ByTag {
394        task_tag: String,
395        #[serde(default)]
396        reveal_target: Option<RevealTarget>,
397    },
398    /// Spawns a task via modal's selection.
399    ViaModal {
400        /// Selected task's `reveal_target` property override.
401        #[serde(default)]
402        reveal_target: Option<RevealTarget>,
403    },
404}
405
406impl Spawn {
407    pub fn modal() -> Self {
408        Self::ViaModal {
409            reveal_target: None,
410        }
411    }
412}
413
414/// Reruns the last task.
415#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
416#[action(namespace = task)]
417#[serde(deny_unknown_fields)]
418pub struct Rerun {
419    /// Controls whether the task context is reevaluated prior to execution of a task.
420    /// 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
421    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
422    /// default: false
423    #[serde(default)]
424    pub reevaluate_context: bool,
425    /// Overrides `allow_concurrent_runs` property of the task being reran.
426    /// Default: null
427    #[serde(default)]
428    pub allow_concurrent_runs: Option<bool>,
429    /// Overrides `use_new_terminal` property of the task being reran.
430    /// Default: null
431    #[serde(default)]
432    pub use_new_terminal: Option<bool>,
433
434    /// If present, rerun the task with this ID, otherwise rerun the last task.
435    #[serde(skip)]
436    pub task_id: Option<String>,
437}
438
439pub mod outline {
440    use std::sync::OnceLock;
441
442    use gpui::{AnyView, App, Window, actions};
443
444    actions!(
445        outline,
446        [
447            #[action(name = "Toggle")]
448            ToggleOutline
449        ]
450    );
451    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
452    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
453}
454
455actions!(
456    zed_predict_onboarding,
457    [
458        /// Opens the Zed Predict onboarding modal.
459        OpenZedPredictOnboarding
460    ]
461);
462actions!(
463    git_onboarding,
464    [
465        /// Opens the git integration onboarding modal.
466        OpenGitIntegrationOnboarding
467    ]
468);
469
470actions!(
471    debug_panel,
472    [
473        /// Toggles focus on the debug panel.
474        ToggleFocus
475    ]
476);
477actions!(
478    debugger,
479    [
480        /// Toggles the enabled state of a breakpoint.
481        ToggleEnableBreakpoint,
482        /// Removes a breakpoint.
483        UnsetBreakpoint,
484        /// Opens the project debug tasks configuration.
485        OpenProjectDebugTasks,
486    ]
487);
488
489#[cfg(target_os = "windows")]
490pub mod wsl_actions {
491    use gpui::Action;
492    use schemars::JsonSchema;
493    use serde::Deserialize;
494
495    /// Opens a folder inside Wsl.
496    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
497    #[action(namespace = projects)]
498    #[serde(deny_unknown_fields)]
499    pub struct OpenFolderInWsl {
500        #[serde(default)]
501        pub create_new_window: bool,
502    }
503
504    /// Open a wsl distro.
505    #[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
506    #[action(namespace = projects)]
507    #[serde(deny_unknown_fields)]
508    pub struct OpenWsl {
509        #[serde(default)]
510        pub create_new_window: bool,
511    }
512}