Move multi_buffer to editor crate

This commit is contained in:
Nathan Sobo 2021-12-10 17:37:53 -07:00
parent 6caf016df9
commit c8b43e3078
16 changed files with 44 additions and 47 deletions

1
Cargo.lock generated
View file

@ -1527,6 +1527,7 @@ dependencies = [
"aho-corasick",
"anyhow",
"clock",
"collections",
"ctor",
"env_logger",
"gpui",

View file

@ -8,6 +8,7 @@ path = "src/editor.rs"
[features]
test-support = [
"rand",
"text/test-support",
"language/test-support",
"gpui/test-support",
@ -17,6 +18,7 @@ test-support = [
[dependencies]
text = { path = "../text" }
clock = { path = "../clock" }
collections = { path = "../collections" }
gpui = { path = "../gpui" }
language = { path = "../language" }
project = { path = "../project" }
@ -30,6 +32,7 @@ lazy_static = "1.4"
log = "0.4"
parking_lot = "0.11"
postage = { version = "0.4", features = ["futures-traits"] }
rand = { version = "0.8.3", optional = true }
serde = { version = "1", features = ["derive", "rc"] }
smallvec = { version = "1.6", features = ["union"] }
smol = "1.2"

View file

@ -3,13 +3,11 @@ mod fold_map;
mod tab_map;
mod wrap_map;
use crate::{Anchor, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};
use block_map::{BlockMap, BlockPoint};
use fold_map::{FoldMap, ToFoldPoint as _};
use gpui::{fonts::FontId, ElementBox, Entity, ModelContext, ModelHandle};
use language::{
multi_buffer::{Anchor, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint},
Point, Subscription as BufferSubscription,
};
use language::{Point, Subscription as BufferSubscription};
use std::{
collections::{HashMap, HashSet},
ops::Range,

View file

@ -1,9 +1,7 @@
use super::wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot};
use crate::{Anchor, ToOffset, ToPoint as _};
use gpui::{AppContext, ElementBox};
use language::{
multi_buffer::{Anchor, ToOffset, ToPoint as _},
Chunk,
};
use language::Chunk;
use parking_lot::Mutex;
use std::{
cmp::{self, Ordering},
@ -866,8 +864,8 @@ fn offset_for_row(s: &str, target: u32) -> (u32, usize) {
mod tests {
use super::*;
use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap};
use crate::multi_buffer::MultiBuffer;
use gpui::{elements::Empty, Element};
use language::multi_buffer::MultiBuffer;
use rand::prelude::*;
use std::env;
use text::RandomCharIter;

View file

@ -1,7 +1,5 @@
use language::{
multi_buffer::{Anchor, AnchorRangeExt, MultiBufferChunks, MultiBufferSnapshot, ToOffset},
Chunk, Edit, Point, PointUtf16, TextSummary,
};
use crate::{Anchor, AnchorRangeExt, MultiBufferChunks, MultiBufferSnapshot, ToOffset};
use language::{Chunk, Edit, Point, PointUtf16, TextSummary};
use parking_lot::Mutex;
use std::{
cmp::{self, Ordering},
@ -1057,8 +1055,7 @@ pub type FoldEdit = Edit<FoldOffset>;
#[cfg(test)]
mod tests {
use super::*;
use crate::ToPoint;
use language::multi_buffer::MultiBuffer;
use crate::{MultiBuffer, ToPoint};
use rand::prelude::*;
use std::{env, mem};
use text::RandomCharIter;

View file

@ -1,5 +1,6 @@
use super::fold_map::{self, FoldEdit, FoldPoint, FoldSnapshot, ToFoldPoint};
use language::{multi_buffer::MultiBufferSnapshot, rope, Chunk};
use crate::MultiBufferSnapshot;
use language::{rope, Chunk};
use parking_lot::Mutex;
use std::{cmp, mem, ops::Range};
use sum_tree::Bias;
@ -438,8 +439,7 @@ impl<'a> Iterator for TabChunks<'a> {
#[cfg(test)]
mod tests {
use super::*;
use crate::display_map::fold_map::FoldMap;
use language::multi_buffer::MultiBuffer;
use crate::{display_map::fold_map::FoldMap, MultiBuffer};
use rand::{prelude::StdRng, Rng};
use text::{RandomCharIter, Rope};

View file

@ -2,11 +2,12 @@ use super::{
fold_map,
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
};
use crate::{MultiBufferSnapshot, Point};
use gpui::{
fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, ModelHandle, MutableAppContext,
Task,
};
use language::{multi_buffer::MultiBufferSnapshot, Chunk, Point};
use language::Chunk;
use lazy_static::lazy_static;
use smol::future::yield_now;
use std::{collections::VecDeque, mem, ops::Range, time::Duration};
@ -977,8 +978,9 @@ mod tests {
use crate::{
display_map::{fold_map::FoldMap, tab_map::TabMap},
test::Observer,
MultiBuffer,
};
use language::{multi_buffer::MultiBuffer, RandomCharIter};
use language::RandomCharIter;
use rand::prelude::*;
use std::{cmp, env};
use text::Rope;

View file

@ -2,6 +2,7 @@ pub mod display_map;
mod element;
pub mod items;
pub mod movement;
mod multi_buffer;
#[cfg(test)]
mod test;
@ -21,12 +22,14 @@ use gpui::{
};
use items::BufferItemHandle;
use language::{
multi_buffer::{
Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, SelectionSet, ToOffset, ToPoint,
},
BracketPair, Buffer, Diagnostic, DiagnosticSeverity, Language, Point, Selection, SelectionGoal,
SelectionSetId,
};
use multi_buffer::{
Anchor, AnchorRangeExt, MultiBufferChunks, MultiBufferSnapshot,
SelectionSet, ToOffset, ToPoint,
};
pub use multi_buffer::MultiBuffer;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use smol::Timer;

View file

@ -4,6 +4,7 @@ use super::{
DisplayPoint, Editor, EditorMode, EditorSettings, EditorSnapshot, EditorStyle, Input, Scroll,
Select, SelectPhase, SoftWrap, MAX_LINE_LEN,
};
use crate::ToPoint;
use clock::ReplicaId;
use gpui::{
color::Color,
@ -19,7 +20,7 @@ use gpui::{
MutableAppContext, PaintContext, Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle,
};
use json::json;
use language::{multi_buffer::ToPoint, Chunk};
use language::Chunk;
use smallvec::SmallVec;
use std::{
cmp::{self, Ordering},
@ -1162,8 +1163,7 @@ fn scale_horizontal_mouse_autoscroll_delta(delta: f32) -> f32 {
#[cfg(test)]
mod tests {
use super::*;
use crate::{Editor, EditorSettings};
use language::{MultiBuffer};
use crate::{Editor, EditorSettings, MultiBuffer};
use util::test::sample_text;
#[gpui::test]

View file

@ -1,14 +1,12 @@
use crate::{Editor, EditorSettings, Event};
use crate::{MultiBuffer, ToPoint as _};
use anyhow::Result;
use gpui::{
elements::*, fonts::TextStyle, AppContext, Entity, ModelContext, ModelHandle,
MutableAppContext, RenderContext, Subscription, Task, View, ViewContext, ViewHandle,
WeakModelHandle,
};
use language::{
multi_buffer::{MultiBuffer, ToPoint as _},
Diagnostic, File as _,
};
use language::{Diagnostic, File as _};
use postage::watch;
use project::{ProjectPath, Worktree};
use std::fmt::Write;

View file

@ -1,6 +1,6 @@
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
use crate::ToPoint;
use anyhow::Result;
use language::multi_buffer::ToPoint;
use std::{cmp, ops::Range};
pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> Result<DisplayPoint> {
@ -244,8 +244,7 @@ fn char_kind(c: char) -> CharKind {
#[cfg(test)]
mod tests {
use super::*;
use crate::display_map::DisplayMap;
use language::MultiBuffer;
use crate::{DisplayMap, MultiBuffer};
#[gpui::test]
fn test_prev_next_word_boundary_multibyte(cx: &mut gpui::MutableAppContext) {

View file

@ -1,15 +1,15 @@
mod anchor;
mod selection;
use crate::{
buffer::{self, Buffer, Chunk, ToOffset as _, ToPoint as _},
BufferSnapshot, DiagnosticEntry, Event, File, Language,
};
pub use anchor::{Anchor, AnchorRangeExt};
use anyhow::Result;
use clock::ReplicaId;
use collections::HashMap;
use gpui::{AppContext, Entity, ModelContext, ModelHandle, MutableAppContext, Task};
use language::{
Buffer, BufferChunks, BufferSnapshot, Chunk, DiagnosticEntry, Event, File, Language,
ToOffset as _, ToPoint as _,
};
pub use selection::SelectionSet;
use std::{
cell::{Ref, RefCell},
@ -72,7 +72,7 @@ pub struct ExcerptProperties<'a, T> {
#[derive(Clone)]
struct Excerpt {
id: ExcerptId,
buffer: buffer::BufferSnapshot,
buffer: BufferSnapshot,
range: Range<text::Anchor>,
text_summary: TextSummary,
header_height: u8,
@ -90,7 +90,7 @@ pub struct MultiBufferChunks<'a> {
cursor: Cursor<'a, Excerpt, usize>,
header_height: u8,
has_trailing_newline: bool,
excerpt_chunks: Option<buffer::BufferChunks<'a>>,
excerpt_chunks: Option<BufferChunks<'a>>,
theme: Option<&'a SyntaxTheme>,
}
@ -394,7 +394,7 @@ impl MultiBuffer {
cx.subscribe(buffer, Self::on_buffer_event).detach();
let buffer = props.buffer.read(cx);
let range = buffer.anchor_before(props.range.start)..buffer.anchor_after(props.range.end);
let range = buffer.anchor_before(&props.range.start)..buffer.anchor_after(&props.range.end);
let mut snapshot = self.snapshot.borrow_mut();
let prev_id = snapshot.excerpts.last().map(|e| &e.id);
let id = ExcerptId::between(prev_id.unwrap_or(&ExcerptId::min()), &ExcerptId::max());
@ -565,7 +565,7 @@ impl MultiBuffer {
}
impl Entity for MultiBuffer {
type Event = super::Event;
type Event = language::Event;
}
impl MultiBufferSnapshot {
@ -1099,7 +1099,7 @@ impl MultiBufferSnapshot {
impl Excerpt {
fn new(
id: ExcerptId,
buffer: buffer::BufferSnapshot,
buffer: BufferSnapshot,
range: Range<text::Anchor>,
header_height: u8,
has_trailing_newline: bool,
@ -1357,8 +1357,8 @@ impl ToPoint for Point {
#[cfg(test)]
mod tests {
use super::*;
use crate::buffer::Buffer;
use gpui::MutableAppContext;
use language::Buffer;
use rand::prelude::*;
use std::env;
use text::{Point, RandomCharIter};

View file

@ -1,7 +1,6 @@
mod buffer;
mod diagnostic_set;
mod highlight_map;
pub mod multi_buffer;
pub mod proto;
#[cfg(test)]
mod tests;
@ -14,7 +13,6 @@ use gpui::{executor::Background, AppContext};
use highlight_map::HighlightMap;
use lazy_static::lazy_static;
use lsp::LanguageServer;
pub use multi_buffer::MultiBuffer;
use parking_lot::Mutex;
use serde::Deserialize;
use std::{collections::HashSet, path::Path, str, sync::Arc};

View file

@ -944,11 +944,11 @@ mod tests {
EstablishConnectionError, UserStore,
},
contacts_panel::JoinWorktree,
editor::{Editor, EditorSettings, Input},
editor::{Editor, EditorSettings, Input, MultiBuffer},
fs::{FakeFs, Fs as _},
language::{
tree_sitter_rust, Diagnostic, DiagnosticEntry, Language, LanguageConfig,
LanguageRegistry, LanguageServerConfig, MultiBuffer, Point,
LanguageRegistry, LanguageServerConfig, Point,
},
lsp,
project::{ProjectPath, Worktree},