mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-12 13:24:19 +00:00
WIP: Move sum_tree module into gpui so we can use it in List
This commit is contained in:
parent
2507f9b4d4
commit
c3dda14490
16 changed files with 190 additions and 138 deletions
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -162,6 +162,12 @@ version = "0.5.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arrayvec"
|
||||||
|
version = "0.7.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be4dc07131ffa69b8072d35f5007352af944213cde02545e2103680baed38fcd"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ascii"
|
name = "ascii"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
|
@ -626,7 +632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
|
checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec",
|
"arrayvec 0.5.2",
|
||||||
"constant_time_eq",
|
"constant_time_eq",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -637,7 +643,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3"
|
checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec",
|
"arrayvec 0.5.2",
|
||||||
"cc",
|
"cc",
|
||||||
"cfg-if 0.1.10",
|
"cfg-if 0.1.10",
|
||||||
"constant_time_eq",
|
"constant_time_eq",
|
||||||
|
@ -2145,6 +2151,7 @@ name = "gpui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"arrayvec 0.7.1",
|
||||||
"async-task",
|
"async-task",
|
||||||
"backtrace",
|
"backtrace",
|
||||||
"bindgen",
|
"bindgen",
|
||||||
|
@ -2632,7 +2639,7 @@ version = "0.8.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e30b1df631d23875f230ed3ddd1a88c231f269a04b2044eb6ca87e763b5f4c42"
|
checksum = "e30b1df631d23875f230ed3ddd1a88c231f269a04b2044eb6ca87e763b5f4c42"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec 0.5.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2665,7 +2672,7 @@ version = "0.7.6"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
|
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec 0.5.2",
|
||||||
"bitflags 1.2.1",
|
"bitflags 1.2.1",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"ryu",
|
"ryu",
|
||||||
|
@ -5164,7 +5171,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1bf81f2900d2e235220e6f31ec9f63ade6a7f59090c556d74fe949bb3b15e9fe"
|
checksum = "1bf81f2900d2e235220e6f31ec9f63ade6a7f59090c556d74fe949bb3b15e9fe"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"arrayvec",
|
"arrayvec 0.5.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"png 0.16.8",
|
"png 0.16.8",
|
||||||
|
@ -5792,7 +5799,7 @@ name = "zed"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"arrayvec",
|
"arrayvec 0.7.1",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
"cargo-bundle",
|
"cargo-bundle",
|
||||||
|
|
|
@ -5,6 +5,7 @@ name = "gpui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
arrayvec = "0.7.1"
|
||||||
async-task = "4.0.3"
|
async-task = "4.0.3"
|
||||||
backtrace = "0.3"
|
backtrace = "0.3"
|
||||||
ctor = "0.1"
|
ctor = "0.1"
|
||||||
|
|
|
@ -7,6 +7,7 @@ mod event_handler;
|
||||||
mod flex;
|
mod flex;
|
||||||
mod label;
|
mod label;
|
||||||
mod line_box;
|
mod line_box;
|
||||||
|
mod list;
|
||||||
mod mouse_event_handler;
|
mod mouse_event_handler;
|
||||||
mod stack;
|
mod stack;
|
||||||
mod svg;
|
mod svg;
|
||||||
|
@ -22,6 +23,7 @@ pub use event_handler::*;
|
||||||
pub use flex::*;
|
pub use flex::*;
|
||||||
pub use label::*;
|
pub use label::*;
|
||||||
pub use line_box::*;
|
pub use line_box::*;
|
||||||
|
pub use list::*;
|
||||||
pub use mouse_event_handler::*;
|
pub use mouse_event_handler::*;
|
||||||
pub use stack::*;
|
pub use stack::*;
|
||||||
pub use svg::*;
|
pub use svg::*;
|
||||||
|
|
45
gpui/src/elements/list.rs
Normal file
45
gpui/src/elements/list.rs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
use crate::sum_tree::{self, SumTree};
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crate::ElementBox;
|
||||||
|
|
||||||
|
pub struct List {
|
||||||
|
state: ListState,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ListState(Arc<Mutex<StateInner>>);
|
||||||
|
|
||||||
|
struct StateInner {
|
||||||
|
elements: Vec<ElementBox>,
|
||||||
|
element_heights: SumTree<ElementHeight>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
enum ElementHeight {
|
||||||
|
Pending,
|
||||||
|
Ready(f32),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Default)]
|
||||||
|
struct ElementHeightSummary {
|
||||||
|
pending_count: usize,
|
||||||
|
height: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sum_tree::Item for ElementHeight {
|
||||||
|
type Summary = ElementHeightSummary;
|
||||||
|
|
||||||
|
fn summary(&self) -> Self::Summary {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sum_tree::Summary for ElementHeightSummary {
|
||||||
|
type Context = ();
|
||||||
|
|
||||||
|
fn add_summary(&mut self, summary: &Self, cx: &Self::Context) {
|
||||||
|
self.pending_count += summary.pending_count;
|
||||||
|
self.height += summary.height;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
mod app;
|
mod app;
|
||||||
pub use app::*;
|
pub use app::*;
|
||||||
mod assets;
|
mod assets;
|
||||||
|
pub mod sum_tree;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
pub use assets::*;
|
pub use assets::*;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod cursor;
|
mod cursor;
|
||||||
|
|
||||||
use crate::util::Bias;
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
pub use cursor::Cursor;
|
pub use cursor::Cursor;
|
||||||
pub use cursor::FilterCursor;
|
pub use cursor::FilterCursor;
|
||||||
|
@ -47,6 +46,29 @@ impl<'a, S: Summary, T: Dimension<'a, S> + Ord> SeekDimension<'a, S> for T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
|
||||||
|
pub enum Bias {
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for Bias {
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for Bias {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
match (self, other) {
|
||||||
|
(Self::Left, Self::Left) => Ordering::Equal,
|
||||||
|
(Self::Left, Self::Right) => Ordering::Less,
|
||||||
|
(Self::Right, Self::Right) => Ordering::Equal,
|
||||||
|
(Self::Right, Self::Left) => Ordering::Greater,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct SumTree<T: Item>(Arc<Node<T>>);
|
pub struct SumTree<T: Item>(Arc<Node<T>>);
|
||||||
|
|
||||||
|
@ -253,8 +275,8 @@ impl<T: Item> SumTree<T> {
|
||||||
summary.add_summary(other_node.summary(), cx);
|
summary.add_summary(other_node.summary(), cx);
|
||||||
|
|
||||||
let height_delta = *height - other_node.height();
|
let height_delta = *height - other_node.height();
|
||||||
let mut summaries_to_append = ArrayVec::<[T::Summary; 2 * TREE_BASE]>::new();
|
let mut summaries_to_append = ArrayVec::<T::Summary, { 2 * TREE_BASE }>::new();
|
||||||
let mut trees_to_append = ArrayVec::<[SumTree<T>; 2 * TREE_BASE]>::new();
|
let mut trees_to_append = ArrayVec::<SumTree<T>, { 2 * TREE_BASE }>::new();
|
||||||
if height_delta == 0 {
|
if height_delta == 0 {
|
||||||
summaries_to_append.extend(other_node.child_summaries().iter().cloned());
|
summaries_to_append.extend(other_node.child_summaries().iter().cloned());
|
||||||
trees_to_append.extend(other_node.child_trees().iter().cloned());
|
trees_to_append.extend(other_node.child_trees().iter().cloned());
|
||||||
|
@ -277,8 +299,8 @@ impl<T: Item> SumTree<T> {
|
||||||
|
|
||||||
let child_count = child_trees.len() + trees_to_append.len();
|
let child_count = child_trees.len() + trees_to_append.len();
|
||||||
if child_count > 2 * TREE_BASE {
|
if child_count > 2 * TREE_BASE {
|
||||||
let left_summaries: ArrayVec<_>;
|
let left_summaries: ArrayVec<_, { 2 * TREE_BASE }>;
|
||||||
let right_summaries: ArrayVec<_>;
|
let right_summaries: ArrayVec<_, { 2 * TREE_BASE }>;
|
||||||
let left_trees;
|
let left_trees;
|
||||||
let right_trees;
|
let right_trees;
|
||||||
|
|
||||||
|
@ -323,7 +345,7 @@ impl<T: Item> SumTree<T> {
|
||||||
let left_items;
|
let left_items;
|
||||||
let right_items;
|
let right_items;
|
||||||
let left_summaries;
|
let left_summaries;
|
||||||
let right_summaries: ArrayVec<[T::Summary; 2 * TREE_BASE]>;
|
let right_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }>;
|
||||||
|
|
||||||
let midpoint = (child_count + child_count % 2) / 2;
|
let midpoint = (child_count + child_count % 2) / 2;
|
||||||
{
|
{
|
||||||
|
@ -491,13 +513,13 @@ pub enum Node<T: Item> {
|
||||||
Internal {
|
Internal {
|
||||||
height: u8,
|
height: u8,
|
||||||
summary: T::Summary,
|
summary: T::Summary,
|
||||||
child_summaries: ArrayVec<[T::Summary; 2 * TREE_BASE]>,
|
child_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }>,
|
||||||
child_trees: ArrayVec<[SumTree<T>; 2 * TREE_BASE]>,
|
child_trees: ArrayVec<SumTree<T>, { 2 * TREE_BASE }>,
|
||||||
},
|
},
|
||||||
Leaf {
|
Leaf {
|
||||||
summary: T::Summary,
|
summary: T::Summary,
|
||||||
items: ArrayVec<[T; 2 * TREE_BASE]>,
|
items: ArrayVec<T, { 2 * TREE_BASE }>,
|
||||||
item_summaries: ArrayVec<[T::Summary; 2 * TREE_BASE]>,
|
item_summaries: ArrayVec<T::Summary, { 2 * TREE_BASE }>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,14 +554,14 @@ impl<T: Item> Node<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child_trees(&self) -> &ArrayVec<[SumTree<T>; 2 * TREE_BASE]> {
|
fn child_trees(&self) -> &ArrayVec<SumTree<T>, { 2 * TREE_BASE }> {
|
||||||
match self {
|
match self {
|
||||||
Node::Internal { child_trees, .. } => child_trees,
|
Node::Internal { child_trees, .. } => child_trees,
|
||||||
Node::Leaf { .. } => panic!("Leaf nodes have no child trees"),
|
Node::Leaf { .. } => panic!("Leaf nodes have no child trees"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn items(&self) -> &ArrayVec<[T; 2 * TREE_BASE]> {
|
fn items(&self) -> &ArrayVec<T, { 2 * TREE_BASE }> {
|
||||||
match self {
|
match self {
|
||||||
Node::Leaf { items, .. } => items,
|
Node::Leaf { items, .. } => items,
|
||||||
Node::Internal { .. } => panic!("Internal nodes have no items"),
|
Node::Internal { .. } => panic!("Internal nodes have no items"),
|
||||||
|
@ -603,7 +625,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[gpui::test(iterations = 100)]
|
#[crate::test(self, iterations = 100)]
|
||||||
fn test_random(mut rng: StdRng) {
|
fn test_random(mut rng: StdRng) {
|
||||||
let rng = &mut rng;
|
let rng = &mut rng;
|
||||||
let mut tree = SumTree::<u8>::new();
|
let mut tree = SumTree::<u8>::new();
|
|
@ -13,7 +13,7 @@ struct StackEntry<'a, T: Item, S, U> {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Cursor<'a, T: Item, S, U> {
|
pub struct Cursor<'a, T: Item, S, U> {
|
||||||
tree: &'a SumTree<T>,
|
tree: &'a SumTree<T>,
|
||||||
stack: ArrayVec<[StackEntry<'a, T, S, U>; 16]>,
|
stack: ArrayVec<StackEntry<'a, T, S, U>, 16>,
|
||||||
seek_dimension: S,
|
seek_dimension: S,
|
||||||
sum_dimension: U,
|
sum_dimension: U,
|
||||||
did_seek: bool,
|
did_seek: bool,
|
||||||
|
@ -495,8 +495,8 @@ where
|
||||||
ref item_summaries,
|
ref item_summaries,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut slice_items = ArrayVec::<[T; 2 * TREE_BASE]>::new();
|
let mut slice_items = ArrayVec::<T, { 2 * TREE_BASE }>::new();
|
||||||
let mut slice_item_summaries = ArrayVec::<[T::Summary; 2 * TREE_BASE]>::new();
|
let mut slice_item_summaries = ArrayVec::<T::Summary, { 2 * TREE_BASE }>::new();
|
||||||
let mut slice_items_summary = match aggregate {
|
let mut slice_items_summary = match aggregate {
|
||||||
SeekAggregate::Slice(_) => Some(T::Summary::default()),
|
SeekAggregate::Slice(_) => Some(T::Summary::default()),
|
||||||
_ => None,
|
_ => None,
|
|
@ -18,8 +18,8 @@ test-support = ["tempdir", "zrpc/test-support"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
arrayvec = "0.5.2"
|
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
arrayvec = "0.7.1"
|
||||||
async-tungstenite = { version = "0.14", features = ["async-tls"] }
|
async-tungstenite = { version = "0.14", features = ["async-tls"] }
|
||||||
crossbeam-channel = "0.5.0"
|
crossbeam-channel = "0.5.0"
|
||||||
ctor = "0.1.20"
|
ctor = "0.1.20"
|
||||||
|
|
|
@ -1,30 +1,30 @@
|
||||||
mod anchor;
|
mod anchor;
|
||||||
|
mod operation_queue;
|
||||||
mod point;
|
mod point;
|
||||||
pub mod rope;
|
pub mod rope;
|
||||||
mod selection;
|
mod selection;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
language::{Language, Tree},
|
||||||
|
settings::{HighlightId, HighlightMap},
|
||||||
|
time::{self, ReplicaId},
|
||||||
|
util::Bias,
|
||||||
|
worktree::{File, Worktree},
|
||||||
|
};
|
||||||
pub use anchor::*;
|
pub use anchor::*;
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
|
use gpui::{
|
||||||
|
sum_tree::{self, FilterCursor, SumTree},
|
||||||
|
AppContext, Entity, ModelContext, ModelHandle, Task,
|
||||||
|
};
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
use operation_queue::OperationQueue;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
pub use point::*;
|
pub use point::*;
|
||||||
pub use rope::{Chunks, Rope, TextSummary};
|
pub use rope::{Chunks, Rope, TextSummary};
|
||||||
use seahash::SeaHasher;
|
use seahash::SeaHasher;
|
||||||
pub use selection::*;
|
pub use selection::*;
|
||||||
use similar::{ChangeTag, TextDiff};
|
use similar::{ChangeTag, TextDiff};
|
||||||
use tree_sitter::{InputEdit, Parser, QueryCursor};
|
|
||||||
use zrpc::proto;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
language::{Language, Tree},
|
|
||||||
operation_queue::{self, OperationQueue},
|
|
||||||
settings::{HighlightId, HighlightMap},
|
|
||||||
sum_tree::{self, FilterCursor, SumTree},
|
|
||||||
time::{self, ReplicaId},
|
|
||||||
util::Bias,
|
|
||||||
worktree::{File, Worktree},
|
|
||||||
};
|
|
||||||
use anyhow::{anyhow, Result};
|
|
||||||
use gpui::{AppContext, Entity, ModelContext, ModelHandle, Task};
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use std::{
|
use std::{
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
cmp,
|
cmp,
|
||||||
|
@ -37,6 +37,8 @@ use std::{
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
||||||
};
|
};
|
||||||
|
use tree_sitter::{InputEdit, Parser, QueryCursor};
|
||||||
|
use zrpc::proto;
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
struct DeterministicState;
|
struct DeterministicState;
|
||||||
|
@ -120,7 +122,7 @@ pub struct Buffer {
|
||||||
syntax_tree: Mutex<Option<SyntaxTree>>,
|
syntax_tree: Mutex<Option<SyntaxTree>>,
|
||||||
is_parsing: bool,
|
is_parsing: bool,
|
||||||
selections: HashMap<SelectionSetId, SelectionSet>,
|
selections: HashMap<SelectionSetId, SelectionSet>,
|
||||||
deferred_ops: OperationQueue<Operation>,
|
deferred_ops: OperationQueue,
|
||||||
deferred_replicas: HashSet<ReplicaId>,
|
deferred_replicas: HashSet<ReplicaId>,
|
||||||
replica_id: ReplicaId,
|
replica_id: ReplicaId,
|
||||||
remote_id: u64,
|
remote_id: u64,
|
||||||
|
@ -483,6 +485,8 @@ pub enum Operation {
|
||||||
set_id: Option<SelectionSetId>,
|
set_id: Option<SelectionSetId>,
|
||||||
lamport_timestamp: time::Lamport,
|
lamport_timestamp: time::Lamport,
|
||||||
},
|
},
|
||||||
|
#[cfg(test)]
|
||||||
|
Test(time::Lamport),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
|
@ -1390,6 +1394,8 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
self.lamport_clock.observe(lamport_timestamp);
|
self.lamport_clock.observe(lamport_timestamp);
|
||||||
}
|
}
|
||||||
|
#[cfg(test)]
|
||||||
|
Operation::Test(_) => {}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1731,6 +1737,8 @@ impl Buffer {
|
||||||
Operation::SetActiveSelections { set_id, .. } => {
|
Operation::SetActiveSelections { set_id, .. } => {
|
||||||
set_id.map_or(true, |set_id| self.selections.contains_key(&set_id))
|
set_id.map_or(true, |set_id| self.selections.contains_key(&set_id))
|
||||||
}
|
}
|
||||||
|
#[cfg(test)]
|
||||||
|
Operation::Test(_) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2564,6 +2572,8 @@ impl Operation {
|
||||||
Operation::SetActiveSelections {
|
Operation::SetActiveSelections {
|
||||||
lamport_timestamp, ..
|
lamport_timestamp, ..
|
||||||
} => *lamport_timestamp,
|
} => *lamport_timestamp,
|
||||||
|
#[cfg(test)]
|
||||||
|
Operation::Test(lamport_timestamp) => *lamport_timestamp,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2630,6 +2640,8 @@ impl<'a> Into<proto::Operation> for &'a Operation {
|
||||||
lamport_timestamp: lamport_timestamp.value,
|
lamport_timestamp: lamport_timestamp.value,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
#[cfg(test)]
|
||||||
|
Operation::Test(_) => unimplemented!()
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2834,12 +2846,6 @@ impl TryFrom<proto::Selection> for Selection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl operation_queue::Operation for Operation {
|
|
||||||
fn timestamp(&self) -> time::Lamport {
|
|
||||||
self.lamport_timestamp()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait ToOffset {
|
pub trait ToOffset {
|
||||||
fn to_offset<'a>(&self, content: impl Into<Content<'a>>) -> usize;
|
fn to_offset<'a>(&self, content: impl Into<Content<'a>>) -> usize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,27 @@
|
||||||
use crate::{
|
use super::Operation;
|
||||||
sum_tree::{Cursor, Dimension, Edit, Item, KeyedItem, SumTree, Summary},
|
use crate::time;
|
||||||
time,
|
use gpui::sum_tree::{Cursor, Dimension, Edit, Item, KeyedItem, SumTree, Summary};
|
||||||
};
|
|
||||||
use std::{fmt::Debug, ops::Add};
|
use std::{fmt::Debug, ops::Add};
|
||||||
|
|
||||||
pub trait Operation: Clone + Debug + Eq {
|
|
||||||
fn timestamp(&self) -> time::Lamport;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct OperationQueue<T: Operation>(SumTree<T>);
|
pub struct OperationQueue(SumTree<Operation>);
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
|
#[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd)]
|
||||||
pub struct OperationKey(time::Lamport);
|
pub struct OperationKey(time::Lamport);
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||||
pub struct OperationSummary {
|
pub struct OperationSummary {
|
||||||
key: OperationKey,
|
pub key: OperationKey,
|
||||||
len: usize,
|
pub len: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Operation> OperationQueue<T> {
|
impl OperationKey {
|
||||||
|
pub fn new(timestamp: time::Lamport) -> Self {
|
||||||
|
Self(timestamp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OperationQueue {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
OperationQueue(SumTree::new())
|
OperationQueue(SumTree::new())
|
||||||
}
|
}
|
||||||
|
@ -29,9 +30,9 @@ impl<T: Operation> OperationQueue<T> {
|
||||||
self.0.summary().len
|
self.0.summary().len
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert(&mut self, mut ops: Vec<T>) {
|
pub fn insert(&mut self, mut ops: Vec<Operation>) {
|
||||||
ops.sort_by_key(|op| op.timestamp());
|
ops.sort_by_key(|op| op.lamport_timestamp());
|
||||||
ops.dedup_by_key(|op| op.timestamp());
|
ops.dedup_by_key(|op| op.lamport_timestamp());
|
||||||
self.0
|
self.0
|
||||||
.edit(ops.into_iter().map(Edit::Insert).collect(), &());
|
.edit(ops.into_iter().map(Edit::Insert).collect(), &());
|
||||||
}
|
}
|
||||||
|
@ -42,30 +43,11 @@ impl<T: Operation> OperationQueue<T> {
|
||||||
clone
|
clone
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cursor(&self) -> Cursor<T, (), ()> {
|
pub fn cursor(&self) -> Cursor<Operation, (), ()> {
|
||||||
self.0.cursor()
|
self.0.cursor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Operation> Item for T {
|
|
||||||
type Summary = OperationSummary;
|
|
||||||
|
|
||||||
fn summary(&self) -> Self::Summary {
|
|
||||||
OperationSummary {
|
|
||||||
key: OperationKey(self.timestamp()),
|
|
||||||
len: 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: Operation> KeyedItem for T {
|
|
||||||
type Key = OperationKey;
|
|
||||||
|
|
||||||
fn key(&self) -> Self::Key {
|
|
||||||
OperationKey(self.timestamp())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Summary for OperationSummary {
|
impl Summary for OperationSummary {
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
||||||
|
@ -95,6 +77,25 @@ impl<'a> Dimension<'a, OperationSummary> for OperationKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Item for Operation {
|
||||||
|
type Summary = OperationSummary;
|
||||||
|
|
||||||
|
fn summary(&self) -> Self::Summary {
|
||||||
|
OperationSummary {
|
||||||
|
key: OperationKey::new(self.lamport_timestamp()),
|
||||||
|
len: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl KeyedItem for Operation {
|
||||||
|
type Key = OperationKey;
|
||||||
|
|
||||||
|
fn key(&self) -> Self::Key {
|
||||||
|
OperationKey::new(self.lamport_timestamp())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -107,27 +108,21 @@ mod tests {
|
||||||
assert_eq!(queue.len(), 0);
|
assert_eq!(queue.len(), 0);
|
||||||
|
|
||||||
queue.insert(vec![
|
queue.insert(vec![
|
||||||
TestOperation(clock.tick()),
|
Operation::Test(clock.tick()),
|
||||||
TestOperation(clock.tick()),
|
Operation::Test(clock.tick()),
|
||||||
]);
|
]);
|
||||||
assert_eq!(queue.len(), 2);
|
assert_eq!(queue.len(), 2);
|
||||||
|
|
||||||
queue.insert(vec![TestOperation(clock.tick())]);
|
queue.insert(vec![Operation::Test(clock.tick())]);
|
||||||
assert_eq!(queue.len(), 3);
|
assert_eq!(queue.len(), 3);
|
||||||
|
|
||||||
drop(queue.drain());
|
drop(queue.drain());
|
||||||
assert_eq!(queue.len(), 0);
|
assert_eq!(queue.len(), 0);
|
||||||
|
|
||||||
queue.insert(vec![TestOperation(clock.tick())]);
|
queue.insert(vec![Operation::Test(clock.tick())]);
|
||||||
assert_eq!(queue.len(), 1);
|
assert_eq!(queue.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
struct TestOperation(time::Lamport);
|
struct TestOperation(time::Lamport);
|
||||||
|
|
||||||
impl Operation for TestOperation {
|
|
||||||
fn timestamp(&self) -> time::Lamport {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,9 +1,7 @@
|
||||||
use super::Point;
|
use super::Point;
|
||||||
use crate::{
|
use crate::util::Bias;
|
||||||
sum_tree::{self, SumTree},
|
|
||||||
util::Bias,
|
|
||||||
};
|
|
||||||
use arrayvec::ArrayString;
|
use arrayvec::ArrayString;
|
||||||
|
use gpui::sum_tree::{self, SumTree};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::{cmp, ops::Range, str};
|
use std::{cmp, ops::Range, str};
|
||||||
|
|
||||||
|
@ -61,7 +59,7 @@ impl Rope {
|
||||||
if last_chunk.0.len() + first_new_chunk_ref.0.len() <= 2 * CHUNK_BASE {
|
if last_chunk.0.len() + first_new_chunk_ref.0.len() <= 2 * CHUNK_BASE {
|
||||||
last_chunk.0.push_str(&first_new_chunk.take().unwrap().0);
|
last_chunk.0.push_str(&first_new_chunk.take().unwrap().0);
|
||||||
} else {
|
} else {
|
||||||
let mut text = ArrayString::<[_; 4 * CHUNK_BASE]>::new();
|
let mut text = ArrayString::<{ 4 * CHUNK_BASE }>::new();
|
||||||
text.push_str(&last_chunk.0);
|
text.push_str(&last_chunk.0);
|
||||||
text.push_str(&first_new_chunk_ref.0);
|
text.push_str(&first_new_chunk_ref.0);
|
||||||
let (left, right) = text.split_at(find_split_ix(&text));
|
let (left, right) = text.split_at(find_split_ix(&text));
|
||||||
|
@ -330,7 +328,7 @@ impl<'a> Iterator for Chunks<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
struct Chunk(ArrayString<[u8; 2 * CHUNK_BASE]>);
|
struct Chunk(ArrayString<{ 2 * CHUNK_BASE }>);
|
||||||
|
|
||||||
impl Chunk {
|
impl Chunk {
|
||||||
fn to_point(&self, target: usize) -> Point {
|
fn to_point(&self, target: usize) -> Point {
|
||||||
|
|
|
@ -2,14 +2,11 @@ use super::{
|
||||||
buffer::{AnchorRangeExt, TextSummary},
|
buffer::{AnchorRangeExt, TextSummary},
|
||||||
Anchor, Buffer, Point, ToOffset,
|
Anchor, Buffer, Point, ToOffset,
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{editor::buffer, settings::HighlightId, time, util::Bias};
|
||||||
editor::buffer,
|
use gpui::{
|
||||||
settings::HighlightId,
|
|
||||||
sum_tree::{self, Cursor, FilterCursor, SumTree},
|
sum_tree::{self, Cursor, FilterCursor, SumTree},
|
||||||
time,
|
AppContext, ModelHandle,
|
||||||
util::Bias,
|
|
||||||
};
|
};
|
||||||
use gpui::{AppContext, ModelHandle};
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::{
|
use std::{
|
||||||
cmp::{self, Ordering},
|
cmp::{self, Ordering},
|
||||||
|
|
|
@ -3,14 +3,11 @@ use super::{
|
||||||
line_wrapper::LineWrapper,
|
line_wrapper::LineWrapper,
|
||||||
tab_map::{self, Edit as TabEdit, Snapshot as TabSnapshot, TabPoint, TextSummary},
|
tab_map::{self, Edit as TabEdit, Snapshot as TabSnapshot, TabPoint, TextSummary},
|
||||||
};
|
};
|
||||||
use crate::{
|
use crate::{editor::Point, settings::HighlightId, util::Bias, Settings};
|
||||||
editor::Point,
|
use gpui::{
|
||||||
settings::HighlightId,
|
|
||||||
sum_tree::{self, Cursor, SumTree},
|
sum_tree::{self, Cursor, SumTree},
|
||||||
util::Bias,
|
Entity, ModelContext, Task,
|
||||||
Settings,
|
|
||||||
};
|
};
|
||||||
use gpui::{Entity, ModelContext, Task};
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use smol::future::yield_now;
|
use smol::future::yield_now;
|
||||||
use std::{collections::VecDeque, ops::Range, time::Duration};
|
use std::{collections::VecDeque, ops::Range, time::Duration};
|
||||||
|
@ -816,8 +813,12 @@ fn push_isomorphic(transforms: &mut Vec<Transform>, summary: TextSummary) {
|
||||||
transforms.push(Transform::isomorphic(summary));
|
transforms.push(Transform::isomorphic(summary));
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SumTree<Transform> {
|
trait SumTreeExt {
|
||||||
pub fn push_or_extend(&mut self, transform: Transform) {
|
fn push_or_extend(&mut self, transform: Transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SumTreeExt for SumTree<Transform> {
|
||||||
|
fn push_or_extend(&mut self, transform: Transform) {
|
||||||
let mut transform = Some(transform);
|
let mut transform = Some(transform);
|
||||||
self.update_last(
|
self.update_last(
|
||||||
|last_transform| {
|
|last_transform| {
|
||||||
|
|
|
@ -7,11 +7,9 @@ pub mod fs;
|
||||||
mod fuzzy;
|
mod fuzzy;
|
||||||
pub mod language;
|
pub mod language;
|
||||||
pub mod menus;
|
pub mod menus;
|
||||||
mod operation_queue;
|
|
||||||
pub mod project_browser;
|
pub mod project_browser;
|
||||||
pub mod rpc;
|
pub mod rpc;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
mod sum_tree;
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub mod test;
|
pub mod test;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
|
|
|
@ -1,30 +1,8 @@
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
pub use gpui::sum_tree::Bias;
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
|
|
||||||
pub enum Bias {
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialOrd for Bias {
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
||||||
Some(self.cmp(other))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ord for Bias {
|
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
|
||||||
match (self, other) {
|
|
||||||
(Self::Left, Self::Left) => Ordering::Equal,
|
|
||||||
(Self::Left, Self::Right) => Ordering::Less,
|
|
||||||
(Self::Right, Self::Right) => Ordering::Equal,
|
|
||||||
(Self::Right, Self::Left) => Ordering::Greater,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn post_inc(value: &mut usize) -> usize {
|
pub fn post_inc(value: &mut usize) -> usize {
|
||||||
let prev = *value;
|
let prev = *value;
|
||||||
*value += 1;
|
*value += 1;
|
||||||
|
|
|
@ -8,7 +8,6 @@ use crate::{
|
||||||
fuzzy::CharBag,
|
fuzzy::CharBag,
|
||||||
language::LanguageRegistry,
|
language::LanguageRegistry,
|
||||||
rpc::{self, proto},
|
rpc::{self, proto},
|
||||||
sum_tree::{self, Cursor, Edit, SumTree},
|
|
||||||
time::{self, ReplicaId},
|
time::{self, ReplicaId},
|
||||||
util::{log_async_errors, Bias},
|
util::{log_async_errors, Bias},
|
||||||
};
|
};
|
||||||
|
@ -17,8 +16,10 @@ use anyhow::{anyhow, Result};
|
||||||
use futures::{Stream, StreamExt};
|
use futures::{Stream, StreamExt};
|
||||||
pub use fuzzy::{match_paths, PathMatch};
|
pub use fuzzy::{match_paths, PathMatch};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
executor, AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext,
|
executor,
|
||||||
Task, UpgradeModelHandle, WeakModelHandle,
|
sum_tree::{self, Cursor, Edit, SumTree},
|
||||||
|
AppContext, AsyncAppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task,
|
||||||
|
UpgradeModelHandle, WeakModelHandle,
|
||||||
};
|
};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
|
Loading…
Reference in a new issue