Pass inlay highlight information

This commit is contained in:
Kirill Bulatov 2023-08-21 23:21:37 +03:00
parent 477fc865f5
commit 6c5761d05b
9 changed files with 279 additions and 145 deletions

View file

@ -1,6 +1,6 @@
use super::{
fold_map::{self, FoldChunks, FoldEdit, FoldPoint, FoldSnapshot},
TextHighlights,
InlayHighlights, TextHighlights,
};
use crate::MultiBufferSnapshot;
use gpui::fonts::HighlightStyle;
@ -71,6 +71,7 @@ impl TabMap {
None,
None,
None,
None,
) {
for (ix, _) in chunk.text.match_indices('\t') {
let offset_from_edit = offset_from_edit + (ix as u32);
@ -183,7 +184,7 @@ impl TabSnapshot {
self.max_point()
};
for c in self
.chunks(range.start..line_end, false, None, None, None)
.chunks(range.start..line_end, false, None, None, None, None)
.flat_map(|chunk| chunk.text.chars())
{
if c == '\n' {
@ -203,6 +204,7 @@ impl TabSnapshot {
None,
None,
None,
None,
)
.flat_map(|chunk| chunk.text.chars())
{
@ -223,9 +225,11 @@ impl TabSnapshot {
&'a self,
range: Range<TabPoint>,
language_aware: bool,
// TODO kb extract into one struct
text_highlights: Option<&'a TextHighlights>,
hint_highlights: Option<HighlightStyle>,
suggestion_highlights: Option<HighlightStyle>,
inlay_highlights: Option<&'a InlayHighlights>,
inlay_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
) -> TabChunks<'a> {
let (input_start, expanded_char_column, to_next_stop) =
self.to_fold_point(range.start, Bias::Left);
@ -246,8 +250,9 @@ impl TabSnapshot {
input_start..input_end,
language_aware,
text_highlights,
hint_highlights,
suggestion_highlights,
inlay_highlights,
inlay_highlight_style,
suggestion_highlight_style,
),
input_column,
column: expanded_char_column,
@ -270,9 +275,16 @@ impl TabSnapshot {
#[cfg(test)]
pub fn text(&self) -> String {
self.chunks(TabPoint::zero()..self.max_point(), false, None, None, None)
.map(|chunk| chunk.text)
.collect()
self.chunks(
TabPoint::zero()..self.max_point(),
false,
None,
None,
None,
None,
)
.map(|chunk| chunk.text)
.collect()
}
pub fn max_point(&self) -> TabPoint {
@ -600,6 +612,7 @@ mod tests {
None,
None,
None,
None,
)
.map(|c| c.text)
.collect::<String>(),
@ -674,7 +687,8 @@ mod tests {
let mut chunks = Vec::new();
let mut was_tab = false;
let mut text = String::new();
for chunk in snapshot.chunks(start..snapshot.max_point(), false, None, None, None) {
for chunk in snapshot.chunks(start..snapshot.max_point(), false, None, None, None, None)
{
if chunk.is_tab != was_tab {
if !text.is_empty() {
chunks.push((mem::take(&mut text), was_tab));
@ -743,7 +757,7 @@ mod tests {
let expected_summary = TextSummary::from(expected_text.as_str());
assert_eq!(
tabs_snapshot
.chunks(start..end, false, None, None, None)
.chunks(start..end, false, None, None, None, None)
.map(|c| c.text)
.collect::<String>(),
expected_text,