Compare commits

...

2 Commits

Author SHA1 Message Date
Antonio Scandurra
11de59e20e WIP 2024-09-17 12:41:51 -06:00
Antonio Scandurra
9c9bb2eb6c Start on multi_buffer2 2024-09-17 12:10:44 -06:00
6 changed files with 7031 additions and 0 deletions

26
Cargo.lock generated
View File

@@ -7005,6 +7005,32 @@ dependencies = [
"util",
]
[[package]]
name = "multi_buffer2"
version = "0.1.0"
dependencies = [
"anyhow",
"clock",
"collections",
"ctor",
"env_logger",
"futures 0.3.30",
"git",
"gpui",
"itertools 0.13.0",
"language",
"log",
"parking_lot",
"rand 0.8.5",
"serde",
"settings",
"smallvec",
"sum_tree",
"text",
"theme",
"util",
]
[[package]]
name = "multimap"
version = "0.8.3"

View File

@@ -65,6 +65,7 @@ members = [
"crates/media",
"crates/menu",
"crates/multi_buffer",
"crates/multi_buffer2",
"crates/node_runtime",
"crates/notifications",
"crates/ollama",

View File

@@ -0,0 +1,51 @@
[package]
name = "multi_buffer2"
version = "0.1.0"
edition = "2021"
publish = false
license = "GPL-3.0-or-later"
[lints]
workspace = true
[lib]
path = "src/multi_buffer2.rs"
doctest = false
[features]
test-support = [
"text/test-support",
"language/test-support",
"gpui/test-support",
"util/test-support",
]
[dependencies]
anyhow.workspace = true
clock.workspace = true
collections.workspace = true
ctor.workspace = true
env_logger.workspace = true
futures.workspace = true
git.workspace = true
gpui.workspace = true
itertools.workspace = true
language.workspace = true
log.workspace = true
parking_lot.workspace = true
rand.workspace = true
settings.workspace = true
serde.workspace = true
smallvec.workspace = true
sum_tree.workspace = true
text.workspace = true
theme.workspace = true
util.workspace = true
[dev-dependencies]
gpui = { workspace = true, features = ["test-support"] }
language = { workspace = true, features = ["test-support"] }
rand.workspace = true
settings = { workspace = true, features = ["test-support"] }
text = { workspace = true, features = ["test-support"] }
util = { workspace = true, features = ["test-support"] }

View File

@@ -0,0 +1 @@
../../LICENSE-GPL

View File

@@ -0,0 +1,138 @@
use super::{MultiBufferSnapshot, ToOffset, ToOffsetUtf16, ToPoint};
use language::{OffsetUtf16, Point, TextDimension};
use std::{
cmp::Ordering,
ops::{Range, Sub},
};
use sum_tree::Bias;
#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash)]
pub struct Anchor(pub text::Anchor);
impl Anchor {
pub fn min() -> Self {
Self(text::Anchor::MIN)
}
pub fn max() -> Self {
Self(text::Anchor::MAX)
}
pub fn cmp(&self, other: &Anchor, snapshot: &MultiBufferSnapshot) -> Ordering {
todo!()
// let excerpt_id_cmp = self.excerpt_id.cmp(&other.excerpt_id, snapshot);
// if excerpt_id_cmp.is_eq() {
// if self.excerpt_id == ExcerptId::min() || self.excerpt_id == ExcerptId::max() {
// Ordering::Equal
// } else if let Some(excerpt) = snapshot.excerpt(self.excerpt_id) {
// self.text_anchor.cmp(&other.text_anchor, &excerpt.buffer)
// } else {
// Ordering::Equal
// }
// } else {
// excerpt_id_cmp
// }
}
pub fn bias(&self) -> Bias {
self.0.bias
}
pub fn bias_left(&self, snapshot: &MultiBufferSnapshot) -> Anchor {
if self.0.bias != Bias::Left {
todo!()
// if let Some(excerpt) = snapshot.excerpt(self.excerpt_id) {
// return Self {
// buffer_id: self.buffer_id,
// excerpt_id: self.excerpt_id,
// text_anchor: self.text_anchor.bias_left(&excerpt.buffer),
// };
// }
}
*self
}
pub fn bias_right(&self, snapshot: &MultiBufferSnapshot) -> Anchor {
if self.0.bias != Bias::Right {
todo!()
// if let Some(excerpt) = snapshot.excerpt(self.excerpt_id) {
// return Self {
// buffer_id: self.buffer_id,
// excerpt_id: self.excerpt_id,
// text_anchor: self.text_anchor.bias_right(&excerpt.buffer),
// };
// }
}
*self
}
pub fn summary<D>(&self, snapshot: &MultiBufferSnapshot) -> D
where
D: TextDimension + Ord + Sub<D, Output = D>,
{
snapshot.summary_for_anchor(self)
}
pub fn is_valid(&self, snapshot: &MultiBufferSnapshot) -> bool {
todo!()
// if *self == Anchor::min() || *self == Anchor::max() {
// true
// } else if let Some(excerpt) = snapshot.excerpt(self.excerpt_id) {
// excerpt.contains(self)
// && (self.text_anchor == excerpt.range.context.start
// || self.text_anchor == excerpt.range.context.end
// || self.text_anchor.is_valid(&excerpt.buffer))
// } else {
// false
// }
}
}
impl ToOffset for Anchor {
fn to_offset(&self, snapshot: &MultiBufferSnapshot) -> usize {
self.summary(snapshot)
}
}
impl ToOffsetUtf16 for Anchor {
fn to_offset_utf16(&self, snapshot: &MultiBufferSnapshot) -> OffsetUtf16 {
self.summary(snapshot)
}
}
impl ToPoint for Anchor {
fn to_point<'a>(&self, snapshot: &MultiBufferSnapshot) -> Point {
self.summary(snapshot)
}
}
pub trait AnchorRangeExt {
fn cmp(&self, b: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> Ordering;
fn overlaps(&self, b: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> bool;
fn to_offset(&self, content: &MultiBufferSnapshot) -> Range<usize>;
fn to_point(&self, content: &MultiBufferSnapshot) -> Range<Point>;
}
impl AnchorRangeExt for Range<Anchor> {
fn cmp(&self, other: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> Ordering {
match self.start.cmp(&other.start, buffer) {
Ordering::Equal => other.end.cmp(&self.end, buffer),
ord => ord,
}
}
fn overlaps(&self, other: &Range<Anchor>, buffer: &MultiBufferSnapshot) -> bool {
self.end.cmp(&other.start, buffer).is_ge() && self.start.cmp(&other.end, buffer).is_le()
}
fn to_offset(&self, content: &MultiBufferSnapshot) -> Range<usize> {
self.start.to_offset(content)..self.end.to_offset(content)
}
fn to_point(&self, content: &MultiBufferSnapshot) -> Range<Point> {
self.start.to_point(content)..self.end.to_point(content)
}
}
#[derive(Clone, Copy, Eq, PartialEq, Debug, Hash, Ord, PartialOrd)]
pub struct Offset(pub usize);

File diff suppressed because it is too large Load Diff