Renames: HighlightedText->HighlightedMatch + HighlightedEdits->HighlightedText (#24057)

In support of work on
https://github.com/zed-industries/zed/tree/new-ui-for-edit-prediction-with-lsp-completions,
where we want to be able to extract a range of the buffer as
`HighlightedText`.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-31 16:15:46 -07:00 committed by GitHub
parent 4d9659adc4
commit 93c7b54caa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 21 additions and 21 deletions

View file

@ -96,7 +96,7 @@ use itertools::Itertools;
use language::{ use language::{
language_settings::{self, all_language_settings, language_settings, InlayHintSettings}, language_settings::{self, all_language_settings, language_settings, InlayHintSettings},
markdown, point_from_lsp, AutoindentMode, BracketPair, Buffer, Capability, CharKind, CodeLabel, markdown, point_from_lsp, AutoindentMode, BracketPair, Buffer, Capability, CharKind, CodeLabel,
CursorShape, Diagnostic, Documentation, EditPreview, HighlightedEdits, IndentKind, IndentSize, CursorShape, Diagnostic, Documentation, EditPreview, HighlightedText, IndentKind, IndentSize,
Language, OffsetRangeExt, Point, Selection, SelectionGoal, TextObject, TransactionId, Language, OffsetRangeExt, Point, Selection, SelectionGoal, TextObject, TransactionId,
TreeSitterOptions, TreeSitterOptions,
}; };
@ -488,7 +488,7 @@ impl InlineCompletionMenuHint {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
enum InlineCompletionText { enum InlineCompletionText {
Move(SharedString), Move(SharedString),
Edit(HighlightedEdits), Edit(HighlightedText),
} }
pub(crate) enum EditDisplayMode { pub(crate) enum EditDisplayMode {
@ -15850,7 +15850,7 @@ fn inline_completion_edit_text(
edit_preview: &EditPreview, edit_preview: &EditPreview,
include_deletions: bool, include_deletions: bool,
cx: &App, cx: &App,
) -> Option<HighlightedEdits> { ) -> Option<HighlightedText> {
let edits = edits let edits = edits
.iter() .iter()
.map(|(anchor, text)| { .map(|(anchor, text)| {

View file

@ -15417,7 +15417,7 @@ async fn assert_highlighted_edits(
edits: Vec<(Range<Point>, String)>, edits: Vec<(Range<Point>, String)>,
include_deletions: bool, include_deletions: bool,
cx: &mut TestAppContext, cx: &mut TestAppContext,
assertion_fn: impl Fn(HighlightedEdits, &App), assertion_fn: impl Fn(HighlightedText, &App),
) { ) {
let window = cx.add_window(|window, cx| { let window = cx.add_window(|window, cx| {
let buffer = MultiBuffer::build_simple(text, cx); let buffer = MultiBuffer::build_simple(text, cx);

View file

@ -596,7 +596,7 @@ pub struct EditPreview {
} }
#[derive(Default, Clone, Debug)] #[derive(Default, Clone, Debug)]
pub struct HighlightedEdits { pub struct HighlightedText {
pub text: SharedString, pub text: SharedString,
pub highlights: Vec<(Range<usize>, HighlightStyle)>, pub highlights: Vec<(Range<usize>, HighlightStyle)>,
} }
@ -608,9 +608,9 @@ impl EditPreview {
edits: &[(Range<Anchor>, String)], edits: &[(Range<Anchor>, String)],
include_deletions: bool, include_deletions: bool,
cx: &App, cx: &App,
) -> HighlightedEdits { ) -> HighlightedText {
let Some(visible_range_in_preview_snapshot) = self.compute_visible_range(edits) else { let Some(visible_range_in_preview_snapshot) = self.compute_visible_range(edits) else {
return HighlightedEdits::default(); return HighlightedText::default();
}; };
let mut text = String::new(); let mut text = String::new();
@ -686,7 +686,7 @@ impl EditPreview {
cx, cx,
); );
HighlightedEdits { HighlightedText {
text: text.into(), text: text.into(),
highlights, highlights,
} }

View file

@ -2739,7 +2739,7 @@ async fn test_preview_edits(cx: &mut TestAppContext) {
edits: Vec<(Range<Point>, &str)>, edits: Vec<(Range<Point>, &str)>,
include_deletions: bool, include_deletions: bool,
cx: &mut TestAppContext, cx: &mut TestAppContext,
assert_fn: impl Fn(HighlightedEdits), assert_fn: impl Fn(HighlightedText),
) { ) {
let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx)); let buffer = cx.new(|cx| Buffer::local(text, cx).with_language(Arc::new(rust_lang()), cx));
let edits = buffer.read_with(cx, |buffer, _| { let edits = buffer.read_with(cx, |buffer, _| {

View file

@ -2,19 +2,19 @@ use ui::{prelude::*, HighlightedLabel};
#[derive(Clone)] #[derive(Clone)]
pub struct HighlightedMatchWithPaths { pub struct HighlightedMatchWithPaths {
pub match_label: HighlightedText, pub match_label: HighlightedMatch,
pub paths: Vec<HighlightedText>, pub paths: Vec<HighlightedMatch>,
} }
#[derive(Debug, Clone, IntoElement)] #[derive(Debug, Clone, IntoElement)]
pub struct HighlightedText { pub struct HighlightedMatch {
pub text: String, pub text: String,
pub highlight_positions: Vec<usize>, pub highlight_positions: Vec<usize>,
pub char_count: usize, pub char_count: usize,
pub color: Color, pub color: Color,
} }
impl HighlightedText { impl HighlightedMatch {
pub fn join(components: impl Iterator<Item = Self>, separator: &str) -> Self { pub fn join(components: impl Iterator<Item = Self>, separator: &str) -> Self {
let mut char_count = 0; let mut char_count = 0;
let separator_char_count = separator.chars().count(); let separator_char_count = separator.chars().count();
@ -48,7 +48,7 @@ impl HighlightedText {
Self { color, ..self } Self { color, ..self }
} }
} }
impl RenderOnce for HighlightedText { impl RenderOnce for HighlightedMatch {
fn render(self, _window: &mut Window, _: &mut App) -> impl IntoElement { fn render(self, _window: &mut Window, _: &mut App) -> impl IntoElement {
HighlightedLabel::new(self.text, self.highlight_positions).color(self.color) HighlightedLabel::new(self.text, self.highlight_positions).color(self.color)
} }

View file

@ -11,7 +11,7 @@ use gpui::{
}; };
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
use picker::{ use picker::{
highlighted_match_with_paths::{HighlightedMatchWithPaths, HighlightedText}, highlighted_match_with_paths::{HighlightedMatch, HighlightedMatchWithPaths},
Picker, PickerDelegate, Picker, PickerDelegate,
}; };
pub use remote_servers::RemoteServerProjects; pub use remote_servers::RemoteServerProjects;
@ -386,7 +386,7 @@ impl PickerDelegate for RecentProjectsDelegate {
.unzip(); .unzip();
let highlighted_match = HighlightedMatchWithPaths { let highlighted_match = HighlightedMatchWithPaths {
match_label: HighlightedText::join(match_labels.into_iter().flatten(), ", "), match_label: HighlightedMatch::join(match_labels.into_iter().flatten(), ", "),
paths, paths,
}; };
@ -487,7 +487,7 @@ fn highlights_for_path(
path: &Path, path: &Path,
match_positions: &Vec<usize>, match_positions: &Vec<usize>,
path_start_offset: usize, path_start_offset: usize,
) -> (Option<HighlightedText>, HighlightedText) { ) -> (Option<HighlightedMatch>, HighlightedMatch) {
let path_string = path.to_string_lossy(); let path_string = path.to_string_lossy();
let path_char_count = path_string.chars().count(); let path_char_count = path_string.chars().count();
// Get the subset of match highlight positions that line up with the given path. // Get the subset of match highlight positions that line up with the given path.
@ -513,7 +513,7 @@ fn highlights_for_path(
.take_while(|position| *position < file_name_start + char_count) .take_while(|position| *position < file_name_start + char_count)
.map(|position| position - file_name_start) .map(|position| position - file_name_start)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
HighlightedText { HighlightedMatch {
text: text.to_string(), text: text.to_string(),
highlight_positions, highlight_positions,
char_count, char_count,
@ -523,7 +523,7 @@ fn highlights_for_path(
( (
file_name_text_and_positions, file_name_text_and_positions,
HighlightedText { HighlightedMatch {
text: path_string.to_string(), text: path_string.to_string(),
highlight_positions: path_positions, highlight_positions: path_positions,
char_count: path_char_count, char_count: path_char_count,

View file

@ -7,7 +7,7 @@ use gpui::{
Focusable, InteractiveElement, ParentElement, Render, SharedString, Styled, Subscription, Task, Focusable, InteractiveElement, ParentElement, Render, SharedString, Styled, Subscription, Task,
WeakEntity, Window, WeakEntity, Window,
}; };
use picker::{highlighted_match_with_paths::HighlightedText, Picker, PickerDelegate}; use picker::{highlighted_match_with_paths::HighlightedMatch, Picker, PickerDelegate};
use project::{task_store::TaskStore, TaskSourceKind}; use project::{task_store::TaskStore, TaskSourceKind};
use task::{ResolvedTask, RevealTarget, TaskContext, TaskTemplate}; use task::{ResolvedTask, RevealTarget, TaskContext, TaskTemplate};
use ui::{ use ui::{
@ -356,7 +356,7 @@ impl PickerDelegate for TasksModalDelegate {
Some(Tooltip::simple(tooltip_label_text, cx)) Some(Tooltip::simple(tooltip_label_text, cx))
}; };
let highlighted_location = HighlightedText { let highlighted_location = HighlightedMatch {
text: hit.string.clone(), text: hit.string.clone(),
highlight_positions: hit.positions.clone(), highlight_positions: hit.positions.clone(),
char_count: hit.string.chars().count(), char_count: hit.string.chars().count(),