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