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
|
@ -1,7 +1,7 @@
|
|||
use crate::Project;
|
||||
use anyhow::{Context as _, Result};
|
||||
use collections::HashMap;
|
||||
use gpui::{AnyWindowHandle, AppContext, Context, Entity, Model, ModelContext, Task, WeakModel};
|
||||
use gpui::{AnyWindowHandle, App, AppContext as _, Context, Entity, Task, WeakEntity};
|
||||
use itertools::Itertools;
|
||||
use language::LanguageName;
|
||||
use settings::{Settings, SettingsLocation};
|
||||
|
@ -24,7 +24,7 @@ use util::ResultExt;
|
|||
// use std::os::unix::ffi::OsStrExt;
|
||||
|
||||
pub struct Terminals {
|
||||
pub(crate) local_handles: Vec<WeakModel<terminal::Terminal>>,
|
||||
pub(crate) local_handles: Vec<WeakEntity<terminal::Terminal>>,
|
||||
}
|
||||
|
||||
/// Terminals are opened either for the users shell, or to run a task.
|
||||
|
@ -44,7 +44,7 @@ pub struct SshCommand {
|
|||
}
|
||||
|
||||
impl Project {
|
||||
pub fn active_project_directory(&self, cx: &AppContext) -> Option<Arc<Path>> {
|
||||
pub fn active_project_directory(&self, cx: &App) -> Option<Arc<Path>> {
|
||||
let worktree = self
|
||||
.active_entry()
|
||||
.and_then(|entry_id| self.worktree_for_entry(entry_id, cx))
|
||||
|
@ -54,7 +54,7 @@ impl Project {
|
|||
worktree
|
||||
}
|
||||
|
||||
pub fn first_project_directory(&self, cx: &AppContext) -> Option<PathBuf> {
|
||||
pub fn first_project_directory(&self, cx: &App) -> Option<PathBuf> {
|
||||
let worktree = self.worktrees(cx).next()?;
|
||||
let worktree = worktree.read(cx);
|
||||
if worktree.root_entry()?.is_dir() {
|
||||
|
@ -64,7 +64,7 @@ impl Project {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn ssh_details(&self, cx: &AppContext) -> Option<(String, SshCommand)> {
|
||||
pub fn ssh_details(&self, cx: &App) -> Option<(String, SshCommand)> {
|
||||
if let Some(ssh_client) = &self.ssh_client {
|
||||
let ssh_client = ssh_client.read(cx);
|
||||
if let Some(args) = ssh_client.ssh_args() {
|
||||
|
@ -82,8 +82,8 @@ impl Project {
|
|||
&mut self,
|
||||
kind: TerminalKind,
|
||||
window: AnyWindowHandle,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Task<Result<Model<Terminal>>> {
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<Entity<Terminal>>> {
|
||||
let path: Option<Arc<Path>> = match &kind {
|
||||
TerminalKind::Shell(path) => path.as_ref().map(|path| Arc::from(path.as_ref())),
|
||||
TerminalKind::Task(spawn_task) => {
|
||||
|
@ -125,7 +125,7 @@ impl Project {
|
|||
pub fn terminal_settings<'a>(
|
||||
&'a self,
|
||||
path: &'a Option<PathBuf>,
|
||||
cx: &'a AppContext,
|
||||
cx: &'a App,
|
||||
) -> &'a TerminalSettings {
|
||||
let mut settings_location = None;
|
||||
if let Some(path) = path.as_ref() {
|
||||
|
@ -139,7 +139,7 @@ impl Project {
|
|||
TerminalSettings::get(settings_location, cx)
|
||||
}
|
||||
|
||||
pub fn exec_in_shell(&self, command: String, cx: &AppContext) -> std::process::Command {
|
||||
pub fn exec_in_shell(&self, command: String, cx: &App) -> std::process::Command {
|
||||
let path = self.first_project_directory(cx);
|
||||
let ssh_details = self.ssh_details(cx);
|
||||
let settings = self.terminal_settings(&path, cx).clone();
|
||||
|
@ -184,8 +184,8 @@ impl Project {
|
|||
kind: TerminalKind,
|
||||
python_venv_directory: Option<PathBuf>,
|
||||
window: AnyWindowHandle,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) -> Result<Model<Terminal>> {
|
||||
cx: &mut Context<Self>,
|
||||
) -> Result<Entity<Terminal>> {
|
||||
let this = &mut *self;
|
||||
let path: Option<Arc<Path>> = match &kind {
|
||||
TerminalKind::Shell(path) => path.as_ref().map(|path| Arc::from(path.as_ref())),
|
||||
|
@ -339,7 +339,7 @@ impl Project {
|
|||
cx,
|
||||
)
|
||||
.map(|builder| {
|
||||
let terminal_handle = cx.new_model(|cx| builder.subscribe(cx));
|
||||
let terminal_handle = cx.new(|cx| builder.subscribe(cx));
|
||||
|
||||
this.terminals
|
||||
.local_handles
|
||||
|
@ -370,7 +370,7 @@ impl Project {
|
|||
&self,
|
||||
abs_path: Arc<Path>,
|
||||
venv_settings: VenvSettings,
|
||||
cx: &ModelContext<Project>,
|
||||
cx: &Context<Project>,
|
||||
) -> Task<Option<PathBuf>> {
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
if let Some((worktree, _)) = this
|
||||
|
@ -409,7 +409,7 @@ impl Project {
|
|||
&self,
|
||||
abs_path: &Path,
|
||||
venv_settings: &terminal_settings::VenvSettingsContent,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Option<PathBuf> {
|
||||
let bin_dir_name = match std::env::consts::OS {
|
||||
"windows" => "Scripts",
|
||||
|
@ -433,7 +433,7 @@ impl Project {
|
|||
&self,
|
||||
abs_path: &Path,
|
||||
venv_settings: &terminal_settings::VenvSettingsContent,
|
||||
cx: &AppContext,
|
||||
cx: &App,
|
||||
) -> Option<PathBuf> {
|
||||
let (worktree, _) = self.find_worktree(abs_path, cx)?;
|
||||
let fs = worktree.read(cx).as_local()?.fs();
|
||||
|
@ -503,13 +503,13 @@ impl Project {
|
|||
fn activate_python_virtual_environment(
|
||||
&self,
|
||||
command: String,
|
||||
terminal_handle: &Model<Terminal>,
|
||||
cx: &mut AppContext,
|
||||
terminal_handle: &Entity<Terminal>,
|
||||
cx: &mut App,
|
||||
) {
|
||||
terminal_handle.update(cx, |terminal, _| terminal.input_bytes(command.into_bytes()));
|
||||
}
|
||||
|
||||
pub fn local_terminal_handles(&self) -> &Vec<WeakModel<terminal::Terminal>> {
|
||||
pub fn local_terminal_handles(&self) -> &Vec<WeakEntity<terminal::Terminal>> {
|
||||
&self.terminals.local_handles
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue