debugger: Parse and highlight text with ANSI escape sequences (#32915)
Relanding #32817 with an improved approach, bugs fixed, and a test. Release Notes: - N/A
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
use collections::BTreeMap;
|
||||
use gpui::HighlightStyle;
|
||||
use language::Chunk;
|
||||
use multi_buffer::{Anchor, MultiBufferChunks, MultiBufferSnapshot, ToOffset as _};
|
||||
use multi_buffer::{MultiBufferChunks, MultiBufferSnapshot, ToOffset as _};
|
||||
use std::{
|
||||
any::TypeId,
|
||||
cmp,
|
||||
iter::{self, Peekable},
|
||||
ops::Range,
|
||||
sync::Arc,
|
||||
vec,
|
||||
};
|
||||
use sum_tree::TreeMap;
|
||||
|
||||
use crate::display_map::{HighlightKey, TextHighlights};
|
||||
|
||||
pub struct CustomHighlightsChunks<'a> {
|
||||
buffer_chunks: MultiBufferChunks<'a>,
|
||||
@@ -19,15 +18,15 @@ pub struct CustomHighlightsChunks<'a> {
|
||||
multibuffer_snapshot: &'a MultiBufferSnapshot,
|
||||
|
||||
highlight_endpoints: Peekable<vec::IntoIter<HighlightEndpoint>>,
|
||||
active_highlights: BTreeMap<TypeId, HighlightStyle>,
|
||||
text_highlights: Option<&'a TreeMap<TypeId, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>>,
|
||||
active_highlights: BTreeMap<HighlightKey, HighlightStyle>,
|
||||
text_highlights: Option<&'a TextHighlights>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
struct HighlightEndpoint {
|
||||
offset: usize,
|
||||
is_start: bool,
|
||||
tag: TypeId,
|
||||
tag: HighlightKey,
|
||||
style: HighlightStyle,
|
||||
}
|
||||
|
||||
@@ -35,7 +34,7 @@ impl<'a> CustomHighlightsChunks<'a> {
|
||||
pub fn new(
|
||||
range: Range<usize>,
|
||||
language_aware: bool,
|
||||
text_highlights: Option<&'a TreeMap<TypeId, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>>,
|
||||
text_highlights: Option<&'a TextHighlights>,
|
||||
multibuffer_snapshot: &'a MultiBufferSnapshot,
|
||||
) -> Self {
|
||||
Self {
|
||||
@@ -66,7 +65,7 @@ impl<'a> CustomHighlightsChunks<'a> {
|
||||
|
||||
fn create_highlight_endpoints(
|
||||
range: &Range<usize>,
|
||||
text_highlights: Option<&TreeMap<TypeId, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>>,
|
||||
text_highlights: Option<&TextHighlights>,
|
||||
buffer: &MultiBufferSnapshot,
|
||||
) -> iter::Peekable<vec::IntoIter<HighlightEndpoint>> {
|
||||
let mut highlight_endpoints = Vec::new();
|
||||
|
||||
@@ -1115,7 +1115,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
InlayId, MultiBuffer,
|
||||
display_map::{InlayHighlights, TextHighlights},
|
||||
display_map::{HighlightKey, InlayHighlights, TextHighlights},
|
||||
hover_links::InlayHighlight,
|
||||
};
|
||||
use gpui::{App, HighlightStyle};
|
||||
@@ -1629,7 +1629,7 @@ mod tests {
|
||||
text_highlight_ranges.sort_by_key(|range| (range.start, Reverse(range.end)));
|
||||
log::info!("highlighting text ranges {text_highlight_ranges:?}");
|
||||
text_highlights.insert(
|
||||
TypeId::of::<()>(),
|
||||
HighlightKey::Type(TypeId::of::<()>()),
|
||||
Arc::new((
|
||||
HighlightStyle::default(),
|
||||
text_highlight_ranges
|
||||
|
||||
Reference in New Issue
Block a user