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#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
 15#[action(namespace = zed)]
 16#[serde(deny_unknown_fields)]
 17pub struct OpenBrowser {
 18    pub url: String,
 19}
 20
 21#[derive(Clone, PartialEq, Deserialize, JsonSchema, Action)]
 22#[action(namespace = zed)]
 23#[serde(deny_unknown_fields)]
 24pub struct OpenZedUrl {
 25    pub url: String,
 26}
 27
 28actions!(
 29    zed,
 30    [
 31        OpenSettings,
 32        OpenDefaultKeymap,
 33        OpenAccountSettings,
 34        OpenServerSettings,
 35        Quit,
 36        OpenKeymap,
 37        About,
 38        OpenDocs,
 39        OpenLicenses,
 40        OpenTelemetryLog,
 41    ]
 42);
 43
 44#[derive(PartialEq, Clone, Copy, Debug, Deserialize, JsonSchema)]
 45#[serde(rename_all = "snake_case")]
 46pub enum ExtensionCategoryFilter {
 47    Themes,
 48    IconThemes,
 49    Languages,
 50    Grammars,
 51    LanguageServers,
 52    ContextServers,
 53    SlashCommands,
 54    IndexedDocsProviders,
 55    Snippets,
 56    DebugAdapters,
 57}
 58
 59#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 60#[action(namespace = zed)]
 61pub struct Extensions {
 62    /// Filters the extensions page down to extensions that are in the specified category.
 63    #[serde(default)]
 64    pub category_filter: Option<ExtensionCategoryFilter>,
 65}
 66
 67#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 68#[action(namespace = zed)]
 69pub struct DecreaseBufferFontSize {
 70    #[serde(default)]
 71    pub persist: bool,
 72}
 73
 74#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 75#[action(namespace = zed)]
 76pub struct IncreaseBufferFontSize {
 77    #[serde(default)]
 78    pub persist: bool,
 79}
 80
 81#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 82#[action(namespace = zed)]
 83pub struct ResetBufferFontSize {
 84    #[serde(default)]
 85    pub persist: bool,
 86}
 87
 88#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 89#[action(namespace = zed)]
 90pub struct DecreaseUiFontSize {
 91    #[serde(default)]
 92    pub persist: bool,
 93}
 94
 95#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
 96#[action(namespace = zed)]
 97pub struct IncreaseUiFontSize {
 98    #[serde(default)]
 99    pub persist: bool,
100}
101
102#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
103#[action(namespace = zed)]
104pub struct ResetUiFontSize {
105    #[serde(default)]
106    pub persist: bool,
107}
108
109pub mod dev {
110    use gpui::actions;
111
112    actions!(dev, [ToggleInspector]);
113}
114
115pub mod workspace {
116    use gpui::actions;
117
118    actions!(
119        workspace,
120        [
121            #[action(deprecated_aliases = ["editor::CopyPath", "outline_panel::CopyPath", "project_panel::CopyPath"])]
122            CopyPath,
123            #[action(deprecated_aliases = ["editor::CopyRelativePath", "outline_panel::CopyRelativePath", "project_panel::CopyRelativePath"])]
124            CopyRelativePath
125        ]
126    );
127}
128
129pub mod git {
130    use gpui::actions;
131
132    actions!(
133        git,
134        [
135            CheckoutBranch,
136            Switch,
137            SelectRepo,
138            #[action(deprecated_aliases = ["branches::OpenRecent"])]
139            Branch
140        ]
141    );
142}
143
144pub mod jj {
145    use gpui::actions;
146
147    actions!(jj, [BookmarkList]);
148}
149
150pub mod toast {
151    use gpui::actions;
152
153    actions!(toast, [RunAction]);
154}
155
156pub mod command_palette {
157    use gpui::actions;
158
159    actions!(command_palette, [Toggle]);
160}
161
162pub mod feedback {
163    use gpui::actions;
164
165    actions!(feedback, [FileBugReport, GiveFeedback]);
166}
167
168pub mod theme_selector {
169    use gpui::Action;
170    use schemars::JsonSchema;
171    use serde::Deserialize;
172
173    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
174    #[action(namespace = theme_selector)]
175    #[serde(deny_unknown_fields)]
176    pub struct Toggle {
177        /// A list of theme names to filter the theme selector down to.
178        pub themes_filter: Option<Vec<String>>,
179    }
180}
181
182pub mod icon_theme_selector {
183    use gpui::Action;
184    use schemars::JsonSchema;
185    use serde::Deserialize;
186
187    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
188    #[action(namespace = icon_theme_selector)]
189    #[serde(deny_unknown_fields)]
190    pub struct Toggle {
191        /// A list of icon theme names to filter the theme selector down to.
192        pub themes_filter: Option<Vec<String>>,
193    }
194}
195
196pub mod agent {
197    use gpui::actions;
198
199    actions!(
200        agent,
201        [OpenConfiguration, OpenOnboardingModal, ResetOnboarding]
202    );
203}
204
205pub mod assistant {
206    use gpui::{Action, actions};
207    use schemars::JsonSchema;
208    use serde::Deserialize;
209    use uuid::Uuid;
210
211    actions!(
212        agent,
213        [
214            #[action(deprecated_aliases = ["assistant::ToggleFocus"])]
215            ToggleFocus
216        ]
217    );
218
219    actions!(assistant, [ShowConfiguration]);
220
221    #[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema, Action)]
222    #[action(namespace = agent, deprecated_aliases = ["assistant::OpenRulesLibrary", "assistant::DeployPromptLibrary"])]
223    #[serde(deny_unknown_fields)]
224    pub struct OpenRulesLibrary {
225        #[serde(skip)]
226        pub prompt_to_select: Option<Uuid>,
227    }
228
229    #[derive(Clone, Default, Deserialize, PartialEq, JsonSchema, Action)]
230    #[action(namespace = assistant)]
231    #[serde(deny_unknown_fields)]
232    pub struct InlineAssist {
233        pub prompt: Option<String>,
234    }
235}
236
237pub mod debugger {
238    use gpui::actions;
239
240    actions!(debugger, [OpenOnboardingModal, ResetOnboarding]);
241}
242
243#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
244#[action(namespace = projects)]
245#[serde(deny_unknown_fields)]
246pub struct OpenRecent {
247    #[serde(default)]
248    pub create_new_window: bool,
249}
250
251#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
252#[action(namespace = projects)]
253#[serde(deny_unknown_fields)]
254pub struct OpenRemote {
255    #[serde(default)]
256    pub from_existing_connection: bool,
257    #[serde(default)]
258    pub create_new_window: bool,
259}
260
261/// Where to spawn the task in the UI.
262#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
263#[serde(rename_all = "snake_case")]
264pub enum RevealTarget {
265    /// In the central pane group, "main" editor area.
266    Center,
267    /// In the terminal dock, "regular" terminal items' place.
268    #[default]
269    Dock,
270}
271
272/// Spawn a task with name or open tasks modal.
273#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema, Action)]
274#[action(namespace = task)]
275#[serde(untagged)]
276pub enum Spawn {
277    /// Spawns a task by the name given.
278    ByName {
279        task_name: String,
280        #[serde(default)]
281        reveal_target: Option<RevealTarget>,
282    },
283    /// Spawns a task by the name given.
284    ByTag {
285        task_tag: String,
286        #[serde(default)]
287        reveal_target: Option<RevealTarget>,
288    },
289    /// Spawns a task via modal's selection.
290    ViaModal {
291        /// Selected task's `reveal_target` property override.
292        #[serde(default)]
293        reveal_target: Option<RevealTarget>,
294    },
295}
296
297impl Spawn {
298    pub fn modal() -> Self {
299        Self::ViaModal {
300            reveal_target: None,
301        }
302    }
303}
304
305/// Rerun the last task.
306#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema, Action)]
307#[action(namespace = task)]
308#[serde(deny_unknown_fields)]
309pub struct Rerun {
310    /// Controls whether the task context is reevaluated prior to execution of a task.
311    /// 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
312    /// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
313    /// default: false
314    #[serde(default)]
315    pub reevaluate_context: bool,
316    /// Overrides `allow_concurrent_runs` property of the task being reran.
317    /// Default: null
318    #[serde(default)]
319    pub allow_concurrent_runs: Option<bool>,
320    /// Overrides `use_new_terminal` property of the task being reran.
321    /// Default: null
322    #[serde(default)]
323    pub use_new_terminal: Option<bool>,
324
325    /// If present, rerun the task with this ID, otherwise rerun the last task.
326    #[serde(skip)]
327    pub task_id: Option<String>,
328}
329
330pub mod outline {
331    use std::sync::OnceLock;
332
333    use gpui::{AnyView, App, Window, actions};
334
335    actions!(
336        outline,
337        [
338            #[action(name = "Toggle")]
339            ToggleOutline
340        ]
341    );
342    /// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
343    pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
344}
345
346actions!(zed_predict_onboarding, [OpenZedPredictOnboarding]);
347actions!(git_onboarding, [OpenGitIntegrationOnboarding]);
348
349actions!(debug_panel, [ToggleFocus]);
350actions!(
351    debugger,
352    [
353        ToggleEnableBreakpoint,
354        UnsetBreakpoint,
355        OpenProjectDebugTasks,
356    ]
357);