Release Notes: - N/A *or* Added/Fixed/Improved ... ---------
Showing the changes to crates/buffer_diff/src/buffer_diff.rs (1 of 12 files). Show all
Unified · Split
| @@ -30,7 +30,7 @@ pub struct BufferDiff { · 29 unmodified lines | ||
| 30 | 30 | #[derive(Clone)] |
| 31 | 31 | pub struct BufferDiffSnapshot { |
| 32 | 32 | inner: BufferDiffInner<language::BufferSnapshot>, |
| 33 | − secondary_diff: Option<Box<BufferDiffSnapshot>>, | |
| 33 | + secondary_diff: Option<Arc<BufferDiffSnapshot>>, | |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | impl std::fmt::Debug for BufferDiffSnapshot { |
| @@ -222,11 +222,11 @@ impl std::fmt::Debug for BufferDiffInner<language::BufferSnapshot> { · 185 unmodified lines | ||
| 222 | 222 | impl BufferDiffSnapshot { |
| 223 | 223 | #[cfg(test)] |
| 224 | 224 | fn new_sync( |
| 225 | − buffer: text::BufferSnapshot, | |
| 225 | + buffer: &text::BufferSnapshot, | |
| 226 | 226 | diff_base: String, |
| 227 | 227 | cx: &mut gpui::TestAppContext, |
| 228 | 228 | ) -> BufferDiffSnapshot { |
| 229 | − let buffer_diff = cx.new(|cx| BufferDiff::new_with_base_text(&diff_base, &buffer, cx)); | |
| 229 | + let buffer_diff = cx.new(|cx| BufferDiff::new_with_base_text(&diff_base, buffer, cx)); | |
| 230 | 230 | buffer_diff.update(cx, |buffer_diff, cx| buffer_diff.snapshot(cx)) |
| 231 | 231 | } |
| 232 | 232 | |
| @@ -950,10 +950,10 @@ fn build_diff_options( · 717 unmodified lines | ||
| 950 | 950 | |
| 951 | 951 | fn compute_hunks( |
| 952 | 952 | diff_base: Option<(Arc<str>, Rope)>, |
| 953 | − buffer: text::BufferSnapshot, | |
| 953 | + buffer: &text::BufferSnapshot, | |
| 954 | 954 | diff_options: Option<DiffOptions>, |
| 955 | 955 | ) -> SumTree<InternalDiffHunk> { |
| 956 | − let mut tree = SumTree::new(&buffer); | |
| 956 | + let mut tree = SumTree::new(buffer); | |
| 957 | 957 | |
| 958 | 958 | if let Some((diff_base, diff_base_rope)) = diff_base { |
| 959 | 959 | let buffer_text = buffer.as_rope().to_string(); |
| @@ -980,7 +980,7 @@ fn compute_hunks( · 20 unmodified lines | ||
| 980 | 980 | base_word_diffs: Vec::default(), |
| 981 | 981 | buffer_word_diffs: Vec::default(), |
| 982 | 982 | }, |
| 983 | − &buffer, | |
| 983 | + buffer, | |
| 984 | 984 | ); |
| 985 | 985 | return tree; |
| 986 | 986 | } |
| @@ -992,11 +992,11 @@ fn compute_hunks( · 5 unmodified lines | ||
| 992 | 992 | &patch, |
| 993 | 993 | hunk_index, |
| 994 | 994 | &diff_base_rope, |
| 995 | − &buffer, | |
| 995 | + buffer, | |
| 996 | 996 | &mut divergence, |
| 997 | 997 | diff_options.as_ref(), |
| 998 | 998 | ); |
| 999 | − tree.push(hunk, &buffer); | |
| 999 | + tree.push(hunk, buffer); | |
| 1000 | 1000 | } |
| 1001 | 1001 | } |
| 1002 | 1002 | } else { |
| @@ -1007,7 +1007,7 @@ fn compute_hunks( · 4 unmodified lines | ||
| 1007 | 1007 | base_word_diffs: Vec::default(), |
| 1008 | 1008 | buffer_word_diffs: Vec::default(), |
| 1009 | 1009 | }, |
| 1010 | − &buffer, | |
| 1010 | + buffer, | |
| 1011 | 1011 | ); |
| 1012 | 1012 | } |
| 1013 | 1013 | |
| @@ -1544,7 +1544,7 @@ impl BufferDiff { · 530 unmodified lines | ||
| 1544 | 1544 | base_text |
| 1545 | 1545 | .clone() |
| 1546 | 1546 | .map(|base_text| (base_text, base_text_rope.clone())), |
| 1547 | − buffer.clone(), | |
| 1547 | + &buffer, | |
| 1548 | 1548 | diff_options, |
| 1549 | 1549 | ); |
| 1550 | 1550 | let base_text = base_text.unwrap_or_default(); |
| @@ -1785,10 +1785,10 @@ impl BufferDiff { · 234 unmodified lines | ||
| 1785 | 1785 | base_text_exists: self.inner.base_text_exists, |
| 1786 | 1786 | buffer_snapshot: self.inner.buffer_snapshot.clone(), |
| 1787 | 1787 | }, |
| 1788 | − secondary_diff: self | |
| 1789 | − .secondary_diff | |
| 1790 | − .as_ref() | |
| 1791 | − .map(|diff| Box::new(diff.read(cx).snapshot(cx))), | |
| 1788 | + secondary_diff: self.secondary_diff.as_ref().map(|diff| { | |
| 1789 | + debug_assert!(diff.read(cx).secondary_diff.is_none()); | |
| 1790 | + Arc::new(diff.read(cx).snapshot(cx)) | |
| 1791 | + }), | |
| 1792 | 1792 | } |
| 1793 | 1793 | } |
| 1794 | 1794 | |
| @@ -2018,7 +2018,7 @@ mod tests { · 223 unmodified lines | ||
| 2018 | 2018 | .unindent(); |
| 2019 | 2019 | |
| 2020 | 2020 | let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text); |
| 2021 | − let mut diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx); | |
| 2021 | + let mut diff = BufferDiffSnapshot::new_sync(&buffer, diff_base.clone(), cx); | |
| 2022 | 2022 | assert_hunks( |
| 2023 | 2023 | diff.hunks_intersecting_range( |
| 2024 | 2024 | Anchor::min_max_range_for_buffer(buffer.remote_id()), |
| @@ -2030,7 +2030,7 @@ mod tests { · 5 unmodified lines | ||
| 2030 | 2030 | ); |
| 2031 | 2031 | |
| 2032 | 2032 | buffer.edit([(0..0, "point five\n")]); |
| 2033 | − diff = BufferDiffSnapshot::new_sync(buffer.clone(), diff_base.clone(), cx); | |
| 2033 | + diff = BufferDiffSnapshot::new_sync(&buffer, diff_base.clone(), cx); | |
| 2034 | 2034 | assert_hunks( |
| 2035 | 2035 | diff.hunks_intersecting_range( |
| 2036 | 2036 | Anchor::min_max_range_for_buffer(buffer.remote_id()), |
| @@ -2101,10 +2101,9 @@ mod tests { · 64 unmodified lines | ||
| 2101 | 2101 | .unindent(); |
| 2102 | 2102 | |
| 2103 | 2103 | let buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text); |
| 2104 | − let unstaged_diff = BufferDiffSnapshot::new_sync(buffer.clone(), index_text, cx); | |
| 2105 | − let mut uncommitted_diff = | |
| 2106 | − BufferDiffSnapshot::new_sync(buffer.clone(), head_text.clone(), cx); | |
| 2107 | − uncommitted_diff.secondary_diff = Some(Box::new(unstaged_diff)); | |
| 2104 | + let unstaged_diff = BufferDiffSnapshot::new_sync(&buffer, index_text, cx); | |
| 2105 | + let mut uncommitted_diff = BufferDiffSnapshot::new_sync(&buffer, head_text.clone(), cx); | |
| 2106 | + uncommitted_diff.secondary_diff = Some(Arc::new(unstaged_diff)); | |
| 2108 | 2107 | |
| 2109 | 2108 | let expected_hunks = vec![ |
| 2110 | 2109 | (2..3, "two\n", "TWO\n", DiffHunkStatus::modified_none()), |
| @@ -2631,7 +2630,7 @@ mod tests { · 520 unmodified lines | ||
| 2631 | 2630 | let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text_1); |
| 2632 | 2631 | |
| 2633 | 2632 | let empty_diff = cx.update(|cx| BufferDiff::new(&buffer, cx).snapshot(cx)); |
| 2634 | − let diff_1 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); | |
| 2633 | + let diff_1 = BufferDiffSnapshot::new_sync(&buffer, base_text.clone(), cx); | |
| 2635 | 2634 | let DiffChanged { |
| 2636 | 2635 | changed_range, |
| 2637 | 2636 | base_text_changed_range, |
| @@ -2666,7 +2665,7 @@ mod tests { · 28 unmodified lines | ||
| 2666 | 2665 | " |
| 2667 | 2666 | .unindent(), |
| 2668 | 2667 | ); |
| 2669 | − let diff_2 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); | |
| 2668 | + let diff_2 = BufferDiffSnapshot::new_sync(&buffer, base_text.clone(), cx); | |
| 2670 | 2669 | let DiffChanged { |
| 2671 | 2670 | changed_range, |
| 2672 | 2671 | base_text_changed_range, |
| @@ -2704,7 +2703,7 @@ mod tests { · 31 unmodified lines | ||
| 2704 | 2703 | " |
| 2705 | 2704 | .unindent(), |
| 2706 | 2705 | ); |
| 2707 | − let diff_3 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); | |
| 2706 | + let diff_3 = BufferDiffSnapshot::new_sync(&buffer, base_text.clone(), cx); | |
| 2708 | 2707 | let DiffChanged { |
| 2709 | 2708 | changed_range, |
| 2710 | 2709 | base_text_changed_range, |
| @@ -2738,7 +2737,7 @@ mod tests { · 27 unmodified lines | ||
| 2738 | 2737 | " |
| 2739 | 2738 | .unindent(), |
| 2740 | 2739 | ); |
| 2741 | − let diff_4 = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); | |
| 2740 | + let diff_4 = BufferDiffSnapshot::new_sync(&buffer, base_text.clone(), cx); | |
| 2742 | 2741 | let DiffChanged { |
| 2743 | 2742 | changed_range, |
| 2744 | 2743 | base_text_changed_range, |
| @@ -3172,11 +3171,11 @@ mod tests { · 427 unmodified lines | ||
| 3172 | 3171 | .unindent(); |
| 3173 | 3172 | |
| 3174 | 3173 | let mut buffer = Buffer::new(ReplicaId::LOCAL, BufferId::new(1).unwrap(), buffer_text); |
| 3175 | − let old_buffer = buffer.snapshot(); | |
| 3176 | − let diff_a = BufferDiffSnapshot::new_sync(buffer.clone(), base_text.clone(), cx); | |
| 3174 | + let old_buffer = buffer.snapshot().clone(); | |
| 3175 | + let diff_a = BufferDiffSnapshot::new_sync(&buffer, base_text.clone(), cx); | |
| 3177 | 3176 | |
| 3178 | 3177 | buffer.edit([(Point::new(1, 3)..Point::new(1, 3), "\n")]); |
| 3179 | − let diff_b = BufferDiffSnapshot::new_sync(buffer.clone(), base_text, cx); | |
| 3178 | + let diff_b = BufferDiffSnapshot::new_sync(&buffer, base_text, cx); | |
| 3180 | 3179 | |
| 3181 | 3180 | let DiffChanged { |
| 3182 | 3181 | changed_range, |
| @@ -3235,11 +3234,11 @@ mod tests { · 52 unmodified lines | ||
| 3235 | 3234 | .unindent(); |
| 3236 | 3235 | |
| 3237 | 3236 | let mut buffer_2 = Buffer::new(ReplicaId::LOCAL, BufferId::new(2).unwrap(), buffer_text_2); |
| 3238 | − let old_buffer_2 = buffer_2.snapshot(); | |
| 3239 | − let diff_2a = BufferDiffSnapshot::new_sync(buffer_2.clone(), base_text_2.clone(), cx); | |
| 3237 | + let old_buffer_2 = buffer_2.snapshot().clone(); | |
| 3238 | + let diff_2a = BufferDiffSnapshot::new_sync(&buffer_2, base_text_2.clone(), cx); | |
| 3240 | 3239 | |
| 3241 | 3240 | buffer_2.edit([(Point::new(4, 0)..Point::new(4, 4), "FIVE_CHANGED")]); |
| 3242 | − let diff_2b = BufferDiffSnapshot::new_sync(buffer_2.clone(), base_text_2, cx); | |
| 3241 | + let diff_2b = BufferDiffSnapshot::new_sync(&buffer_2, base_text_2, cx); | |
| 3243 | 3242 | |
| 3244 | 3243 | let DiffChanged { |
| 3245 | 3244 | changed_range, |
| @@ -3293,7 +3292,7 @@ mod tests { · 47 unmodified lines | ||
| 3293 | 3292 | buffer_text_1.to_string(), |
| 3294 | 3293 | ); |
| 3295 | 3294 | |
| 3296 | − let old_base_snapshot_1 = base_text_buffer.snapshot(); | |
| 3295 | + let old_base_snapshot_1 = base_text_buffer.snapshot().clone(); | |
| 3297 | 3296 | let old_hunks_1 = compute_hunks( |
| 3298 | 3297 | Some((Arc::from(initial_base), Rope::from(initial_base))), |
| 3299 | 3298 | buffer.snapshot(), |
| @@ -3352,7 +3351,7 @@ mod tests { · 52 unmodified lines | ||
| 3352 | 3351 | buffer_text_2.to_string(), |
| 3353 | 3352 | ); |
| 3354 | 3353 | |
| 3355 | − let old_base_snapshot_2 = base_buf_2.snapshot(); | |
| 3354 | + let old_base_snapshot_2 = base_buf_2.snapshot().clone(); | |
| 3356 | 3355 | let old_hunks_2 = compute_hunks( |
| 3357 | 3356 | Some((Arc::from(simple_base), Rope::from(simple_base))), |
| 3358 | 3357 | buffer_2.snapshot(), |
| @@ -3419,7 +3418,7 @@ mod tests { · 60 unmodified lines | ||
| 3419 | 3418 | buffer_text_3.to_string(), |
| 3420 | 3419 | ); |
| 3421 | 3420 | |
| 3422 | − let old_base_snapshot_3 = base_buf_3.snapshot(); | |
| 3421 | + let old_base_snapshot_3 = base_buf_3.snapshot().clone(); | |
| 3423 | 3422 | let old_hunks_3 = compute_hunks( |
| 3424 | 3423 | Some((Arc::from(base_3), Rope::from(base_3))), |
| 3425 | 3424 | buffer_3.snapshot(), |
| @@ -3485,8 +3484,8 @@ mod tests { · 59 unmodified lines | ||
| 3485 | 3484 | buffer_text_4.to_string(), |
| 3486 | 3485 | ); |
| 3487 | 3486 | |
| 3488 | − let old_base_snapshot_4 = base_buf_4.snapshot(); | |
| 3489 | − let old_buffer_snapshot_4 = buffer_4.snapshot(); | |
| 3487 | + let old_base_snapshot_4 = base_buf_4.snapshot().clone(); | |
| 3488 | + let old_buffer_snapshot_4 = buffer_4.snapshot().clone(); | |
| 3490 | 3489 | let old_hunks_4 = compute_hunks( |
| 3491 | 3490 | Some((Arc::from(base_4), Rope::from(base_4))), |
| 3492 | 3491 | buffer_4.snapshot(), |