lib.rs

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