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