adds tracing for instrumenting non-async functions (#44147)
Tracing code is not included in normal release builds Documents how to use them in our performance docs Only the maps and cursors are instrumented atm # Compile times: current main: fresh release build (cargo clean then build --release) 377.34 secs current main: fresh debug build (cargo clean then build ) 89.31 secs tracing tracy: fresh release build (cargo clean then build --release) 374.84 secs tracing tracy: fresh debug build (cargo clean then build ) 88.95 secs tracing tracy: fresh release build with timings (cargo clean then build --release --features tracing) 375.77 secs tracing tracy: fresh debug build with timings (cargo clean then build --features tracing) 90.03 secs Release Notes: - N/A --------- Co-authored-by: localcc <work@localcc.cc>
This commit is contained in:
co-authored by
localcc
parent
07fe8e9bb1
commit
b558be7ec6
@@ -164,6 +164,7 @@ impl<T> BlockPlacement<T> {
|
||||
}
|
||||
|
||||
impl BlockPlacement<Anchor> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn cmp(&self, other: &Self, buffer: &MultiBufferSnapshot) -> Ordering {
|
||||
self.start()
|
||||
.cmp(other.start(), buffer)
|
||||
@@ -171,6 +172,7 @@ impl BlockPlacement<Anchor> {
|
||||
.then_with(|| self.tie_break().cmp(&other.tie_break()))
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn to_wrap_row(&self, wrap_snapshot: &WrapSnapshot) -> Option<BlockPlacement<WrapRow>> {
|
||||
let buffer_snapshot = wrap_snapshot.buffer_snapshot();
|
||||
match self {
|
||||
@@ -474,6 +476,7 @@ pub struct BlockRows<'a> {
|
||||
}
|
||||
|
||||
impl BlockMap {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn new(
|
||||
wrap_snapshot: WrapSnapshot,
|
||||
buffer_header_height: u32,
|
||||
@@ -503,6 +506,7 @@ impl BlockMap {
|
||||
map
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn read(&self, wrap_snapshot: WrapSnapshot, edits: WrapPatch) -> BlockMapReader<'_> {
|
||||
self.sync(&wrap_snapshot, edits);
|
||||
*self.wrap_snapshot.borrow_mut() = wrap_snapshot.clone();
|
||||
@@ -518,13 +522,17 @@ impl BlockMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn write(&mut self, wrap_snapshot: WrapSnapshot, edits: WrapPatch) -> BlockMapWriter<'_> {
|
||||
self.sync(&wrap_snapshot, edits);
|
||||
*self.wrap_snapshot.borrow_mut() = wrap_snapshot;
|
||||
BlockMapWriter(self)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all, fields(edits))]
|
||||
fn sync(&self, wrap_snapshot: &WrapSnapshot, mut edits: WrapPatch) {
|
||||
let _timer = zlog::time!("BlockMap::sync").warn_if_gt(std::time::Duration::from_millis(50));
|
||||
|
||||
let buffer = wrap_snapshot.buffer_snapshot();
|
||||
|
||||
// Handle changing the last excerpt if it is empty.
|
||||
@@ -784,6 +792,7 @@ impl BlockMap {
|
||||
*transforms = new_transforms;
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn replace_blocks(&mut self, mut renderers: HashMap<CustomBlockId, RenderBlock>) {
|
||||
for block in &mut self.custom_blocks {
|
||||
if let Some(render) = renderers.remove(&block.id) {
|
||||
@@ -793,6 +802,7 @@ impl BlockMap {
|
||||
}
|
||||
|
||||
/// Guarantees that `wrap_row_for` is called with points in increasing order.
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn header_and_footer_blocks<'a, R, T>(
|
||||
&'a self,
|
||||
buffer: &'a multi_buffer::MultiBufferSnapshot,
|
||||
@@ -880,6 +890,7 @@ impl BlockMap {
|
||||
})
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn sort_blocks(blocks: &mut Vec<(BlockPlacement<WrapRow>, Block)>) {
|
||||
blocks.sort_unstable_by(|(placement_a, block_a), (placement_b, block_b)| {
|
||||
placement_a
|
||||
@@ -1016,6 +1027,7 @@ impl DerefMut for BlockMapReader<'_> {
|
||||
}
|
||||
|
||||
impl BlockMapReader<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn row_for_block(&self, block_id: CustomBlockId) -> Option<BlockRow> {
|
||||
let block = self.blocks.iter().find(|block| block.id == block_id)?;
|
||||
let buffer_row = block
|
||||
@@ -1054,6 +1066,7 @@ impl BlockMapReader<'_> {
|
||||
}
|
||||
|
||||
impl BlockMapWriter<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn insert(
|
||||
&mut self,
|
||||
blocks: impl IntoIterator<Item = BlockProperties<Anchor>>,
|
||||
@@ -1120,6 +1133,7 @@ impl BlockMapWriter<'_> {
|
||||
ids
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn resize(&mut self, mut heights: HashMap<CustomBlockId, u32>) {
|
||||
let wrap_snapshot = &*self.0.wrap_snapshot.borrow();
|
||||
let buffer = wrap_snapshot.buffer_snapshot();
|
||||
@@ -1172,6 +1186,7 @@ impl BlockMapWriter<'_> {
|
||||
self.0.sync(wrap_snapshot, edits);
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn remove(&mut self, block_ids: HashSet<CustomBlockId>) {
|
||||
let wrap_snapshot = &*self.0.wrap_snapshot.borrow();
|
||||
let buffer = wrap_snapshot.buffer_snapshot();
|
||||
@@ -1217,6 +1232,7 @@ impl BlockMapWriter<'_> {
|
||||
self.0.sync(wrap_snapshot, edits);
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn remove_intersecting_replace_blocks(
|
||||
&mut self,
|
||||
ranges: impl IntoIterator<Item = Range<MultiBufferOffset>>,
|
||||
@@ -1239,6 +1255,7 @@ impl BlockMapWriter<'_> {
|
||||
self.0.buffers_with_disabled_headers.insert(buffer_id);
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn fold_buffers(
|
||||
&mut self,
|
||||
buffer_ids: impl IntoIterator<Item = BufferId>,
|
||||
@@ -1248,6 +1265,7 @@ impl BlockMapWriter<'_> {
|
||||
self.fold_or_unfold_buffers(true, buffer_ids, multi_buffer, cx);
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn unfold_buffers(
|
||||
&mut self,
|
||||
buffer_ids: impl IntoIterator<Item = BufferId>,
|
||||
@@ -1257,6 +1275,7 @@ impl BlockMapWriter<'_> {
|
||||
self.fold_or_unfold_buffers(false, buffer_ids, multi_buffer, cx);
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn fold_or_unfold_buffers(
|
||||
&mut self,
|
||||
fold: bool,
|
||||
@@ -1292,6 +1311,7 @@ impl BlockMapWriter<'_> {
|
||||
self.0.sync(&wrap_snapshot, edits);
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn blocks_intersecting_buffer_range(
|
||||
&self,
|
||||
range: Range<MultiBufferOffset>,
|
||||
@@ -1326,6 +1346,7 @@ impl BlockMapWriter<'_> {
|
||||
|
||||
impl BlockSnapshot {
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(
|
||||
BlockRow(0)..self.transforms.summary().output_rows,
|
||||
@@ -1337,6 +1358,7 @@ impl BlockSnapshot {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn chunks<'a>(
|
||||
&'a self,
|
||||
rows: Range<BlockRow>,
|
||||
@@ -1378,6 +1400,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(super) fn row_infos(&self, start_row: BlockRow) -> BlockRows<'_> {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&start_row, Bias::Right);
|
||||
@@ -1399,6 +1422,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn blocks_in_range(
|
||||
&self,
|
||||
rows: Range<BlockRow>,
|
||||
@@ -1432,6 +1456,7 @@ impl BlockSnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn sticky_header_excerpt(&self, position: f64) -> Option<StickyHeaderExcerpt<'_>> {
|
||||
let top_row = position as u32;
|
||||
let mut cursor = self.transforms.cursor::<BlockRow>(());
|
||||
@@ -1455,6 +1480,7 @@ impl BlockSnapshot {
|
||||
None
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn block_for_id(&self, block_id: BlockId) -> Option<Block> {
|
||||
let buffer = self.wrap_snapshot.buffer_snapshot();
|
||||
let wrap_point = match block_id {
|
||||
@@ -1491,6 +1517,7 @@ impl BlockSnapshot {
|
||||
None
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn max_point(&self) -> BlockPoint {
|
||||
let row = self
|
||||
.transforms
|
||||
@@ -1500,10 +1527,12 @@ impl BlockSnapshot {
|
||||
BlockPoint::new(row, self.line_len(row))
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn longest_row(&self) -> BlockRow {
|
||||
self.transforms.summary().longest_row
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn longest_row_in_range(&self, range: Range<BlockRow>) -> BlockRow {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
@@ -1555,6 +1584,7 @@ impl BlockSnapshot {
|
||||
longest_row
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(super) fn line_len(&self, row: BlockRow) -> u32 {
|
||||
let (start, _, item) =
|
||||
self.transforms
|
||||
@@ -1574,11 +1604,13 @@ impl BlockSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(super) fn is_block_line(&self, row: BlockRow) -> bool {
|
||||
let (_, _, item) = self.transforms.find::<BlockRow, _>((), &row, Bias::Right);
|
||||
item.is_some_and(|t| t.block.is_some())
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(super) fn is_folded_buffer_header(&self, row: BlockRow) -> bool {
|
||||
let (_, _, item) = self.transforms.find::<BlockRow, _>((), &row, Bias::Right);
|
||||
let Some(transform) = item else {
|
||||
@@ -1587,6 +1619,7 @@ impl BlockSnapshot {
|
||||
matches!(transform.block, Some(Block::FoldedBuffer { .. }))
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(super) fn is_line_replaced(&self, row: MultiBufferRow) -> bool {
|
||||
let wrap_point = self
|
||||
.wrap_snapshot
|
||||
@@ -1602,6 +1635,7 @@ impl BlockSnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(());
|
||||
cursor.seek(&BlockRow(point.row), Bias::Right);
|
||||
@@ -1663,6 +1697,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_block_point(&self, wrap_point: WrapPoint) -> BlockPoint {
|
||||
let (start, _, item) = self.transforms.find::<Dimensions<WrapRow, BlockRow>, _>(
|
||||
(),
|
||||
@@ -1684,6 +1719,7 @@ impl BlockSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_wrap_point(&self, block_point: BlockPoint, bias: Bias) -> WrapPoint {
|
||||
let (start, end, item) = self.transforms.find::<Dimensions<BlockRow, WrapRow>, _>(
|
||||
(),
|
||||
@@ -1719,6 +1755,7 @@ impl BlockSnapshot {
|
||||
|
||||
impl BlockChunks<'_> {
|
||||
/// Go to the next transform
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn advance(&mut self) {
|
||||
self.input_chunk = Chunk::default();
|
||||
self.transforms.next();
|
||||
@@ -1759,6 +1796,7 @@ pub struct StickyHeaderExcerpt<'a> {
|
||||
impl<'a> Iterator for BlockChunks<'a> {
|
||||
type Item = Chunk<'a>;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.output_row >= self.max_output_row {
|
||||
return None;
|
||||
@@ -1858,6 +1896,7 @@ impl<'a> Iterator for BlockChunks<'a> {
|
||||
impl Iterator for BlockRows<'_> {
|
||||
type Item = RowInfo;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.started {
|
||||
self.output_row.0 += 1;
|
||||
@@ -1960,14 +1999,17 @@ impl DerefMut for BlockContext<'_, '_> {
|
||||
}
|
||||
|
||||
impl CustomBlock {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn render(&self, cx: &mut BlockContext) -> AnyElement {
|
||||
self.render.lock()(cx)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn start(&self) -> Anchor {
|
||||
*self.placement.start()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn end(&self) -> Anchor {
|
||||
*self.placement.end()
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ pub struct CreaseMap {
|
||||
}
|
||||
|
||||
impl CreaseMap {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn new(snapshot: &MultiBufferSnapshot) -> Self {
|
||||
CreaseMap {
|
||||
snapshot: CreaseSnapshot::new(snapshot),
|
||||
@@ -40,11 +41,13 @@ impl CreaseSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn creases(&self) -> impl Iterator<Item = (CreaseId, &Crease<Anchor>)> {
|
||||
self.creases.iter().map(|item| (item.id, &item.crease))
|
||||
}
|
||||
|
||||
/// Returns the first Crease starting on the specified buffer row.
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn query_row<'a>(
|
||||
&'a self,
|
||||
row: MultiBufferRow,
|
||||
@@ -69,6 +72,7 @@ impl CreaseSnapshot {
|
||||
None
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn creases_in_range<'a>(
|
||||
&'a self,
|
||||
range: Range<MultiBufferRow>,
|
||||
@@ -95,6 +99,7 @@ impl CreaseSnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn crease_items_with_offsets(
|
||||
&self,
|
||||
snapshot: &MultiBufferSnapshot,
|
||||
@@ -156,6 +161,7 @@ pub struct CreaseMetadata {
|
||||
}
|
||||
|
||||
impl<T> Crease<T> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn simple(range: Range<T>, placeholder: FoldPlaceholder) -> Self {
|
||||
Crease::Inline {
|
||||
range,
|
||||
@@ -166,6 +172,7 @@ impl<T> Crease<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn block(range: Range<T>, height: u32, style: BlockStyle, render: RenderBlock) -> Self {
|
||||
Self::Block {
|
||||
range,
|
||||
@@ -177,6 +184,7 @@ impl<T> Crease<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn inline<RenderToggle, ToggleElement, RenderTrailer, TrailerElement>(
|
||||
range: Range<T>,
|
||||
placeholder: FoldPlaceholder,
|
||||
@@ -216,6 +224,7 @@ impl<T> Crease<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn with_metadata(self, metadata: CreaseMetadata) -> Self {
|
||||
match self {
|
||||
Crease::Inline {
|
||||
@@ -235,6 +244,7 @@ impl<T> Crease<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn range(&self) -> &Range<T> {
|
||||
match self {
|
||||
Crease::Inline { range, .. } => range,
|
||||
@@ -242,6 +252,7 @@ impl<T> Crease<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn metadata(&self) -> Option<&CreaseMetadata> {
|
||||
match self {
|
||||
Self::Inline { metadata, .. } => metadata.as_ref(),
|
||||
@@ -287,6 +298,7 @@ impl CreaseMap {
|
||||
self.snapshot.clone()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn insert(
|
||||
&mut self,
|
||||
creases: impl IntoIterator<Item = Crease<Anchor>>,
|
||||
@@ -312,6 +324,7 @@ impl CreaseMap {
|
||||
new_ids
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn remove(
|
||||
&mut self,
|
||||
ids: impl IntoIterator<Item = CreaseId>,
|
||||
@@ -379,6 +392,7 @@ impl sum_tree::Summary for ItemSummary {
|
||||
impl sum_tree::Item for CreaseItem {
|
||||
type Summary = ItemSummary;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn summary(&self, _cx: &MultiBufferSnapshot) -> Self::Summary {
|
||||
ItemSummary {
|
||||
range: self.crease.range().clone(),
|
||||
@@ -388,12 +402,14 @@ impl sum_tree::Item for CreaseItem {
|
||||
|
||||
/// Implements `SeekTarget` for `Range<Anchor>` to enable seeking within a `SumTree` of `CreaseItem`s.
|
||||
impl SeekTarget<'_, ItemSummary, ItemSummary> for Range<Anchor> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn cmp(&self, cursor_location: &ItemSummary, snapshot: &MultiBufferSnapshot) -> Ordering {
|
||||
AnchorRangeExt::cmp(self, &cursor_location.range, snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
impl SeekTarget<'_, ItemSummary, ItemSummary> for Anchor {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn cmp(&self, other: &ItemSummary, snapshot: &MultiBufferSnapshot) -> Ordering {
|
||||
self.cmp(&other.range.start, snapshot)
|
||||
}
|
||||
@@ -461,6 +477,7 @@ mod test {
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn test_creases_in_range(cx: &mut App) {
|
||||
let text = "line1\nline2\nline3\nline4\nline5\nline6\nline7";
|
||||
let buffer = MultiBuffer::build_simple(text, cx);
|
||||
|
||||
@@ -30,6 +30,7 @@ struct HighlightEndpoint {
|
||||
}
|
||||
|
||||
impl<'a> CustomHighlightsChunks<'a> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn new(
|
||||
range: Range<MultiBufferOffset>,
|
||||
language_aware: bool,
|
||||
@@ -51,6 +52,7 @@ impl<'a> CustomHighlightsChunks<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn seek(&mut self, new_range: Range<MultiBufferOffset>) {
|
||||
self.highlight_endpoints =
|
||||
create_highlight_endpoints(&new_range, self.text_highlights, self.multibuffer_snapshot);
|
||||
@@ -108,6 +110,7 @@ fn create_highlight_endpoints(
|
||||
impl<'a> Iterator for CustomHighlightsChunks<'a> {
|
||||
type Item = Chunk<'a>;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mut next_highlight_endpoint = MultiBufferOffset(usize::MAX);
|
||||
while let Some(endpoint) = self.highlight_endpoints.peek().copied() {
|
||||
|
||||
@@ -99,6 +99,7 @@ impl FoldPoint {
|
||||
&mut self.0.column
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_inlay_point(self, snapshot: &FoldSnapshot) -> InlayPoint {
|
||||
let (start, _, _) = snapshot
|
||||
.transforms
|
||||
@@ -107,6 +108,7 @@ impl FoldPoint {
|
||||
InlayPoint(start.1.0 + overshoot)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_offset(self, snapshot: &FoldSnapshot) -> FoldOffset {
|
||||
let (start, _, item) = snapshot
|
||||
.transforms
|
||||
@@ -138,6 +140,7 @@ impl<'a> sum_tree::Dimension<'a, TransformSummary> for FoldPoint {
|
||||
pub(crate) struct FoldMapWriter<'a>(&'a mut FoldMap);
|
||||
|
||||
impl FoldMapWriter<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn fold<T: ToOffset>(
|
||||
&mut self,
|
||||
ranges: impl IntoIterator<Item = (Range<T>, FoldPlaceholder)>,
|
||||
@@ -202,6 +205,7 @@ impl FoldMapWriter<'_> {
|
||||
}
|
||||
|
||||
/// Removes any folds with the given ranges.
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn remove_folds<T: ToOffset>(
|
||||
&mut self,
|
||||
ranges: impl IntoIterator<Item = Range<T>>,
|
||||
@@ -215,6 +219,7 @@ impl FoldMapWriter<'_> {
|
||||
}
|
||||
|
||||
/// Removes any folds whose ranges intersect the given ranges.
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn unfold_intersecting<T: ToOffset>(
|
||||
&mut self,
|
||||
ranges: impl IntoIterator<Item = Range<T>>,
|
||||
@@ -225,6 +230,7 @@ impl FoldMapWriter<'_> {
|
||||
|
||||
/// Removes any folds that intersect the given ranges and for which the given predicate
|
||||
/// returns true.
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn remove_folds_with<T: ToOffset>(
|
||||
&mut self,
|
||||
ranges: impl IntoIterator<Item = Range<T>>,
|
||||
@@ -277,6 +283,7 @@ impl FoldMapWriter<'_> {
|
||||
(self.0.snapshot.clone(), edits)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn update_fold_widths(
|
||||
&mut self,
|
||||
new_widths: impl IntoIterator<Item = (ChunkRendererId, Pixels)>,
|
||||
@@ -326,6 +333,7 @@ pub struct FoldMap {
|
||||
}
|
||||
|
||||
impl FoldMap {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn new(inlay_snapshot: InlaySnapshot) -> (Self, FoldSnapshot) {
|
||||
let this = Self {
|
||||
snapshot: FoldSnapshot {
|
||||
@@ -350,6 +358,7 @@ impl FoldMap {
|
||||
(this, snapshot)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn read(
|
||||
&mut self,
|
||||
inlay_snapshot: InlaySnapshot,
|
||||
@@ -360,6 +369,7 @@ impl FoldMap {
|
||||
(self.snapshot.clone(), edits)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn write(
|
||||
&mut self,
|
||||
inlay_snapshot: InlaySnapshot,
|
||||
@@ -369,6 +379,7 @@ impl FoldMap {
|
||||
(FoldMapWriter(self), snapshot, edits)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn check_invariants(&self) {
|
||||
if cfg!(test) {
|
||||
assert_eq!(
|
||||
@@ -398,6 +409,7 @@ impl FoldMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn sync(
|
||||
&mut self,
|
||||
inlay_snapshot: InlaySnapshot,
|
||||
@@ -645,6 +657,7 @@ impl FoldSnapshot {
|
||||
&self.inlay_snapshot.buffer
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn fold_width(&self, fold_id: &FoldId) -> Option<Pixels> {
|
||||
self.fold_metadata_by_id.get(fold_id)?.width
|
||||
}
|
||||
@@ -665,6 +678,7 @@ impl FoldSnapshot {
|
||||
self.folds.items(&self.inlay_snapshot.buffer).len()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text_summary_for_range(&self, range: Range<FoldPoint>) -> MBTextSummary {
|
||||
let mut summary = MBTextSummary::default();
|
||||
|
||||
@@ -718,6 +732,7 @@ impl FoldSnapshot {
|
||||
summary
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_fold_point(&self, point: InlayPoint, bias: Bias) -> FoldPoint {
|
||||
let (start, end, item) = self
|
||||
.transforms
|
||||
@@ -734,6 +749,7 @@ impl FoldSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn fold_point_cursor(&self) -> FoldPointCursor<'_> {
|
||||
let cursor = self
|
||||
.transforms
|
||||
@@ -741,10 +757,12 @@ impl FoldSnapshot {
|
||||
FoldPointCursor { cursor }
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn len(&self) -> FoldOffset {
|
||||
FoldOffset(self.transforms.summary().output.len)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn line_len(&self, row: u32) -> u32 {
|
||||
let line_start = FoldPoint::new(row, 0).to_offset(self).0;
|
||||
let line_end = if row >= self.max_point().row() {
|
||||
@@ -755,6 +773,7 @@ impl FoldSnapshot {
|
||||
(line_end - line_start) as u32
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn row_infos(&self, start_row: u32) -> FoldRows<'_> {
|
||||
if start_row > self.transforms.summary().output.lines.row {
|
||||
panic!("invalid display row {}", start_row);
|
||||
@@ -777,6 +796,7 @@ impl FoldSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn max_point(&self) -> FoldPoint {
|
||||
FoldPoint(self.transforms.summary().output.lines)
|
||||
}
|
||||
@@ -786,6 +806,7 @@ impl FoldSnapshot {
|
||||
self.transforms.summary().output.longest_row
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn folds_in_range<T>(&self, range: Range<T>) -> impl Iterator<Item = &Fold>
|
||||
where
|
||||
T: ToOffset,
|
||||
@@ -800,6 +821,7 @@ impl FoldSnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn intersects_fold<T>(&self, offset: T) -> bool
|
||||
where
|
||||
T: ToOffset,
|
||||
@@ -812,6 +834,7 @@ impl FoldSnapshot {
|
||||
item.is_some_and(|t| t.placeholder.is_some())
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn is_line_folded(&self, buffer_row: MultiBufferRow) -> bool {
|
||||
let mut inlay_point = self
|
||||
.inlay_snapshot
|
||||
@@ -840,6 +863,7 @@ impl FoldSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn chunks<'a>(
|
||||
&'a self,
|
||||
range: Range<FoldOffset>,
|
||||
@@ -884,6 +908,7 @@ impl FoldSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn chars_at(&self, start: FoldPoint) -> impl '_ + Iterator<Item = char> {
|
||||
self.chunks(
|
||||
start.to_offset(self)..self.len(),
|
||||
@@ -893,6 +918,7 @@ impl FoldSnapshot {
|
||||
.flat_map(|chunk| chunk.text.chars())
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn chunks_at(&self, start: FoldPoint) -> FoldChunks<'_> {
|
||||
self.chunks(
|
||||
start.to_offset(self)..self.len(),
|
||||
@@ -902,6 +928,7 @@ impl FoldSnapshot {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn clip_offset(&self, offset: FoldOffset, bias: Bias) -> FoldOffset {
|
||||
if offset > self.len() {
|
||||
self.len()
|
||||
@@ -910,6 +937,7 @@ impl FoldSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn clip_point(&self, point: FoldPoint, bias: Bias) -> FoldPoint {
|
||||
let (start, end, item) = self
|
||||
.transforms
|
||||
@@ -939,6 +967,7 @@ pub struct FoldPointCursor<'transforms> {
|
||||
}
|
||||
|
||||
impl FoldPointCursor<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn map(&mut self, point: InlayPoint, bias: Bias) -> FoldPoint {
|
||||
let cursor = &mut self.cursor;
|
||||
if cursor.did_seek() {
|
||||
@@ -1267,6 +1296,7 @@ pub struct FoldRows<'a> {
|
||||
}
|
||||
|
||||
impl FoldRows<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn seek(&mut self, row: u32) {
|
||||
let fold_point = FoldPoint::new(row, 0);
|
||||
self.cursor.seek(&fold_point, Bias::Left);
|
||||
@@ -1280,6 +1310,7 @@ impl FoldRows<'_> {
|
||||
impl Iterator for FoldRows<'_> {
|
||||
type Item = RowInfo;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let mut traversed_fold = false;
|
||||
while self.fold_point > self.cursor.end().0 {
|
||||
@@ -1391,6 +1422,7 @@ pub struct FoldChunks<'a> {
|
||||
}
|
||||
|
||||
impl FoldChunks<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn seek(&mut self, range: Range<FoldOffset>) {
|
||||
self.transform_cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
@@ -1425,6 +1457,7 @@ impl FoldChunks<'_> {
|
||||
impl<'a> Iterator for FoldChunks<'a> {
|
||||
type Item = Chunk<'a>;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.output_offset >= self.max_output_offset {
|
||||
return None;
|
||||
@@ -1524,6 +1557,7 @@ impl<'a> Iterator for FoldChunks<'a> {
|
||||
pub struct FoldOffset(pub MultiBufferOffset);
|
||||
|
||||
impl FoldOffset {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_point(self, snapshot: &FoldSnapshot) -> FoldPoint {
|
||||
let (start, _, item) = snapshot
|
||||
.transforms
|
||||
@@ -1539,6 +1573,7 @@ impl FoldOffset {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_inlay_offset(self, snapshot: &FoldSnapshot) -> InlayOffset {
|
||||
let (start, _, _) = snapshot
|
||||
.transforms
|
||||
|
||||
@@ -52,6 +52,7 @@ enum Transform {
|
||||
impl sum_tree::Item for Transform {
|
||||
type Summary = TransformSummary;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn summary(&self, _: ()) -> Self::Summary {
|
||||
match self {
|
||||
Transform::Isomorphic(summary) => TransformSummary {
|
||||
@@ -228,6 +229,7 @@ pub struct InlayChunk<'a> {
|
||||
}
|
||||
|
||||
impl InlayChunks<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn seek(&mut self, new_range: Range<InlayOffset>) {
|
||||
self.transforms.seek(&new_range.start, Bias::Right);
|
||||
|
||||
@@ -248,6 +250,7 @@ impl InlayChunks<'_> {
|
||||
impl<'a> Iterator for InlayChunks<'a> {
|
||||
type Item = InlayChunk<'a>;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.output_offset == self.max_output_offset {
|
||||
return None;
|
||||
@@ -441,6 +444,7 @@ impl<'a> Iterator for InlayChunks<'a> {
|
||||
}
|
||||
|
||||
impl InlayBufferRows<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn seek(&mut self, row: u32) {
|
||||
let inlay_point = InlayPoint::new(row, 0);
|
||||
self.transforms.seek(&inlay_point, Bias::Left);
|
||||
@@ -465,6 +469,7 @@ impl InlayBufferRows<'_> {
|
||||
impl Iterator for InlayBufferRows<'_> {
|
||||
type Item = RowInfo;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let buffer_row = if self.inlay_row == 0 {
|
||||
self.buffer_rows.next().unwrap()
|
||||
@@ -494,6 +499,7 @@ impl InlayPoint {
|
||||
}
|
||||
|
||||
impl InlayMap {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn new(buffer: MultiBufferSnapshot) -> (Self, InlaySnapshot) {
|
||||
let version = 0;
|
||||
let snapshot = InlaySnapshot {
|
||||
@@ -511,6 +517,7 @@ impl InlayMap {
|
||||
)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn sync(
|
||||
&mut self,
|
||||
buffer_snapshot: MultiBufferSnapshot,
|
||||
@@ -643,6 +650,7 @@ impl InlayMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn splice(
|
||||
&mut self,
|
||||
to_remove: &[InlayId],
|
||||
@@ -693,11 +701,13 @@ impl InlayMap {
|
||||
(snapshot, edits)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn current_inlays(&self) -> impl Iterator<Item = &Inlay> {
|
||||
self.inlays.iter()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn randomly_mutate(
|
||||
&mut self,
|
||||
next_inlay_id: &mut usize,
|
||||
@@ -766,6 +776,7 @@ impl InlayMap {
|
||||
}
|
||||
|
||||
impl InlaySnapshot {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_point(&self, offset: InlayOffset) -> InlayPoint {
|
||||
let (start, _, item) = self.transforms.find::<Dimensions<
|
||||
InlayOffset,
|
||||
@@ -789,14 +800,17 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn len(&self) -> InlayOffset {
|
||||
InlayOffset(self.transforms.summary().output.len)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn max_point(&self) -> InlayPoint {
|
||||
InlayPoint(self.transforms.summary().output.lines)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all, fields(point))]
|
||||
pub fn to_offset(&self, point: InlayPoint) -> InlayOffset {
|
||||
let (start, _, item) = self
|
||||
.transforms
|
||||
@@ -817,6 +831,7 @@ impl InlaySnapshot {
|
||||
None => self.len(),
|
||||
}
|
||||
}
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_buffer_point(&self, point: InlayPoint) -> Point {
|
||||
let (start, _, item) =
|
||||
self.transforms
|
||||
@@ -830,6 +845,7 @@ impl InlaySnapshot {
|
||||
None => self.buffer.max_point(),
|
||||
}
|
||||
}
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_buffer_offset(&self, offset: InlayOffset) -> MultiBufferOffset {
|
||||
let (start, _, item) = self
|
||||
.transforms
|
||||
@@ -844,6 +860,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_inlay_offset(&self, offset: MultiBufferOffset) -> InlayOffset {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
@@ -880,10 +897,12 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_inlay_point(&self, point: Point) -> InlayPoint {
|
||||
self.inlay_point_cursor().map(point)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn inlay_point_cursor(&self) -> InlayPointCursor<'_> {
|
||||
let cursor = self.transforms.cursor::<Dimensions<Point, InlayPoint>>(());
|
||||
InlayPointCursor {
|
||||
@@ -892,6 +911,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn clip_point(&self, mut point: InlayPoint, mut bias: Bias) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
@@ -983,10 +1003,12 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text_summary(&self) -> MBTextSummary {
|
||||
self.transforms.summary().output
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text_summary_for_range(&self, range: Range<InlayOffset>) -> MBTextSummary {
|
||||
let mut summary = MBTextSummary::default();
|
||||
|
||||
@@ -1044,6 +1066,7 @@ impl InlaySnapshot {
|
||||
summary
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn row_infos(&self, row: u32) -> InlayBufferRows<'_> {
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(());
|
||||
let inlay_point = InlayPoint::new(row, 0);
|
||||
@@ -1071,6 +1094,7 @@ impl InlaySnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn line_len(&self, row: u32) -> u32 {
|
||||
let line_start = self.to_offset(InlayPoint::new(row, 0)).0;
|
||||
let line_end = if row >= self.max_point().row() {
|
||||
@@ -1081,6 +1105,7 @@ impl InlaySnapshot {
|
||||
(line_end - line_start) as u32
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn chunks<'a>(
|
||||
&'a self,
|
||||
range: Range<InlayOffset>,
|
||||
@@ -1115,12 +1140,14 @@ impl InlaySnapshot {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(Default::default()..self.len(), false, Highlights::default())
|
||||
.map(|chunk| chunk.chunk.text)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn check_invariants(&self) {
|
||||
#[cfg(any(debug_assertions, feature = "test-support"))]
|
||||
{
|
||||
@@ -1147,6 +1174,7 @@ pub struct InlayPointCursor<'transforms> {
|
||||
}
|
||||
|
||||
impl InlayPointCursor<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn map(&mut self, point: Point) -> InlayPoint {
|
||||
let cursor = &mut self.cursor;
|
||||
if cursor.did_seek() {
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
// ref: https://gist.github.com/ConradIrwin/f759e1fc29267143c4c7895aa495dca5?h=1
|
||||
// ref: https://unicode.org/Public/emoji/13.0/emoji-test.txt
|
||||
// https://github.com/bits/UTF-8-Unicode-Test-Documents/blob/master/UTF-8_sequence_separated/utf8_sequence_0-0x10ffff_assigned_including-unprintable-asis.txt
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn is_invisible(c: char) -> bool {
|
||||
if c <= '\u{1f}' {
|
||||
c != '\t' && c != '\n' && c != '\r'
|
||||
|
||||
@@ -20,6 +20,7 @@ const MAX_TABS: NonZeroU32 = NonZeroU32::new(SPACES.len() as u32).unwrap();
|
||||
pub struct TabMap(TabSnapshot);
|
||||
|
||||
impl TabMap {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn new(fold_snapshot: FoldSnapshot, tab_size: NonZeroU32) -> (Self, TabSnapshot) {
|
||||
let snapshot = TabSnapshot {
|
||||
fold_snapshot,
|
||||
@@ -36,6 +37,7 @@ impl TabMap {
|
||||
self.0.clone()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn sync(
|
||||
&mut self,
|
||||
fold_snapshot: FoldSnapshot,
|
||||
@@ -176,10 +178,12 @@ impl std::ops::Deref for TabSnapshot {
|
||||
}
|
||||
|
||||
impl TabSnapshot {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot {
|
||||
&self.fold_snapshot.inlay_snapshot.buffer
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn line_len(&self, row: u32) -> u32 {
|
||||
let max_point = self.max_point();
|
||||
if row < max_point.row() {
|
||||
@@ -191,10 +195,12 @@ impl TabSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text_summary(&self) -> TextSummary {
|
||||
self.text_summary_for_range(TabPoint::zero()..self.max_point())
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all, fields(rows))]
|
||||
pub fn text_summary_for_range(&self, range: Range<TabPoint>) -> TextSummary {
|
||||
let input_start = self.tab_point_to_fold_point(range.start, Bias::Left).0;
|
||||
let input_end = self.tab_point_to_fold_point(range.end, Bias::Right).0;
|
||||
@@ -234,6 +240,7 @@ impl TabSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn chunks<'a>(
|
||||
&'a self,
|
||||
range: Range<TabPoint>,
|
||||
@@ -276,11 +283,13 @@ impl TabSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn rows(&self, row: u32) -> fold_map::FoldRows<'_> {
|
||||
self.fold_snapshot.row_infos(row)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(
|
||||
TabPoint::zero()..self.max_point(),
|
||||
@@ -291,10 +300,12 @@ impl TabSnapshot {
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn max_point(&self) -> TabPoint {
|
||||
self.fold_point_to_tab_point(self.fold_snapshot.max_point())
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn clip_point(&self, point: TabPoint, bias: Bias) -> TabPoint {
|
||||
self.fold_point_to_tab_point(
|
||||
self.fold_snapshot
|
||||
@@ -302,6 +313,7 @@ impl TabSnapshot {
|
||||
)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn fold_point_to_tab_point(&self, input: FoldPoint) -> TabPoint {
|
||||
let chunks = self.fold_snapshot.chunks_at(FoldPoint::new(input.row(), 0));
|
||||
let tab_cursor = TabStopCursor::new(chunks);
|
||||
@@ -309,10 +321,12 @@ impl TabSnapshot {
|
||||
TabPoint::new(input.row(), expanded)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn tab_point_cursor(&self) -> TabPointCursor<'_> {
|
||||
TabPointCursor { this: self }
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn tab_point_to_fold_point(&self, output: TabPoint, bias: Bias) -> (FoldPoint, u32, u32) {
|
||||
let chunks = self
|
||||
.fold_snapshot
|
||||
@@ -330,12 +344,14 @@ impl TabSnapshot {
|
||||
)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn point_to_tab_point(&self, point: Point, bias: Bias) -> TabPoint {
|
||||
let inlay_point = self.fold_snapshot.inlay_snapshot.to_inlay_point(point);
|
||||
let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
|
||||
self.fold_point_to_tab_point(fold_point)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn tab_point_to_point(&self, point: TabPoint, bias: Bias) -> Point {
|
||||
let fold_point = self.tab_point_to_fold_point(point, bias).0;
|
||||
let inlay_point = fold_point.to_inlay_point(&self.fold_snapshot);
|
||||
@@ -344,6 +360,7 @@ impl TabSnapshot {
|
||||
.to_buffer_point(inlay_point)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn expand_tabs<'a, I>(&self, mut cursor: TabStopCursor<'a, I>, column: u32) -> u32
|
||||
where
|
||||
I: Iterator<Item = Chunk<'a>>,
|
||||
@@ -377,6 +394,7 @@ impl TabSnapshot {
|
||||
expanded_bytes + column.saturating_sub(collapsed_bytes)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn collapse_tabs<'a, I>(
|
||||
&self,
|
||||
mut cursor: TabStopCursor<'a, I>,
|
||||
@@ -442,6 +460,7 @@ pub struct TabPointCursor<'this> {
|
||||
}
|
||||
|
||||
impl TabPointCursor<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn map(&mut self, point: FoldPoint) -> TabPoint {
|
||||
self.this.fold_point_to_tab_point(point)
|
||||
}
|
||||
@@ -486,6 +505,7 @@ pub struct TextSummary {
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for TextSummary {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn from(text: &'a str) -> Self {
|
||||
let sum = text::TextSummary::from(text);
|
||||
|
||||
@@ -500,6 +520,7 @@ impl<'a> From<&'a str> for TextSummary {
|
||||
}
|
||||
|
||||
impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn add_assign(&mut self, other: &'a Self) {
|
||||
let joined_chars = self.last_line_chars + other.first_line_chars;
|
||||
if joined_chars > self.longest_row_chars {
|
||||
@@ -541,6 +562,7 @@ pub struct TabChunks<'a> {
|
||||
}
|
||||
|
||||
impl TabChunks<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn seek(&mut self, range: Range<TabPoint>) {
|
||||
let (input_start, expanded_char_column, to_next_stop) = self
|
||||
.snapshot
|
||||
@@ -576,6 +598,7 @@ impl TabChunks<'_> {
|
||||
impl<'a> Iterator for TabChunks<'a> {
|
||||
type Item = Chunk<'a>;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.chunk.text.is_empty() {
|
||||
if let Some(chunk) = self.fold_chunks.next() {
|
||||
@@ -1452,6 +1475,7 @@ impl<'a, I> TabStopCursor<'a, I>
|
||||
where
|
||||
I: Iterator<Item = Chunk<'a>>,
|
||||
{
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn new(chunks: impl IntoIterator<Item = Chunk<'a>, IntoIter = I>) -> Self {
|
||||
Self {
|
||||
chunks: chunks.into_iter(),
|
||||
@@ -1461,6 +1485,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn bytes_until_next_char(&self) -> Option<usize> {
|
||||
self.current_chunk.as_ref().and_then(|(chunk, idx)| {
|
||||
let mut idx = *idx;
|
||||
@@ -1482,6 +1507,7 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn is_char_boundary(&self) -> bool {
|
||||
self.current_chunk
|
||||
.as_ref()
|
||||
@@ -1489,6 +1515,7 @@ where
|
||||
}
|
||||
|
||||
/// distance: length to move forward while searching for the next tab stop
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn seek(&mut self, distance: u32) -> Option<TabStop> {
|
||||
if distance == 0 {
|
||||
return None;
|
||||
|
||||
@@ -86,6 +86,7 @@ pub struct WrapRows<'a> {
|
||||
}
|
||||
|
||||
impl WrapRows<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn seek(&mut self, start_row: WrapRow) {
|
||||
self.transforms
|
||||
.seek(&WrapPoint::new(start_row, 0), Bias::Left);
|
||||
@@ -101,6 +102,7 @@ impl WrapRows<'_> {
|
||||
}
|
||||
|
||||
impl WrapMap {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn new(
|
||||
tab_snapshot: TabSnapshot,
|
||||
font: Font,
|
||||
@@ -131,6 +133,7 @@ impl WrapMap {
|
||||
self.background_task.is_some()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn sync(
|
||||
&mut self,
|
||||
tab_snapshot: TabSnapshot,
|
||||
@@ -150,6 +153,7 @@ impl WrapMap {
|
||||
(self.snapshot.clone(), mem::take(&mut self.edits_since_sync))
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn set_font_with_size(
|
||||
&mut self,
|
||||
font: Font,
|
||||
@@ -167,6 +171,7 @@ impl WrapMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn set_wrap_width(&mut self, wrap_width: Option<Pixels>, cx: &mut Context<Self>) -> bool {
|
||||
if wrap_width == self.wrap_width {
|
||||
return false;
|
||||
@@ -177,6 +182,7 @@ impl WrapMap {
|
||||
true
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn rewrap(&mut self, cx: &mut Context<Self>) {
|
||||
self.background_task.take();
|
||||
self.interpolated_edits.clear();
|
||||
@@ -248,6 +254,7 @@ impl WrapMap {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn flush_edits(&mut self, cx: &mut Context<Self>) {
|
||||
if !self.snapshot.interpolated {
|
||||
let mut to_remove_len = 0;
|
||||
@@ -330,6 +337,7 @@ impl WrapMap {
|
||||
}
|
||||
|
||||
impl WrapSnapshot {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn new(tab_snapshot: TabSnapshot) -> Self {
|
||||
let mut transforms = SumTree::default();
|
||||
let extent = tab_snapshot.text_summary();
|
||||
@@ -343,10 +351,12 @@ impl WrapSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot {
|
||||
self.tab_snapshot.buffer_snapshot()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn interpolate(&mut self, new_tab_snapshot: TabSnapshot, tab_edits: &[TabEdit]) -> WrapPatch {
|
||||
let mut new_transforms;
|
||||
if tab_edits.is_empty() {
|
||||
@@ -411,6 +421,7 @@ impl WrapSnapshot {
|
||||
old_snapshot.compute_edits(tab_edits, self)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
async fn update(
|
||||
&mut self,
|
||||
new_tab_snapshot: TabSnapshot,
|
||||
@@ -570,6 +581,7 @@ impl WrapSnapshot {
|
||||
old_snapshot.compute_edits(tab_edits, self)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn compute_edits(&self, tab_edits: &[TabEdit], new_snapshot: &WrapSnapshot) -> WrapPatch {
|
||||
let mut wrap_edits = Vec::with_capacity(tab_edits.len());
|
||||
let mut old_cursor = self.transforms.cursor::<TransformSummary>(());
|
||||
@@ -606,6 +618,7 @@ impl WrapSnapshot {
|
||||
Patch::new(wrap_edits)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn chunks<'a>(
|
||||
&'a self,
|
||||
rows: Range<WrapRow>,
|
||||
@@ -640,10 +653,12 @@ impl WrapSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn max_point(&self) -> WrapPoint {
|
||||
WrapPoint(self.transforms.summary().output.lines)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn line_len(&self, row: WrapRow) -> u32 {
|
||||
let (start, _, item) = self.transforms.find::<Dimensions<WrapPoint, TabPoint>, _>(
|
||||
(),
|
||||
@@ -664,6 +679,7 @@ impl WrapSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all, fields(rows))]
|
||||
pub fn text_summary_for_range(&self, rows: Range<WrapRow>) -> TextSummary {
|
||||
let mut summary = TextSummary::default();
|
||||
|
||||
@@ -725,6 +741,7 @@ impl WrapSnapshot {
|
||||
summary
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn soft_wrap_indent(&self, row: WrapRow) -> Option<u32> {
|
||||
let (.., item) = self.transforms.find::<WrapPoint, _>(
|
||||
(),
|
||||
@@ -740,10 +757,12 @@ impl WrapSnapshot {
|
||||
})
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn longest_row(&self) -> u32 {
|
||||
self.transforms.summary().output.longest_row
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn row_infos(&self, start_row: WrapRow) -> WrapRows<'_> {
|
||||
let mut transforms = self
|
||||
.transforms
|
||||
@@ -766,6 +785,7 @@ impl WrapSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_tab_point(&self, point: WrapPoint) -> TabPoint {
|
||||
let (start, _, item) =
|
||||
self.transforms
|
||||
@@ -777,15 +797,18 @@ impl WrapSnapshot {
|
||||
TabPoint(tab_point)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn to_point(&self, point: WrapPoint, bias: Bias) -> Point {
|
||||
self.tab_snapshot
|
||||
.tab_point_to_point(self.to_tab_point(point), bias)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn make_wrap_point(&self, point: Point, bias: Bias) -> WrapPoint {
|
||||
self.tab_point_to_wrap_point(self.tab_snapshot.point_to_tab_point(point, bias))
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn tab_point_to_wrap_point(&self, point: TabPoint) -> WrapPoint {
|
||||
let (start, ..) =
|
||||
self.transforms
|
||||
@@ -793,6 +816,7 @@ impl WrapSnapshot {
|
||||
WrapPoint(start.1.0 + (point.0 - start.0.0))
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn wrap_point_cursor(&self) -> WrapPointCursor<'_> {
|
||||
WrapPointCursor {
|
||||
cursor: self
|
||||
@@ -801,6 +825,7 @@ impl WrapSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn clip_point(&self, mut point: WrapPoint, bias: Bias) -> WrapPoint {
|
||||
if bias == Bias::Left {
|
||||
let (start, _, item) = self
|
||||
@@ -815,6 +840,7 @@ impl WrapSnapshot {
|
||||
self.tab_point_to_wrap_point(self.tab_snapshot.clip_point(self.to_tab_point(point), bias))
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all, fields(point, ret))]
|
||||
pub fn prev_row_boundary(&self, mut point: WrapPoint) -> WrapRow {
|
||||
if self.transforms.is_empty() {
|
||||
return WrapRow(0);
|
||||
@@ -841,6 +867,7 @@ impl WrapSnapshot {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn next_row_boundary(&self, mut point: WrapPoint) -> Option<WrapRow> {
|
||||
point.0 += Point::new(1, 0);
|
||||
|
||||
@@ -860,11 +887,13 @@ impl WrapSnapshot {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text(&self) -> String {
|
||||
self.text_chunks(WrapRow(0)).collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn text_chunks(&self, wrap_row: WrapRow) -> impl Iterator<Item = &str> {
|
||||
self.chunks(
|
||||
wrap_row..self.max_point().row() + WrapRow(1),
|
||||
@@ -874,6 +903,7 @@ impl WrapSnapshot {
|
||||
.map(|h| h.text)
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn check_invariants(&self) {
|
||||
#[cfg(test)]
|
||||
{
|
||||
@@ -927,6 +957,7 @@ pub struct WrapPointCursor<'transforms> {
|
||||
}
|
||||
|
||||
impl WrapPointCursor<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub fn map(&mut self, point: TabPoint) -> WrapPoint {
|
||||
let cursor = &mut self.cursor;
|
||||
if cursor.did_seek() {
|
||||
@@ -939,6 +970,7 @@ impl WrapPointCursor<'_> {
|
||||
}
|
||||
|
||||
impl WrapChunks<'_> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
pub(crate) fn seek(&mut self, rows: Range<WrapRow>) {
|
||||
let output_start = WrapPoint::new(rows.start, 0);
|
||||
let output_end = WrapPoint::new(rows.end, 0);
|
||||
@@ -961,6 +993,7 @@ impl WrapChunks<'_> {
|
||||
impl<'a> Iterator for WrapChunks<'a> {
|
||||
type Item = Chunk<'a>;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.output_position.row() >= self.max_output_row {
|
||||
return None;
|
||||
@@ -1033,6 +1066,7 @@ impl<'a> Iterator for WrapChunks<'a> {
|
||||
impl Iterator for WrapRows<'_> {
|
||||
type Item = RowInfo;
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.output_row > self.max_output_row {
|
||||
return None;
|
||||
@@ -1069,6 +1103,7 @@ impl Iterator for WrapRows<'_> {
|
||||
}
|
||||
|
||||
impl Transform {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn isomorphic(summary: TextSummary) -> Self {
|
||||
#[cfg(test)]
|
||||
assert!(!summary.lines.is_zero());
|
||||
@@ -1082,6 +1117,7 @@ impl Transform {
|
||||
}
|
||||
}
|
||||
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn wrap(indent: u32) -> Self {
|
||||
static WRAP_TEXT: LazyLock<String> = LazyLock::new(|| {
|
||||
let mut wrap_text = String::new();
|
||||
@@ -1134,6 +1170,7 @@ trait SumTreeExt {
|
||||
}
|
||||
|
||||
impl SumTreeExt for SumTree<Transform> {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn push_or_extend(&mut self, transform: Transform) {
|
||||
let mut transform = Some(transform);
|
||||
self.update_last(
|
||||
@@ -1197,6 +1234,7 @@ impl<'a> sum_tree::Dimension<'a, TransformSummary> for TabPoint {
|
||||
}
|
||||
|
||||
impl sum_tree::SeekTarget<'_, TransformSummary, TransformSummary> for TabPoint {
|
||||
#[ztracing::instrument(skip_all)]
|
||||
fn cmp(&self, cursor_location: &TransformSummary, _: ()) -> std::cmp::Ordering {
|
||||
Ord::cmp(&self.0, &cursor_location.input.lines)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user