ZIm/refactor.sh
Nathan Sobo 6fca1d2b0b
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>
2025-01-26 03:02:45 +00:00

111 lines
5.2 KiB
Bash
Executable file

#!/bin/bash
# Merge process:
#
# * Use mergiraf for merge, with `git merge main -X theirs`
#
# - Need to use it with a patched tree-sitter-rust. I (Michael)
# haven't yet uploaded a fork for this, can do if helpful.
# https://github.com/tree-sitter/tree-sitter-rust/pull/245
#
# - Watch for newlines between top level decls sometimes disappearing
#
# * Run this script.
dry=true
if [ "$1" = "apply" ]; then
dry=false
fi
re() {
echo "$1" " --> " "$2"
if [ "$dry" = true ]; then
ruplacer "$1" "$2" crates/ --type *.rs
else
ruplacer "$1" "$2" crates/ --type *.rs --go
fi
}
re '\.new_view\(' '.new_model('
re 'cx.view\(' 'cx.model('
re '\.observe_new_views\(' '.observe_new_models('
re 'View<' 'Model<'
re 'FocusableView' 'Focusable'
# closure parameters
re ', &mut WindowContext\)' ', &mut Window, &mut AppContext)'
re ', &mut ViewContext<([^>]+)>\)' ', &mut Window, &mut ModelContext<$1>)'
re '\(&mut WindowContext\)' '(&mut Window, &mut AppContext)'
re '\(&mut ViewContext<([^>]+)>\)' '(&mut Window, &mut ModelContext<$1>)'
# function parameters
re '_: &mut WindowContext\)' '_window: &mut Window, _cx: &mut AppContext)'
re '_: &mut ViewContext<([^>]+)>\)' '_window: &mut Window, _cx: &mut ModelContext<$1>)'
re '_: &mut WindowContext,' '_window: &mut Window, _cx: &mut AppContext,'
re '_: &mut ViewContext<([^>]+)>,' '_window: &mut Window, _cx: &mut ModelContext<$1>,'
re '_cx: &mut WindowContext\)' '_window: &mut Window, _cx: &mut AppContext)'
re '_cx: &mut ViewContext<([^>]+)>\)' '_window: &mut Window, _cx: &mut ModelContext<$1>)'
re '_cx: &mut WindowContext,' '_window: &mut Window, _cx: &mut AppContext,'
re '_cx: &mut ViewContext<([^>]+)>,' '_window: &mut Window, _cx: &mut ModelContext<$1>,'
re 'cx: &mut WindowContext\)' 'window: &mut Window, cx: &mut AppContext)'
re 'cx: &mut ViewContext<([^>]+)>\)' 'window: &mut Window, cx: &mut ModelContext<$1>)'
re 'cx: &mut WindowContext,' 'window: &mut Window, cx: &mut AppContext,'
re 'cx: &mut ViewContext<([^>]+)>,' 'window: &mut Window, cx: &mut ModelContext<$1>,'
re '_: &WindowContext\)' '_window: &Window, _cx: &AppContext)'
re '_: &ViewContext<([^>]+)>\)' '_window: &Window, _cx: &ModelContext<$1>)'
re '_: &WindowContext,' '_window: &Window, _cx: &AppContext,'
re '_: &ViewContext<([^>]+)>,' '_window: &Window, _cx: &ModelContext<$1>,'
re '_cx: &WindowContext\)' '_window: &Window, _cx: &AppContext)'
re '_cx: &ViewContext<([^>]+)>\)' '_window: &Window, _cx: &ModelContext<$1>)'
re '_cx: &WindowContext,' '_window: &Window, _cx: &AppContext,'
re '_cx: &ViewContext<([^>]+)>,' '_window: &Window, _cx: &ModelContext<$1>,'
re 'cx: &WindowContext\)' 'window: &Window, cx: &AppContext)'
re 'cx: &ViewContext<([^>]+)>\)' 'window: &Window, cx: &ModelContext<$1>)'
re 'cx: &WindowContext,' 'window: &Window, cx: &AppContext,'
re 'cx: &ViewContext<([^>]+)>,' 'window: &Window, cx: &ModelContext<$1>,'
# VisualContext methods moved to window, that take context
re 'cx.dismiss_view\(' 'window.dismiss_view(cx, '
re 'cx.focus_view\(' 'window.focus_view(cx, '
re 'cx.new_view\(' 'window.new_view(cx, '
re 'cx.replace_root_view\(' 'window.replace_root_view(cx, '
# AppContext methods moved to window, that take context
re 'cx.appearance_changed\(\)' 'window.appearance_changed(cx)'
re 'cx.available_actions\(\)' 'window.available_actions(cx)'
re 'cx.dispatch_keystroke_observers\(' 'window.dispatch_keystroke_observers(cx, '
re 'cx.display\(\)' 'window.display(cx)'
re 'cx.focused\(\)' 'window.focused(cx)'
re 'cx.handle_input\(' 'window.handle_input(cx, '
re 'cx.paint_svg\(' 'window.paint_svg(cx, '
re 'cx.request_layout\(' 'window.request_layout(cx, '
re 'cx.use_asset\(' 'window.use_asset(cx, '
# Subset of AppContext methods moved to window that don't take context
re 'cx\.set_cursor_style\(' 'window.set_cursor_style('
re 'cx\.modifiers\(' 'window.modifiers('
re 'cx\.mouse_position\(' 'window.mouse_position('
re 'cx\.text_style\(' 'window.text_style('
re 'cx\.line_height\(' 'window.line_height('
# common closure patterns
re 'cx.listener\(move \|this, _, cx\|' 'cx.listener(move |this, _, window, cx|'
re 'cx.listener\(\|this, _, cx\|' 'cx.listener(|this, _, window, cx|'
re 'cx.listener\(move \|_, _, cx\|' 'cx.listener(move |_, _, window, cx|'
re 'cx.listener\(\|_, _, cx\|' 'cx.listener(|_, _, window, cx|'
re '\.on_click\(move \|_, cx\|' '.on_click(move |_, window, cx|'
re '\.on_mouse_move\(\|_, cx\|' '.on_mouse_move(|_, window, cx|'
# cleanup imports
re ' ViewContext,' ''
re ' WindowContext,' ''
re ' WeakView,' ''
re ' View,' ''
re ', ViewContext\}' '}'
re ', WindowContext\}' '}'
re ', WeakView\}' '}'
re ', View\}' '}'
# other patterns
re '\.detach_and_notify_err\(cx' '.detach_and_notify_err(window, cx'