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:
Nathan Sobo 2025-01-25 20:02:45 -07:00 committed by GitHub
parent 21b4a0d50e
commit 6fca1d2b0b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
648 changed files with 36248 additions and 28208 deletions

View file

@ -16,10 +16,10 @@ use std::{
use crate::{
display_map::Inlay, Anchor, Editor, ExcerptId, InlayId, MultiBuffer, MultiBufferSnapshot,
};
use anyhow::Context;
use anyhow::Context as _;
use clock::Global;
use futures::future;
use gpui::{AsyncWindowContext, Model, ModelContext, Task, ViewContext};
use gpui::{AsyncAppContext, Context, Entity, Task, Window};
use language::{language_settings::InlayHintKind, Buffer, BufferSnapshot};
use parking_lot::RwLock;
use project::{InlayHint, ResolveState};
@ -281,10 +281,10 @@ impl InlayHintCache {
/// Does not update inlay hint cache state on disabling or inlay hint kinds change: only reenabling forces new LSP queries.
pub(super) fn update_settings(
&mut self,
multi_buffer: &Model<MultiBuffer>,
multi_buffer: &Entity<MultiBuffer>,
new_hint_settings: InlayHintSettings,
visible_hints: Vec<Inlay>,
cx: &mut ViewContext<Editor>,
cx: &mut Context<Editor>,
) -> ControlFlow<Option<InlaySplice>> {
let old_enabled = self.enabled;
// If the setting for inlay hints has changed, update `enabled`. This condition avoids inlay
@ -348,10 +348,10 @@ impl InlayHintCache {
pub(super) fn spawn_hint_refresh(
&mut self,
reason_description: &'static str,
excerpts_to_query: HashMap<ExcerptId, (Model<Buffer>, Global, Range<usize>)>,
excerpts_to_query: HashMap<ExcerptId, (Entity<Buffer>, Global, Range<usize>)>,
invalidate: InvalidationStrategy,
ignore_debounce: bool,
cx: &mut ViewContext<Editor>,
cx: &mut Context<Editor>,
) -> Option<InlaySplice> {
if !self.enabled {
return None;
@ -411,10 +411,10 @@ impl InlayHintCache {
fn new_allowed_hint_kinds_splice(
&self,
multi_buffer: &Model<MultiBuffer>,
multi_buffer: &Entity<MultiBuffer>,
visible_hints: &[Inlay],
new_kinds: &HashSet<Option<InlayHintKind>>,
cx: &mut ViewContext<Editor>,
cx: &mut Context<Editor>,
) -> Option<InlaySplice> {
let old_kinds = &self.allowed_hint_kinds;
if new_kinds == old_kinds {
@ -582,7 +582,8 @@ impl InlayHintCache {
buffer_id: BufferId,
excerpt_id: ExcerptId,
id: InlayId,
cx: &mut ViewContext<Editor>,
window: &mut Window,
cx: &mut Context<Editor>,
) {
if let Some(excerpt_hints) = self.hints.get(&excerpt_id) {
let mut guard = excerpt_hints.write();
@ -592,7 +593,7 @@ impl InlayHintCache {
let server_id = *server_id;
cached_hint.resolve_state = ResolveState::Resolving;
drop(guard);
cx.spawn(|editor, mut cx| async move {
cx.spawn_in(window, |editor, mut cx| async move {
let resolved_hint_task = editor.update(&mut cx, |editor, cx| {
let buffer = editor.buffer().read(cx).buffer(buffer_id)?;
editor.semantics_provider.as_ref()?.resolve_inlay_hint(
@ -640,10 +641,10 @@ fn debounce_value(debounce_ms: u64) -> Option<Duration> {
fn spawn_new_update_tasks(
editor: &mut Editor,
reason: &'static str,
excerpts_to_query: HashMap<ExcerptId, (Model<Buffer>, Global, Range<usize>)>,
excerpts_to_query: HashMap<ExcerptId, (Entity<Buffer>, Global, Range<usize>)>,
invalidate: InvalidationStrategy,
update_cache_version: usize,
cx: &mut ViewContext<Editor>,
cx: &mut Context<Editor>,
) {
for (excerpt_id, (excerpt_buffer, new_task_buffer_version, excerpt_visible_range)) in
excerpts_to_query
@ -738,9 +739,9 @@ impl QueryRanges {
fn determine_query_ranges(
multi_buffer: &mut MultiBuffer,
excerpt_id: ExcerptId,
excerpt_buffer: &Model<Buffer>,
excerpt_buffer: &Entity<Buffer>,
excerpt_visible_range: Range<usize>,
cx: &mut ModelContext<'_, MultiBuffer>,
cx: &mut Context<'_, MultiBuffer>,
) -> Option<QueryRanges> {
let full_excerpt_range = multi_buffer
.excerpts_for_buffer(excerpt_buffer, cx)
@ -809,8 +810,8 @@ const INVISIBLE_RANGES_HINTS_REQUEST_DELAY_MILLIS: u64 = 400;
fn new_update_task(
query: ExcerptQuery,
query_ranges: QueryRanges,
excerpt_buffer: Model<Buffer>,
cx: &mut ViewContext<Editor>,
excerpt_buffer: Entity<Buffer>,
cx: &mut Context<Editor>,
) -> Task<()> {
cx.spawn(move |editor, mut cx| async move {
let visible_range_update_results = future::join_all(
@ -839,7 +840,7 @@ fn new_update_task(
));
let query_range_failed =
|range: &Range<language::Anchor>, e: anyhow::Error, cx: &mut AsyncWindowContext| {
|range: &Range<language::Anchor>, e: anyhow::Error, cx: &mut AsyncAppContext| {
log::error!("inlay hint update task for range failed: {e:#?}");
editor
.update(cx, |editor, cx| {
@ -892,11 +893,11 @@ fn new_update_task(
}
fn fetch_and_update_hints(
excerpt_buffer: Model<Buffer>,
excerpt_buffer: Entity<Buffer>,
query: ExcerptQuery,
fetch_range: Range<language::Anchor>,
invalidate: bool,
cx: &mut ViewContext<Editor>,
cx: &mut Context<Editor>,
) -> Task<anyhow::Result<()>> {
cx.spawn(|editor, mut cx| async move {
let buffer_snapshot = excerpt_buffer.update(&mut cx, |buffer, _| buffer.snapshot())?;
@ -1018,7 +1019,7 @@ fn fetch_and_update_hints(
);
log::trace!("New update: {new_update:?}");
editor
.update(&mut cx, |editor, cx| {
.update(&mut cx, |editor, cx| {
apply_hint_update(
editor,
new_update,
@ -1142,7 +1143,7 @@ fn apply_hint_update(
invalidate: bool,
buffer_snapshot: BufferSnapshot,
multi_buffer_snapshot: MultiBufferSnapshot,
cx: &mut ViewContext<Editor>,
cx: &mut Context<Editor>,
) {
let cached_excerpt_hints = editor
.inlay_hint_cache
@ -1262,7 +1263,7 @@ pub mod tests {
use crate::scroll::ScrollAmount;
use crate::{scroll::Autoscroll, test::editor_lsp_test_context::rust_lang, ExcerptRange};
use futures::StreamExt;
use gpui::{Context, SemanticVersion, TestAppContext, WindowHandle};
use gpui::{AppContext as _, Context, SemanticVersion, TestAppContext, WindowHandle};
use itertools::Itertools as _;
use language::{language_settings::AllLanguageSettingsContent, Capability, FakeLspAdapter};
use language::{Language, LanguageConfig, LanguageMatcher};
@ -1317,7 +1318,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["1".to_string()];
assert_eq!(
expected_hints,
@ -1334,14 +1335,14 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
editor.handle_input("some change", cx);
.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13]));
editor.handle_input("some change", window, cx);
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["2".to_string()];
assert_eq!(
expected_hints,
@ -1363,7 +1364,7 @@ pub mod tests {
.expect("inlay refresh request failed");
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["3".to_string()];
assert_eq!(
expected_hints,
@ -1422,7 +1423,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let expected_hints = vec!["0".to_string()];
assert_eq!(
expected_hints,
@ -1450,7 +1451,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let expected_hints = vec!["0".to_string()];
assert_eq!(
expected_hints,
@ -1470,7 +1471,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let expected_hints = vec!["1".to_string()];
assert_eq!(
expected_hints,
@ -1588,14 +1589,15 @@ pub mod tests {
})
.await
.unwrap();
let rs_editor =
cx.add_window(|cx| Editor::for_buffer(rs_buffer, Some(project.clone()), cx));
let rs_editor = cx.add_window(|window, cx| {
Editor::for_buffer(rs_buffer, Some(project.clone()), window, cx)
});
cx.executor().run_until_parked();
let _rs_fake_server = rs_fake_servers.unwrap().next().await.unwrap();
cx.executor().run_until_parked();
rs_editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["1".to_string()];
assert_eq!(
expected_hints,
@ -1613,13 +1615,14 @@ pub mod tests {
})
.await
.unwrap();
let md_editor = cx.add_window(|cx| Editor::for_buffer(md_buffer, Some(project), cx));
let md_editor =
cx.add_window(|window, cx| Editor::for_buffer(md_buffer, Some(project), window, cx));
cx.executor().run_until_parked();
let _md_fake_server = md_fake_servers.unwrap().next().await.unwrap();
cx.executor().run_until_parked();
md_editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["1".to_string()];
assert_eq!(
expected_hints,
@ -1631,14 +1634,14 @@ pub mod tests {
.unwrap();
rs_editor
.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
editor.handle_input("some rs change", cx);
.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13]));
editor.handle_input("some rs change", window, cx);
})
.unwrap();
cx.executor().run_until_parked();
rs_editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
// TODO: Here, we do not get "2", because inserting another language server will trigger `RefreshInlayHints` event from the `LspStore`
// A project is listened in every editor, so each of them will react to this event.
//
@ -1654,7 +1657,7 @@ pub mod tests {
})
.unwrap();
md_editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["1".to_string()];
assert_eq!(
expected_hints,
@ -1666,14 +1669,14 @@ pub mod tests {
.unwrap();
md_editor
.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
editor.handle_input("some md change", cx);
.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13]));
editor.handle_input("some md change", window, cx);
})
.unwrap();
cx.executor().run_until_parked();
md_editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["2".to_string()];
assert_eq!(
expected_hints,
@ -1684,7 +1687,7 @@ pub mod tests {
})
.unwrap();
rs_editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec!["3".to_string()];
assert_eq!(
expected_hints,
@ -1767,7 +1770,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert_eq!(
lsp_request_count.load(Ordering::Relaxed),
1,
@ -1800,7 +1803,7 @@ pub mod tests {
.expect("inlay refresh request failed");
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert_eq!(
lsp_request_count.load(Ordering::Relaxed),
2,
@ -1870,7 +1873,7 @@ pub mod tests {
})
});
cx.executor().run_until_parked();
editor.update(cx, |editor, cx| {
editor.update(cx, |editor, _, cx| {
assert_eq!(
lsp_request_count.load(Ordering::Relaxed),
2,
@ -1913,7 +1916,7 @@ pub mod tests {
});
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert_eq!(
lsp_request_count.load(Ordering::Relaxed),
2,
@ -1941,7 +1944,7 @@ pub mod tests {
.expect("inlay refresh request failed");
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
assert_eq!(
lsp_request_count.load(Ordering::Relaxed),
2,
@ -1967,7 +1970,7 @@ pub mod tests {
});
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert_eq!(
lsp_request_count.load(Ordering::Relaxed),
3,
@ -2001,7 +2004,7 @@ pub mod tests {
.expect("inlay refresh request failed");
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert_eq!(
lsp_request_count.load(Ordering::Relaxed),
4,
@ -2075,9 +2078,9 @@ pub mod tests {
"initial change #3",
] {
editor
.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
editor.handle_input(change_after_opening, cx);
.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13]));
editor.handle_input(change_after_opening, window, cx);
})
.unwrap();
expected_changes.push(change_after_opening);
@ -2086,7 +2089,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let current_text = editor.text(cx);
for change in &expected_changes {
assert!(
@ -2119,9 +2122,9 @@ pub mod tests {
let task_editor = editor;
edits.push(cx.spawn(|mut cx| async move {
task_editor
.update(&mut cx, |editor, cx| {
editor.change_selections(None, cx, |s| s.select_ranges([13..13]));
editor.handle_input(async_later_change, cx);
.update(&mut cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| s.select_ranges([13..13]));
editor.handle_input(async_later_change, window, cx);
})
.unwrap();
}));
@ -2130,7 +2133,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let current_text = editor.text(cx);
for change in &expected_changes {
assert!(
@ -2238,7 +2241,8 @@ pub mod tests {
})
.await
.unwrap();
let editor = cx.add_window(|cx| Editor::for_buffer(buffer, Some(project), cx));
let editor =
cx.add_window(|window, cx| Editor::for_buffer(buffer, Some(project), window, cx));
cx.executor().run_until_parked();
@ -2266,7 +2270,7 @@ pub mod tests {
lsp::Position::new(initial_visible_range.end.row * 2, 2);
let mut expected_invisible_query_start = lsp_initial_visible_range.end;
expected_invisible_query_start.character += 1;
editor.update(cx, |editor, cx| {
editor.update(cx, |editor, _window, cx| {
let ranges = lsp_request_ranges.lock().drain(..).collect::<Vec<_>>();
assert_eq!(ranges.len(), 2,
"When scroll is at the edge of a big document, its visible part and the same range further should be queried in order, but got: {ranges:?}");
@ -2290,14 +2294,14 @@ pub mod tests {
}).unwrap();
editor
.update(cx, |editor, cx| {
editor.scroll_screen(&ScrollAmount::Page(1.0), cx);
.update(cx, |editor, window, cx| {
editor.scroll_screen(&ScrollAmount::Page(1.0), window, cx);
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
editor.scroll_screen(&ScrollAmount::Page(1.0), cx);
.update(cx, |editor, window, cx| {
editor.scroll_screen(&ScrollAmount::Page(1.0), window, cx);
})
.unwrap();
cx.executor().advance_clock(Duration::from_millis(
@ -2306,10 +2310,12 @@ pub mod tests {
cx.executor().run_until_parked();
let visible_range_after_scrolls = editor_visible_range(&editor, cx);
let visible_line_count = editor
.update(cx, |editor, _| editor.visible_line_count().unwrap())
.update(cx, |editor, _window, _| {
editor.visible_line_count().unwrap()
})
.unwrap();
let selection_in_cached_range = editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let ranges = lsp_request_ranges
.lock()
.drain(..)
@ -2362,8 +2368,8 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::center()), cx, |s| {
.update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::center()), window, cx, |s| {
s.select_ranges([selection_in_cached_range..selection_in_cached_range])
});
})
@ -2372,7 +2378,7 @@ pub mod tests {
INVISIBLE_RANGES_HINTS_REQUEST_DELAY_MILLIS + 100,
));
cx.executor().run_until_parked();
editor.update(cx, |_, _| {
editor.update(cx, |_, _, _| {
let ranges = lsp_request_ranges
.lock()
.drain(..)
@ -2383,15 +2389,15 @@ pub mod tests {
}).unwrap();
editor
.update(cx, |editor, cx| {
editor.handle_input("++++more text++++", cx);
.update(cx, |editor, window, cx| {
editor.handle_input("++++more text++++", window, cx);
})
.unwrap();
cx.executor().advance_clock(Duration::from_millis(
INVISIBLE_RANGES_HINTS_REQUEST_DELAY_MILLIS + 100,
));
cx.executor().run_until_parked();
editor.update(cx, |editor, cx| {
editor.update(cx, |editor, _window, cx| {
let mut ranges = lsp_request_ranges.lock().drain(..).collect::<Vec<_>>();
ranges.sort_by_key(|r| r.start);
@ -2427,7 +2433,7 @@ pub mod tests {
cx: &mut gpui::TestAppContext,
) -> Range<Point> {
let ranges = editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
editor.excerpts_for_inlay_hints_query(None, cx)
})
.unwrap();
@ -2501,7 +2507,7 @@ pub mod tests {
})
.await
.unwrap();
let multibuffer = cx.new_model(|cx| {
let multibuffer = cx.new(|cx| {
let mut multibuffer = MultiBuffer::new(Capability::ReadWrite);
multibuffer.push_excerpts(
buffer_1.clone(),
@ -2567,8 +2573,9 @@ pub mod tests {
});
cx.executor().run_until_parked();
let editor = cx
.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), true, cx));
let editor = cx.add_window(|window, cx| {
Editor::for_multibuffer(multibuffer, Some(project.clone()), true, window, cx)
});
let editor_edited = Arc::new(AtomicBool::new(false));
let fake_server = fake_servers.next().await.unwrap();
@ -2641,7 +2648,7 @@ pub mod tests {
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"main hint #0".to_string(),
"main hint #1".to_string(),
@ -2660,21 +2667,21 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::Next), cx, |s| {
.update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| {
s.select_ranges([Point::new(4, 0)..Point::new(4, 0)])
});
editor.change_selections(Some(Autoscroll::Next), cx, |s| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| {
s.select_ranges([Point::new(22, 0)..Point::new(22, 0)])
});
editor.change_selections(Some(Autoscroll::Next), cx, |s| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| {
s.select_ranges([Point::new(50, 0)..Point::new(50, 0)])
});
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"main hint #0".to_string(),
"main hint #1".to_string(),
@ -2693,8 +2700,8 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::Next), cx, |s| {
.update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| {
s.select_ranges([Point::new(100, 0)..Point::new(100, 0)])
});
})
@ -2704,7 +2711,7 @@ pub mod tests {
));
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"main hint #0".to_string(),
"main hint #1".to_string(),
@ -2726,8 +2733,8 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.change_selections(Some(Autoscroll::Next), cx, |s| {
.update(cx, |editor, window, cx| {
editor.change_selections(Some(Autoscroll::Next), window, cx, |s| {
s.select_ranges([Point::new(4, 0)..Point::new(4, 0)])
});
})
@ -2737,7 +2744,7 @@ pub mod tests {
));
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"main hint #0".to_string(),
"main hint #1".to_string(),
@ -2760,16 +2767,16 @@ pub mod tests {
editor_edited.store(true, Ordering::Release);
editor
.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| {
.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| {
s.select_ranges([Point::new(57, 0)..Point::new(57, 0)])
});
editor.handle_input("++++more text++++", cx);
editor.handle_input("++++more text++++", window, cx);
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"main hint #0".to_string(),
"main hint #1".to_string(),
@ -2843,7 +2850,7 @@ pub mod tests {
})
.await
.unwrap();
let multibuffer = cx.new_model(|_| MultiBuffer::new(Capability::ReadWrite));
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
let (buffer_1_excerpts, buffer_2_excerpts) = multibuffer.update(cx, |multibuffer, cx| {
let buffer_1_excerpts = multibuffer.push_excerpts(
buffer_1.clone(),
@ -2868,8 +2875,9 @@ pub mod tests {
assert!(!buffer_2_excerpts.is_empty());
cx.executor().run_until_parked();
let editor = cx
.add_window(|cx| Editor::for_multibuffer(multibuffer, Some(project.clone()), true, cx));
let editor = cx.add_window(|window, cx| {
Editor::for_multibuffer(multibuffer, Some(project.clone()), true, window, cx)
});
let editor_edited = Arc::new(AtomicBool::new(false));
let fake_server = fake_servers.next().await.unwrap();
let closure_editor_edited = Arc::clone(&editor_edited);
@ -2939,7 +2947,7 @@ pub mod tests {
.await;
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert_eq!(
vec!["main hint #0".to_string(), "other hint #0".to_string()],
sorted_cached_hint_labels(editor),
@ -2953,7 +2961,7 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
editor.buffer().update(cx, |multibuffer, cx| {
multibuffer.remove_excerpts(buffer_2_excerpts, cx)
})
@ -2961,7 +2969,7 @@ pub mod tests {
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert_eq!(
vec!["main hint #0".to_string()],
cached_hint_labels(editor),
@ -2987,7 +2995,7 @@ pub mod tests {
});
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let expected_hints = vec!["main hint #0".to_string()];
assert_eq!(
expected_hints,
@ -3073,19 +3081,20 @@ pub mod tests {
})
.await
.unwrap();
let editor = cx.add_window(|cx| Editor::for_buffer(buffer, Some(project), cx));
let editor =
cx.add_window(|window, cx| Editor::for_buffer(buffer, Some(project), window, cx));
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| {
.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| {
s.select_ranges([Point::new(10, 0)..Point::new(10, 0)])
})
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let expected_hints = vec!["1".to_string()];
assert_eq!(expected_hints, cached_hint_labels(editor));
assert_eq!(expected_hints, visible_hint_labels(editor, cx));
@ -3134,14 +3143,14 @@ pub mod tests {
.await;
editor
.update(cx, |editor, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
.update(cx, |editor, window, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, window, cx)
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let expected_hints = vec!["1".to_string()];
assert_eq!(
expected_hints,
@ -3153,13 +3162,13 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
.update(cx, |editor, window, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, window, cx)
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert!(
cached_hint_labels(editor).is_empty(),
"Should clear hints after 2nd toggle"
@ -3181,7 +3190,7 @@ pub mod tests {
});
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
let expected_hints = vec!["2".to_string()];
assert_eq!(
expected_hints,
@ -3193,13 +3202,13 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
.update(cx, |editor, window, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, window, cx)
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert!(
cached_hint_labels(editor).is_empty(),
"Should clear hints after enabling in settings and a 3rd toggle"
@ -3209,12 +3218,12 @@ pub mod tests {
.unwrap();
editor
.update(cx, |editor, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, cx)
.update(cx, |editor, window, cx| {
editor.toggle_inlay_hints(&crate::ToggleInlayHints, window, cx)
})
.unwrap();
cx.executor().run_until_parked();
editor.update(cx, |editor, cx| {
editor.update(cx, |editor, _, cx| {
let expected_hints = vec!["3".to_string()];
assert_eq!(
expected_hints,
@ -3346,19 +3355,20 @@ pub mod tests {
})
.await
.unwrap();
let editor = cx.add_window(|cx| Editor::for_buffer(buffer, Some(project), cx));
let editor =
cx.add_window(|window, cx| Editor::for_buffer(buffer, Some(project), window, cx));
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
editor.change_selections(None, cx, |s| {
.update(cx, |editor, window, cx| {
editor.change_selections(None, window, cx, |s| {
s.select_ranges([Point::new(10, 0)..Point::new(10, 0)])
})
})
.unwrap();
cx.executor().run_until_parked();
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _window, cx| {
let expected_hints = vec![
"move".to_string(),
"(".to_string(),
@ -3429,10 +3439,11 @@ pub mod tests {
})
.await
.unwrap();
let editor = cx.add_window(|cx| Editor::for_buffer(buffer, Some(project), cx));
let editor =
cx.add_window(|window, cx| Editor::for_buffer(buffer, Some(project), window, cx));
editor
.update(cx, |editor, cx| {
.update(cx, |editor, _, cx| {
assert!(cached_hint_labels(editor).is_empty());
assert!(visible_hint_labels(editor, cx).is_empty());
})
@ -3471,7 +3482,7 @@ pub mod tests {
labels
}
pub fn visible_hint_labels(editor: &Editor, cx: &ViewContext<Editor>) -> Vec<String> {
pub fn visible_hint_labels(editor: &Editor, cx: &Context<Editor>) -> Vec<String> {
editor
.visible_inlay_hints(cx)
.into_iter()