
There's still a bit more work to do on this, but this PR is compiling (with warnings) after eliminating the key types. When the tasks below are complete, this will be the new narrative for GPUI: - `Entity<T>` - This replaces `View<T>`/`Model<T>`. It represents a unit of state, and if `T` implements `Render`, then `Entity<T>` implements `Element`. - `&mut App` This replaces `AppContext` and represents the app. - `&mut Context<T>` This replaces `ModelContext` and derefs to `App`. It is provided by the framework when updating an entity. - `&mut Window` Broken out of `&mut WindowContext` which no longer exists. Every method that once took `&mut WindowContext` now takes `&mut Window, &mut App` and every method that took `&mut ViewContext<T>` now takes `&mut Window, &mut Context<T>` Not pictured here are the two other failed attempts. It's been quite a month! Tasks: - [x] Remove `View`, `ViewContext`, `WindowContext` and thread through `Window` - [x] [@cole-miller @mikayla-maki] Redraw window when entities change - [x] [@cole-miller @mikayla-maki] Get examples and Zed running - [x] [@cole-miller @mikayla-maki] Fix Zed rendering - [x] [@mikayla-maki] Fix todo! macros and comments - [x] Fix a bug where the editor would not be redrawn because of view caching - [x] remove publicness window.notify() and replace with `AppContext::notify` - [x] remove `observe_new_window_models`, replace with `observe_new_models` with an optional window - [x] Fix a bug where the project panel would not be redrawn because of the wrong refresh() call being used - [x] Fix the tests - [x] Fix warnings by eliminating `Window` params or using `_` - [x] Fix conflicts - [x] Simplify generic code where possible - [x] Rename types - [ ] Update docs ### issues post merge - [x] Issues switching between normal and insert mode - [x] Assistant re-rendering failure - [x] Vim test failures - [x] Mac build issue Release Notes: - N/A --------- Co-authored-by: Antonio Scandurra <me@as-cii.com> Co-authored-by: Cole Miller <cole@zed.dev> Co-authored-by: Mikayla <mikayla@zed.dev> Co-authored-by: Joseph <joseph@zed.dev> Co-authored-by: max <max@zed.dev> Co-authored-by: Michael Sloan <michael@zed.dev> Co-authored-by: Mikayla Maki <mikaylamaki@Mikaylas-MacBook-Pro.local> Co-authored-by: Mikayla <mikayla.c.maki@gmail.com> Co-authored-by: joão <joao@zed.dev>
174 lines
4.6 KiB
Rust
174 lines
4.6 KiB
Rust
use gpui::{actions, impl_actions};
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
// If the zed binary doesn't use anything in this crate, it will be optimized away
|
|
// and the actions won't initialize. So we just provide an empty initialization function
|
|
// to be called from main.
|
|
//
|
|
// These may provide relevant context:
|
|
// https://github.com/rust-lang/rust/issues/47384
|
|
// https://github.com/mmastrac/rust-ctor/issues/280
|
|
pub fn init() {}
|
|
|
|
#[derive(Clone, PartialEq, Deserialize, JsonSchema)]
|
|
pub struct OpenBrowser {
|
|
pub url: String,
|
|
}
|
|
|
|
#[derive(Clone, PartialEq, Deserialize, JsonSchema)]
|
|
pub struct OpenZedUrl {
|
|
pub url: String,
|
|
}
|
|
|
|
impl_actions!(zed, [OpenBrowser, OpenZedUrl]);
|
|
|
|
actions!(
|
|
zed,
|
|
[
|
|
OpenSettings,
|
|
OpenDefaultKeymap,
|
|
OpenAccountSettings,
|
|
OpenServerSettings,
|
|
Quit,
|
|
OpenKeymap,
|
|
About,
|
|
Extensions,
|
|
OpenLicenses,
|
|
OpenTelemetryLog,
|
|
DecreaseBufferFontSize,
|
|
IncreaseBufferFontSize,
|
|
ResetBufferFontSize,
|
|
DecreaseUiFontSize,
|
|
IncreaseUiFontSize,
|
|
ResetUiFontSize
|
|
]
|
|
);
|
|
|
|
pub mod branches {
|
|
use gpui::actions;
|
|
|
|
actions!(branches, [OpenRecent]);
|
|
}
|
|
|
|
pub mod command_palette {
|
|
use gpui::actions;
|
|
|
|
actions!(command_palette, [Toggle]);
|
|
}
|
|
|
|
pub mod feedback {
|
|
use gpui::actions;
|
|
|
|
actions!(feedback, [GiveFeedback]);
|
|
}
|
|
|
|
pub mod theme_selector {
|
|
use gpui::impl_actions;
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
|
|
#[derive(PartialEq, Clone, Default, Debug, Deserialize, JsonSchema)]
|
|
pub struct Toggle {
|
|
/// A list of theme names to filter the theme selector down to.
|
|
pub themes_filter: Option<Vec<String>>,
|
|
}
|
|
|
|
impl_actions!(theme_selector, [Toggle]);
|
|
}
|
|
|
|
pub mod assistant {
|
|
use gpui::{actions, impl_actions};
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
|
|
actions!(assistant, [ToggleFocus, DeployPromptLibrary]);
|
|
|
|
#[derive(Clone, Default, Deserialize, PartialEq, JsonSchema)]
|
|
pub struct InlineAssist {
|
|
pub prompt: Option<String>,
|
|
}
|
|
|
|
impl_actions!(assistant, [InlineAssist]);
|
|
}
|
|
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
pub struct OpenRecent {
|
|
#[serde(default)]
|
|
pub create_new_window: bool,
|
|
}
|
|
|
|
impl_actions!(projects, [OpenRecent]);
|
|
actions!(projects, [OpenRemote]);
|
|
|
|
/// Where to spawn the task in the UI.
|
|
#[derive(Default, Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum RevealTarget {
|
|
/// In the central pane group, "main" editor area.
|
|
Center,
|
|
/// In the terminal dock, "regular" terminal items' place.
|
|
#[default]
|
|
Dock,
|
|
}
|
|
|
|
/// Spawn a task with name or open tasks modal.
|
|
#[derive(Debug, PartialEq, Clone, Deserialize, JsonSchema)]
|
|
#[serde(untagged)]
|
|
pub enum Spawn {
|
|
/// Spawns a task by the name given.
|
|
ByName {
|
|
task_name: String,
|
|
#[serde(default)]
|
|
reveal_target: Option<RevealTarget>,
|
|
},
|
|
/// Spawns a task via modal's selection.
|
|
ViaModal {
|
|
/// Selected task's `reveal_target` property override.
|
|
#[serde(default)]
|
|
reveal_target: Option<RevealTarget>,
|
|
},
|
|
}
|
|
|
|
impl Spawn {
|
|
pub fn modal() -> Self {
|
|
Self::ViaModal {
|
|
reveal_target: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Rerun the last task.
|
|
#[derive(PartialEq, Clone, Deserialize, Default, JsonSchema)]
|
|
pub struct Rerun {
|
|
/// Controls whether the task context is reevaluated prior to execution of a task.
|
|
/// 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
|
|
/// If it is, these variables will be updated to reflect current state of editor at the time task::Rerun is executed.
|
|
/// default: false
|
|
#[serde(default)]
|
|
pub reevaluate_context: bool,
|
|
/// Overrides `allow_concurrent_runs` property of the task being reran.
|
|
/// Default: null
|
|
#[serde(default)]
|
|
pub allow_concurrent_runs: Option<bool>,
|
|
/// Overrides `use_new_terminal` property of the task being reran.
|
|
/// Default: null
|
|
#[serde(default)]
|
|
pub use_new_terminal: Option<bool>,
|
|
|
|
/// If present, rerun the task with this ID, otherwise rerun the last task.
|
|
#[serde(skip)]
|
|
pub task_id: Option<String>,
|
|
}
|
|
|
|
impl_actions!(task, [Spawn, Rerun]);
|
|
|
|
pub mod outline {
|
|
use std::sync::OnceLock;
|
|
|
|
use gpui::{action_as, AnyView, App, Window};
|
|
|
|
action_as!(outline, ToggleOutline as Toggle);
|
|
/// A pointer to outline::toggle function, exposed here to sewer the breadcrumbs <-> outline dependency.
|
|
pub static TOGGLE_OUTLINE: OnceLock<fn(AnyView, &mut Window, &mut App)> = OnceLock::new();
|
|
}
|