Eliminate GPUI View, ViewContext, and WindowContext types (#22632)
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>
This commit is contained in:
parent
21b4a0d50e
commit
6fca1d2b0b
648 changed files with 36248 additions and 28208 deletions
|
@ -9,9 +9,7 @@ use client::{proto, Client};
|
|||
use collections::BTreeMap;
|
||||
|
||||
use futures::{channel::mpsc, io::BufReader, AsyncBufReadExt, StreamExt};
|
||||
use gpui::{
|
||||
actions, AppContext, AsyncAppContext, EntityId, Global, Model, ModelContext, Task, WeakModel,
|
||||
};
|
||||
use gpui::{actions, App, AsyncAppContext, Context, Entity, EntityId, Global, Task, WeakEntity};
|
||||
use language::{
|
||||
language_settings::all_language_settings, Anchor, Buffer, BufferSnapshot, ToOffset,
|
||||
};
|
||||
|
@ -29,8 +27,8 @@ use util::ResultExt;
|
|||
|
||||
actions!(supermaven, [SignOut]);
|
||||
|
||||
pub fn init(client: Arc<Client>, cx: &mut AppContext) {
|
||||
let supermaven = cx.new_model(|_| Supermaven::Starting);
|
||||
pub fn init(client: Arc<Client>, cx: &mut App) {
|
||||
let supermaven = cx.new(|_| Supermaven::Starting);
|
||||
Supermaven::set_global(supermaven.clone(), cx);
|
||||
|
||||
let mut provider = all_language_settings(None, cx).inline_completions.provider;
|
||||
|
@ -73,21 +71,21 @@ pub enum AccountStatus {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct SupermavenGlobal(Model<Supermaven>);
|
||||
struct SupermavenGlobal(Entity<Supermaven>);
|
||||
|
||||
impl Global for SupermavenGlobal {}
|
||||
|
||||
impl Supermaven {
|
||||
pub fn global(cx: &AppContext) -> Option<Model<Self>> {
|
||||
pub fn global(cx: &App) -> Option<Entity<Self>> {
|
||||
cx.try_global::<SupermavenGlobal>()
|
||||
.map(|model| model.0.clone())
|
||||
}
|
||||
|
||||
pub fn set_global(supermaven: Model<Self>, cx: &mut AppContext) {
|
||||
pub fn set_global(supermaven: Entity<Self>, cx: &mut App) {
|
||||
cx.set_global(SupermavenGlobal(supermaven));
|
||||
}
|
||||
|
||||
pub fn start(&mut self, client: Arc<Client>, cx: &mut ModelContext<Self>) {
|
||||
pub fn start(&mut self, client: Arc<Client>, cx: &mut Context<Self>) {
|
||||
if let Self::Starting = self {
|
||||
cx.spawn(|this, mut cx| async move {
|
||||
let binary_path =
|
||||
|
@ -115,9 +113,9 @@ impl Supermaven {
|
|||
|
||||
pub fn complete(
|
||||
&mut self,
|
||||
buffer: &Model<Buffer>,
|
||||
buffer: &Entity<Buffer>,
|
||||
cursor_position: Anchor,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Option<SupermavenCompletion> {
|
||||
if let Self::Spawned(agent) = self {
|
||||
let buffer_id = buffer.entity_id();
|
||||
|
@ -179,9 +177,9 @@ impl Supermaven {
|
|||
|
||||
pub fn completion(
|
||||
&self,
|
||||
buffer: &Model<Buffer>,
|
||||
buffer: &Entity<Buffer>,
|
||||
cursor_position: Anchor,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Option<&str> {
|
||||
if let Self::Spawned(agent) = self {
|
||||
find_relevant_completion(
|
||||
|
@ -267,7 +265,7 @@ impl SupermavenAgent {
|
|||
fn new(
|
||||
binary_path: PathBuf,
|
||||
client: Arc<Client>,
|
||||
cx: &mut ModelContext<Supermaven>,
|
||||
cx: &mut Context<Supermaven>,
|
||||
) -> Result<Self> {
|
||||
let mut process = util::command::new_smol_command(&binary_path)
|
||||
.arg("stdio")
|
||||
|
@ -342,7 +340,7 @@ impl SupermavenAgent {
|
|||
}
|
||||
|
||||
async fn handle_incoming_messages(
|
||||
this: WeakModel<Supermaven>,
|
||||
this: WeakEntity<Supermaven>,
|
||||
stdout: ChildStdout,
|
||||
mut cx: AsyncAppContext,
|
||||
) -> Result<()> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{Supermaven, SupermavenCompletionStateId};
|
||||
use anyhow::Result;
|
||||
use futures::StreamExt as _;
|
||||
use gpui::{AppContext, EntityId, Model, ModelContext, Task};
|
||||
use gpui::{App, Context, Entity, EntityId, Task};
|
||||
use inline_completion::{Direction, InlineCompletion, InlineCompletionProvider};
|
||||
use language::{language_settings::all_language_settings, Anchor, Buffer, BufferSnapshot};
|
||||
use std::{
|
||||
|
@ -15,7 +15,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
|||
pub const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(75);
|
||||
|
||||
pub struct SupermavenCompletionProvider {
|
||||
supermaven: Model<Supermaven>,
|
||||
supermaven: Entity<Supermaven>,
|
||||
buffer_id: Option<EntityId>,
|
||||
completion_id: Option<SupermavenCompletionStateId>,
|
||||
file_extension: Option<String>,
|
||||
|
@ -23,7 +23,7 @@ pub struct SupermavenCompletionProvider {
|
|||
}
|
||||
|
||||
impl SupermavenCompletionProvider {
|
||||
pub fn new(supermaven: Model<Supermaven>) -> Self {
|
||||
pub fn new(supermaven: Entity<Supermaven>) -> Self {
|
||||
Self {
|
||||
supermaven,
|
||||
buffer_id: None,
|
||||
|
@ -113,7 +113,7 @@ impl InlineCompletionProvider for SupermavenCompletionProvider {
|
|||
false
|
||||
}
|
||||
|
||||
fn is_enabled(&self, buffer: &Model<Buffer>, cursor_position: Anchor, cx: &AppContext) -> bool {
|
||||
fn is_enabled(&self, buffer: &Entity<Buffer>, cursor_position: Anchor, cx: &App) -> bool {
|
||||
if !self.supermaven.read(cx).is_enabled() {
|
||||
return false;
|
||||
}
|
||||
|
@ -131,10 +131,10 @@ impl InlineCompletionProvider for SupermavenCompletionProvider {
|
|||
|
||||
fn refresh(
|
||||
&mut self,
|
||||
buffer_handle: Model<Buffer>,
|
||||
buffer_handle: Entity<Buffer>,
|
||||
cursor_position: Anchor,
|
||||
debounce: bool,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) {
|
||||
let Some(mut completion) = self.supermaven.update(cx, |supermaven, cx| {
|
||||
supermaven.complete(&buffer_handle, cursor_position, cx)
|
||||
|
@ -169,28 +169,28 @@ impl InlineCompletionProvider for SupermavenCompletionProvider {
|
|||
|
||||
fn cycle(
|
||||
&mut self,
|
||||
_buffer: Model<Buffer>,
|
||||
_buffer: Entity<Buffer>,
|
||||
_cursor_position: Anchor,
|
||||
_direction: Direction,
|
||||
_cx: &mut ModelContext<Self>,
|
||||
_cx: &mut Context<Self>,
|
||||
) {
|
||||
}
|
||||
|
||||
fn accept(&mut self, _cx: &mut ModelContext<Self>) {
|
||||
fn accept(&mut self, _cx: &mut Context<Self>) {
|
||||
self.pending_refresh = None;
|
||||
self.completion_id = None;
|
||||
}
|
||||
|
||||
fn discard(&mut self, _cx: &mut ModelContext<Self>) {
|
||||
fn discard(&mut self, _cx: &mut Context<Self>) {
|
||||
self.pending_refresh = None;
|
||||
self.completion_id = None;
|
||||
}
|
||||
|
||||
fn suggest(
|
||||
&mut self,
|
||||
buffer: &Model<Buffer>,
|
||||
buffer: &Entity<Buffer>,
|
||||
cursor_position: Anchor,
|
||||
cx: &mut ModelContext<Self>,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Option<InlineCompletion> {
|
||||
let completion_text = self
|
||||
.supermaven
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue