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