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
|
@ -11,7 +11,7 @@ use futures::future::BoxFuture;
|
|||
use futures::stream::BoxStream;
|
||||
use futures::{FutureExt, StreamExt};
|
||||
use gpui::{
|
||||
percentage, svg, Animation, AnimationExt, AnyView, AppContext, AsyncAppContext, Model, Render,
|
||||
percentage, svg, Animation, AnimationExt, AnyView, App, AsyncAppContext, Entity, Render,
|
||||
Subscription, Task, Transformation,
|
||||
};
|
||||
use language_model::{
|
||||
|
@ -34,7 +34,7 @@ const PROVIDER_NAME: &str = "GitHub Copilot Chat";
|
|||
pub struct CopilotChatSettings {}
|
||||
|
||||
pub struct CopilotChatLanguageModelProvider {
|
||||
state: Model<State>,
|
||||
state: Entity<State>,
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
|
@ -43,7 +43,7 @@ pub struct State {
|
|||
}
|
||||
|
||||
impl State {
|
||||
fn is_authenticated(&self, cx: &AppContext) -> bool {
|
||||
fn is_authenticated(&self, cx: &App) -> bool {
|
||||
CopilotChat::global(cx)
|
||||
.map(|m| m.read(cx).is_authenticated())
|
||||
.unwrap_or(false)
|
||||
|
@ -51,8 +51,8 @@ impl State {
|
|||
}
|
||||
|
||||
impl CopilotChatLanguageModelProvider {
|
||||
pub fn new(cx: &mut AppContext) -> Self {
|
||||
let state = cx.new_model(|cx| {
|
||||
pub fn new(cx: &mut App) -> Self {
|
||||
let state = cx.new(|cx| {
|
||||
let _copilot_chat_subscription = CopilotChat::global(cx)
|
||||
.map(|copilot_chat| cx.observe(&copilot_chat, |_, _, cx| cx.notify()));
|
||||
State {
|
||||
|
@ -70,7 +70,7 @@ impl CopilotChatLanguageModelProvider {
|
|||
impl LanguageModelProviderState for CopilotChatLanguageModelProvider {
|
||||
type ObservableEntity = State;
|
||||
|
||||
fn observable_entity(&self) -> Option<gpui::Model<Self::ObservableEntity>> {
|
||||
fn observable_entity(&self) -> Option<gpui::Entity<Self::ObservableEntity>> {
|
||||
Some(self.state.clone())
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ impl LanguageModelProvider for CopilotChatLanguageModelProvider {
|
|||
IconName::Copilot
|
||||
}
|
||||
|
||||
fn provided_models(&self, _cx: &AppContext) -> Vec<Arc<dyn LanguageModel>> {
|
||||
fn provided_models(&self, _cx: &App) -> Vec<Arc<dyn LanguageModel>> {
|
||||
CopilotChatModel::iter()
|
||||
.map(|model| {
|
||||
Arc::new(CopilotChatLanguageModel {
|
||||
|
@ -99,11 +99,11 @@ impl LanguageModelProvider for CopilotChatLanguageModelProvider {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn is_authenticated(&self, cx: &AppContext) -> bool {
|
||||
fn is_authenticated(&self, cx: &App) -> bool {
|
||||
self.state.read(cx).is_authenticated(cx)
|
||||
}
|
||||
|
||||
fn authenticate(&self, cx: &mut AppContext) -> Task<Result<()>> {
|
||||
fn authenticate(&self, cx: &mut App) -> Task<Result<()>> {
|
||||
let result = if self.is_authenticated(cx) {
|
||||
Ok(())
|
||||
} else if let Some(copilot) = Copilot::global(cx) {
|
||||
|
@ -125,12 +125,12 @@ impl LanguageModelProvider for CopilotChatLanguageModelProvider {
|
|||
Task::ready(result)
|
||||
}
|
||||
|
||||
fn configuration_view(&self, cx: &mut WindowContext) -> AnyView {
|
||||
fn configuration_view(&self, _: &mut Window, cx: &mut App) -> AnyView {
|
||||
let state = self.state.clone();
|
||||
cx.new_view(|cx| ConfigurationView::new(state, cx)).into()
|
||||
cx.new(|cx| ConfigurationView::new(state, cx)).into()
|
||||
}
|
||||
|
||||
fn reset_credentials(&self, _cx: &mut AppContext) -> Task<Result<()>> {
|
||||
fn reset_credentials(&self, _cx: &mut App) -> Task<Result<()>> {
|
||||
Task::ready(Err(anyhow!(
|
||||
"Signing out of GitHub Copilot Chat is currently not supported."
|
||||
)))
|
||||
|
@ -170,7 +170,7 @@ impl LanguageModel for CopilotChatLanguageModel {
|
|||
fn count_tokens(
|
||||
&self,
|
||||
request: LanguageModelRequest,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> BoxFuture<'static, Result<usize>> {
|
||||
match self.model {
|
||||
CopilotChatModel::Claude3_5Sonnet => count_anthropic_tokens(request, cx),
|
||||
|
@ -294,12 +294,12 @@ impl CopilotChatLanguageModel {
|
|||
|
||||
struct ConfigurationView {
|
||||
copilot_status: Option<copilot::Status>,
|
||||
state: Model<State>,
|
||||
state: Entity<State>,
|
||||
_subscription: Option<Subscription>,
|
||||
}
|
||||
|
||||
impl ConfigurationView {
|
||||
pub fn new(state: Model<State>, cx: &mut ViewContext<Self>) -> Self {
|
||||
pub fn new(state: Entity<State>, cx: &mut Context<Self>) -> Self {
|
||||
let copilot = Copilot::global(cx);
|
||||
|
||||
Self {
|
||||
|
@ -316,7 +316,7 @@ impl ConfigurationView {
|
|||
}
|
||||
|
||||
impl Render for ConfigurationView {
|
||||
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
if self.state.read(cx).is_authenticated(cx) {
|
||||
const LABEL: &str = "Authorized.";
|
||||
h_flex()
|
||||
|
@ -327,7 +327,7 @@ impl Render for ConfigurationView {
|
|||
let loading_icon = svg()
|
||||
.size_8()
|
||||
.path(IconName::ArrowCircle.path())
|
||||
.text_color(cx.text_style().color)
|
||||
.text_color(window.text_style().color)
|
||||
.with_animation(
|
||||
"icon_circle_arrow",
|
||||
Animation::new(Duration::from_secs(2)).repeat(),
|
||||
|
@ -378,7 +378,9 @@ impl Render for ConfigurationView {
|
|||
.icon_size(IconSize::Medium)
|
||||
.style(ui::ButtonStyle::Filled)
|
||||
.full_width()
|
||||
.on_click(|_, cx| copilot::initiate_sign_in(cx)),
|
||||
.on_click(|_, window, cx| {
|
||||
copilot::initiate_sign_in(window, cx)
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div().flex().w_full().items_center().child(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue