From 32d3074bbb88cf77664ea6a71d62df923eaa2c96 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Mon, 23 Sep 2024 16:21:44 -0600 Subject: [PATCH] WIP --- crates/multi_buffer2/src/multi_buffer2.rs | 40 +++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/multi_buffer2/src/multi_buffer2.rs b/crates/multi_buffer2/src/multi_buffer2.rs index 79ebc9cda0..4ff226f289 100644 --- a/crates/multi_buffer2/src/multi_buffer2.rs +++ b/crates/multi_buffer2/src/multi_buffer2.rs @@ -1,4 +1,5 @@ -use language::{Bias, BufferSnapshot, ReplicaId}; +use gpui::{Context, Model}; +use language::{Buffer, BufferSnapshot, ReplicaId}; use std::{ fmt::{self, Debug, Formatter}, ops::Range, @@ -6,7 +7,7 @@ use std::{ }; use sum_tree::{SumTree, TreeMap}; -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] struct BufferId { remote_id: text::BufferId, replica_id: ReplicaId, @@ -16,6 +17,22 @@ pub struct MultiBuffer { snapshot: MultiBufferSnapshot, } +impl MultiBuffer { + pub fn new() -> Self { + Self { + snapshot: MultiBufferSnapshot::default(), + } + } + + pub fn insert_excerpts( + &mut self, + new_excerpts: impl IntoIterator, Range)>, + ) { + let mut new_excerpts = new_excerpts.into_iter().collect::>(); + } +} + +#[derive(Default)] pub struct MultiBufferSnapshot { excerpts: SumTree, snapshots: TreeMap, @@ -68,3 +85,22 @@ impl sum_tree::Summary for ExcerptSummary { self.max_key = summary.max_key.clone(); } } + +#[cfg(test)] +mod tests { + use super::*; + use gpui::AppContext; + use language::Buffer; + + #[gpui::test] + fn test_insert_excerpts(cx: &mut AppContext) { + let buffer1 = cx.new_model(|cx| Buffer::local("abc\ndef\nghi", cx)); + let buffer2 = cx.new_model(|cx| Buffer::local("jkl\nmno\npqr", cx)); + + let multi = cx.new_model(|cx| { + let mut multi = MultiBuffer::new(); + multi.insert_excerpts(vec![(buffer1.clone(), 0..4), (buffer2.clone(), 8..11)]); + multi + }); + } +}