From e217a95fcc12f30b9862b7fafbca59f7c2cede96 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 16 Jun 2023 17:07:04 +0300 Subject: [PATCH] Cleanup the warnings --- crates/editor/src/display_map/fold_map.rs | 1 + crates/editor/src/display_map/inlay_map.rs | 13 ++------ crates/editor/src/editor.rs | 39 ++++++++++------------ crates/editor/src/inlay_cache.rs | 10 +++--- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index 7e39402e59..fe3c0d86ab 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -1169,6 +1169,7 @@ impl FoldOffset { FoldPoint(cursor.start().1.output.lines + overshoot) } + #[cfg(test)] pub fn to_inlay_offset(self, snapshot: &FoldSnapshot) -> InlayOffset { let mut cursor = snapshot.transforms.cursor::<(FoldOffset, InlayOffset)>(); cursor.seek(&self, Bias::Right, &()); diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index ea6acaaffe..d731e0dc4c 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -13,7 +13,6 @@ use std::{ }; use sum_tree::{Bias, Cursor, SumTree}; use text::Patch; -use util::post_inc; pub struct InlayMap { snapshot: Mutex, @@ -284,10 +283,6 @@ impl InlayPoint { pub fn row(self) -> u32 { self.0.row } - - pub fn column(self) -> u32 { - self.0.column - } } impl InlayMap { @@ -493,13 +488,14 @@ impl InlayMap { self.sync(buffer_snapshot, buffer_edits) } - #[cfg(any(test, feature = "test-support"))] + #[cfg(test)] pub(crate) fn randomly_mutate( &mut self, next_inlay_id: &mut usize, rng: &mut rand::rngs::StdRng, ) -> (InlaySnapshot, Vec) { use rand::prelude::*; + use util::post_inc; let mut to_remove = Vec::new(); let mut to_insert = Vec::new(); @@ -590,11 +586,6 @@ impl InlaySnapshot { } } - pub fn chars_at(&self, start: InlayPoint) -> impl '_ + Iterator { - self.chunks(self.to_offset(start)..self.len(), false, None) - .flat_map(|chunk| chunk.text.chars()) - } - pub fn to_buffer_point(&self, point: InlayPoint) -> Point { let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(); cursor.seek(&point, Bias::Right, &()); diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index bf6e88de50..1e5370cce5 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -55,7 +55,7 @@ use gpui::{ use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; use inlay_cache::{ - Inlay, InlayCache, InlayFetchRange, InlayId, InlayProperties, InlayRefreshReason, InlaySplice, + Inlay, InlayCache, InlayHintQuery, InlayId, InlayProperties, InlayRefreshReason, InlaySplice, }; pub use items::MAX_TAB_TITLE_LEN; use itertools::Itertools; @@ -1302,7 +1302,7 @@ impl Editor { } project_subscriptions.push(cx.subscribe(project, |editor, _, event, cx| { if let project::Event::RefreshInlays = event { - editor.refresh_inlays(InlayRefreshReason::OpenExcerptsChange, cx); + editor.refresh_inlays(InlayRefreshReason::VisibleExcerptsChange, cx); }; })); } @@ -1382,7 +1382,7 @@ impl Editor { } this.report_editor_event("open", None, cx); - this.refresh_inlays(InlayRefreshReason::OpenExcerptsChange, cx); + this.refresh_inlays(InlayRefreshReason::VisibleExcerptsChange, cx); this } @@ -2615,7 +2615,7 @@ impl Editor { self.splice_inlay_hints(to_remove, to_insert, cx); } InlayRefreshReason::Scroll(scrolled_to) => { - let ranges_to_add = self + let addition_queries = self .excerpt_visible_offsets(&multi_buffer_handle, cx) .into_iter() .find_map(|(buffer, excerpt_visible_offset_range, excerpt_id)| { @@ -2623,12 +2623,7 @@ impl Editor { if buffer_id == buffer.read(cx).remote_id() && scrolled_to.anchor.excerpt_id == excerpt_id { - get_inlay_fetch_range( - &buffer, - excerpt_id, - excerpt_visible_offset_range, - cx, - ) + inlay_hint_query(&buffer, excerpt_id, excerpt_visible_offset_range, cx) } else { None } @@ -2641,9 +2636,11 @@ impl Editor { to_insert, } = editor .update(&mut cx, |editor, cx| { - editor - .inlay_cache - .append_inlays(multi_buffer_handle, ranges_to_add, cx) + editor.inlay_cache.append_inlays( + multi_buffer_handle, + addition_queries, + cx, + ) })? .await .context("inlay cache hint fetch")?; @@ -2654,12 +2651,12 @@ impl Editor { }) .detach_and_log_err(cx); } - InlayRefreshReason::OpenExcerptsChange => { - let new_ranges = self + InlayRefreshReason::VisibleExcerptsChange => { + let replacement_queries = self .excerpt_visible_offsets(&multi_buffer_handle, cx) .into_iter() .filter_map(|(buffer, excerpt_visible_offset_range, excerpt_id)| { - get_inlay_fetch_range(&buffer, excerpt_id, excerpt_visible_offset_range, cx) + inlay_hint_query(&buffer, excerpt_id, excerpt_visible_offset_range, cx) }) .collect::>(); cx.spawn(|editor, mut cx| async move { @@ -2670,7 +2667,7 @@ impl Editor { .update(&mut cx, |editor, cx| { editor.inlay_cache.replace_inlays( multi_buffer_handle, - new_ranges.into_iter(), + replacement_queries.into_iter(), cx, ) })? @@ -7355,7 +7352,7 @@ impl Editor { }; if refresh_inlays { - self.refresh_inlays(InlayRefreshReason::OpenExcerptsChange, cx); + self.refresh_inlays(InlayRefreshReason::VisibleExcerptsChange, cx); } } @@ -7660,12 +7657,12 @@ impl Editor { } } -fn get_inlay_fetch_range( +fn inlay_hint_query( buffer: &ModelHandle, excerpt_id: ExcerptId, excerpt_visible_offset_range: Range, cx: &mut ViewContext<'_, '_, Editor>, -) -> Option { +) -> Option { let buffer = buffer.read(cx); let buffer_snapshot = buffer.snapshot(); let max_buffer_len = buffer.len(); @@ -7679,7 +7676,7 @@ fn get_inlay_fetch_range( .end .saturating_add(visible_offset_range_len), ); - Some(InlayFetchRange { + Some(InlayHintQuery { buffer_path: buffer_snapshot.resolve_file_path(cx, true)?, buffer_id: buffer.remote_id(), buffer_version: buffer.version().clone(), diff --git a/crates/editor/src/inlay_cache.rs b/crates/editor/src/inlay_cache.rs index 659473f5e6..b571a29cc1 100644 --- a/crates/editor/src/inlay_cache.rs +++ b/crates/editor/src/inlay_cache.rs @@ -31,7 +31,7 @@ pub struct InlayProperties { pub enum InlayRefreshReason { SettingsChange(editor_settings::InlayHints), Scroll(ScrollAnchor), - OpenExcerptsChange, + VisibleExcerptsChange, } #[derive(Debug, Clone, Default)] @@ -89,7 +89,7 @@ pub struct InlaySplice { pub to_insert: Vec<(InlayId, Anchor, InlayHint)>, } -pub struct InlayFetchRange { +pub struct InlayHintQuery { pub buffer_id: u64, pub buffer_path: PathBuf, pub buffer_version: Global, @@ -109,7 +109,7 @@ impl InlayCache { pub fn append_inlays( &mut self, multi_buffer: ModelHandle, - ranges_to_add: impl Iterator, + ranges_to_add: impl Iterator, cx: &mut ViewContext, ) -> Task> { self.fetch_inlays(multi_buffer, ranges_to_add, false, cx) @@ -118,7 +118,7 @@ impl InlayCache { pub fn replace_inlays( &mut self, multi_buffer: ModelHandle, - new_ranges: impl Iterator, + new_ranges: impl Iterator, cx: &mut ViewContext, ) -> Task> { self.fetch_inlays(multi_buffer, new_ranges, true, cx) @@ -127,7 +127,7 @@ impl InlayCache { fn fetch_inlays( &mut self, multi_buffer: ModelHandle, - inlay_fetch_ranges: impl Iterator, + inlay_fetch_ranges: impl Iterator, replace_old: bool, cx: &mut ViewContext, ) -> Task> {