From 096bad1f73933a3c7783c3d2e3d156f299ac71ec Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 26 Jun 2023 13:52:09 +0300 Subject: [PATCH] Revert useless changes, simplify --- crates/collab/src/tests/integration_tests.rs | 4 +- crates/editor/Cargo.toml | 3 +- crates/editor/src/editor.rs | 59 +++++++++----------- crates/editor/src/inlay_hint_cache.rs | 13 +---- crates/editor/src/multi_buffer.rs | 1 - 5 files changed, 30 insertions(+), 50 deletions(-) diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index 5ff7f09ff8..8095b39a7f 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -6406,7 +6406,6 @@ async fn test_basic_following( let client_b = server.create_client(cx_b, "user_b").await; let client_c = server.create_client(cx_c, "user_c").await; let client_d = server.create_client(cx_d, "user_d").await; - server .create_room(&mut [ (&client_a, cx_a), @@ -7944,8 +7943,7 @@ async fn test_mutual_editor_inlay_hint_cache_update( cx_a.foreground().finish_waiting(); cx_a.foreground().run_until_parked(); - let mut edits_made = 0; - edits_made += 1; + let mut edits_made = 1; editor_a.update(cx_a, |editor, _| { assert_eq!( vec!["0".to_string()], diff --git a/crates/editor/Cargo.toml b/crates/editor/Cargo.toml index 61145e40ff..dcc2220227 100644 --- a/crates/editor/Cargo.toml +++ b/crates/editor/Cargo.toml @@ -10,6 +10,7 @@ doctest = false [features] test-support = [ + "rand", "copilot/test-support", "text/test-support", "language/test-support", @@ -56,7 +57,7 @@ ordered-float.workspace = true parking_lot.workspace = true postage.workspace = true pulldown-cmark = { version = "0.9.2", default-features = false } -rand = { workspace = true } +rand = { workspace = true, optional = true } schemars.workspace = true serde.workspace = true serde_derive.workspace = true diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 5d5bdd1db4..65beec6d97 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -1,5 +1,4 @@ mod blink_manager; - pub mod display_map; mod editor_settings; mod element; @@ -54,7 +53,7 @@ use gpui::{ }; use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; -use inlay_hint_cache::{visible_inlay_hints, InlayHintCache, InlaySplice, InvalidationStrategy}; +use inlay_hint_cache::{InlayHintCache, InlaySplice, InvalidationStrategy}; pub use items::MAX_TAB_TITLE_LEN; use itertools::Itertools; pub use language::{char_kind, CharKind}; @@ -2617,7 +2616,7 @@ impl Editor { let new_splice = self.inlay_hint_cache.update_settings( &self.buffer, new_settings, - visible_inlay_hints(self, cx).cloned().collect(), + self.visible_inlay_hints(cx), cx, ); if let Some(InlaySplice { @@ -2648,6 +2647,17 @@ impl Editor { } } + fn visible_inlay_hints(&self, cx: &ViewContext<'_, '_, Editor>) -> Vec { + self.display_map + .read(cx) + .current_inlays() + .filter(move |inlay| { + Some(inlay.id) != self.copilot_state.suggestion.as_ref().map(|h| h.id) + }) + .cloned() + .collect() + } + fn excerpt_visible_offsets( &self, cx: &mut ViewContext<'_, '_, Editor>, @@ -5659,7 +5669,6 @@ impl Editor { } } - // TODO: Handle selections that cross excerpts // TODO: Handle selections that cross excerpts for selection in &mut selections { let start_column = snapshot.indent_size_for_line(selection.start.row).len; @@ -7257,37 +7266,21 @@ impl Editor { buffer, predecessor, excerpts, - } => { - cx.emit(Event::ExcerptsAdded { - buffer: buffer.clone(), - predecessor: *predecessor, - excerpts: excerpts.clone(), - }); - } + } => cx.emit(Event::ExcerptsAdded { + buffer: buffer.clone(), + predecessor: *predecessor, + excerpts: excerpts.clone(), + }), multi_buffer::Event::ExcerptsRemoved { ids } => { - cx.emit(Event::ExcerptsRemoved { ids: ids.clone() }); - } - multi_buffer::Event::Reparsed => { - cx.emit(Event::Reparsed); - } - multi_buffer::Event::DirtyChanged => { - cx.emit(Event::DirtyChanged); - } - multi_buffer::Event::Saved => { - cx.emit(Event::Saved); - } - multi_buffer::Event::FileHandleChanged => { - cx.emit(Event::TitleChanged); - } - multi_buffer::Event::Reloaded => { - cx.emit(Event::TitleChanged); - } - multi_buffer::Event::DiffBaseChanged => { - cx.emit(Event::DiffBaseChanged); - } - multi_buffer::Event::Closed => { - cx.emit(Event::Closed); + cx.emit(Event::ExcerptsRemoved { ids: ids.clone() }) } + multi_buffer::Event::Reparsed => cx.emit(Event::Reparsed), + multi_buffer::Event::DirtyChanged => cx.emit(Event::DirtyChanged), + multi_buffer::Event::Saved => cx.emit(Event::Saved), + multi_buffer::Event::FileHandleChanged => cx.emit(Event::TitleChanged), + multi_buffer::Event::Reloaded => cx.emit(Event::TitleChanged), + multi_buffer::Event::DiffBaseChanged => cx.emit(Event::DiffBaseChanged), + multi_buffer::Event::Closed => cx.emit(Event::Closed), multi_buffer::Event::DiagnosticsUpdated => { self.refresh_active_diagnostics(cx); } diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index d0274b516d..bee08f6cc7 100644 --- a/crates/editor/src/inlay_hint_cache.rs +++ b/crates/editor/src/inlay_hint_cache.rs @@ -306,7 +306,7 @@ fn spawn_new_update_tasks( update_cache_version: usize, cx: &mut ViewContext<'_, '_, Editor>, ) { - let visible_hints = Arc::new(visible_inlay_hints(editor, cx).cloned().collect::>()); + let visible_hints = Arc::new(editor.visible_inlay_hints(cx)); for (excerpt_id, (buffer_handle, excerpt_visible_range)) in excerpts_to_query { if !excerpt_visible_range.is_empty() { let buffer = buffer_handle.read(cx); @@ -786,17 +786,6 @@ fn hints_fetch_tasks( } } -pub fn visible_inlay_hints<'a, 'b: 'a, 'c, 'd: 'a>( - editor: &'a Editor, - cx: &'b ViewContext<'c, 'd, Editor>, -) -> impl Iterator + 'a { - editor - .display_map - .read(cx) - .current_inlays() - .filter(|inlay| Some(inlay.id) != editor.copilot_state.suggestion.as_ref().map(|h| h.id)) -} - fn contains_position( range: &Range, position: language::Anchor, diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index d4298efacf..c5070363eb 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -2631,7 +2631,6 @@ impl MultiBufferSnapshot { }; } } - panic!("excerpt not found") }