Finished refactoring out fs and rope

This commit is contained in:
Mikayla Maki 2022-10-11 15:25:54 -07:00
parent 0a8e2f6bb0
commit 0beb97547e
58 changed files with 328 additions and 223 deletions

View file

@ -11,7 +11,8 @@ use gpui::{
fonts::{FontId, HighlightStyle},
Entity, ModelContext, ModelHandle,
};
use language::{OffsetUtf16, Point, Subscription as BufferSubscription};
use language::Subscription as BufferSubscription;
use rope::{offset_utf16::OffsetUtf16, point::Point};
use settings::Settings;
use std::{any::TypeId, fmt::Debug, num::NonZeroU32, ops::Range, sync::Arc};
use sum_tree::{Bias, TreeMap};
@ -565,7 +566,7 @@ pub mod tests {
use super::*;
use crate::{movement, test::marked_display_snapshot};
use gpui::{color::Color, elements::*, test::observe, MutableAppContext};
use language::{Buffer, Language, LanguageConfig, RandomCharIter, SelectionGoal};
use language::{Buffer, Language, LanguageConfig, SelectionGoal};
use rand::{prelude::*, Rng};
use smol::stream::StreamExt;
use std::{env, sync::Arc};
@ -609,7 +610,9 @@ pub mod tests {
let buffer = cx.update(|cx| {
if rng.gen() {
let len = rng.gen_range(0..10);
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
let text = util::RandomCharIter::new(&mut rng)
.take(len)
.collect::<String>();
MultiBuffer::build_simple(&text, cx)
} else {
MultiBuffer::build_random(&mut rng, cx)

View file

@ -7,6 +7,7 @@ use collections::{Bound, HashMap, HashSet};
use gpui::{ElementBox, RenderContext};
use language::{BufferSnapshot, Chunk, Patch};
use parking_lot::Mutex;
use rope::point::Point;
use std::{
cell::RefCell,
cmp::{self, Ordering},
@ -18,7 +19,7 @@ use std::{
},
};
use sum_tree::{Bias, SumTree};
use text::{Edit, Point};
use text::Edit;
const NEWLINES: &[u8] = &[b'\n'; u8::MAX as usize];
@ -42,7 +43,7 @@ pub struct BlockSnapshot {
pub struct BlockId(usize);
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct BlockPoint(pub super::Point);
pub struct BlockPoint(pub Point);
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
struct BlockRow(u32);
@ -994,7 +995,7 @@ mod tests {
use rand::prelude::*;
use settings::Settings;
use std::env;
use text::RandomCharIter;
use util::RandomCharIter;
#[gpui::test]
fn test_offset_for_row() {

View file

@ -5,8 +5,9 @@ use crate::{
};
use collections::BTreeMap;
use gpui::fonts::HighlightStyle;
use language::{Chunk, Edit, Point, TextSummary};
use language::{Chunk, Edit, TextSummary};
use parking_lot::Mutex;
use rope::point::Point;
use std::{
any::TypeId,
cmp::{self, Ordering},
@ -18,11 +19,11 @@ use std::{
use sum_tree::{Bias, Cursor, FilterCursor, SumTree};
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct FoldPoint(pub super::Point);
pub struct FoldPoint(pub Point);
impl FoldPoint {
pub fn new(row: u32, column: u32) -> Self {
Self(super::Point::new(row, column))
Self(Point::new(row, column))
}
pub fn row(self) -> u32 {
@ -1196,8 +1197,8 @@ mod tests {
use settings::Settings;
use std::{cmp::Reverse, env, mem, sync::Arc};
use sum_tree::TreeMap;
use text::RandomCharIter;
use util::test::sample_text;
use util::RandomCharIter;
use Bias::{Left, Right};
#[gpui::test]

View file

@ -3,11 +3,12 @@ use super::{
TextHighlights,
};
use crate::MultiBufferSnapshot;
use language::{rope, Chunk};
use language::Chunk;
use parking_lot::Mutex;
use rope;
use rope::point::Point;
use std::{cmp, mem, num::NonZeroU32, ops::Range};
use sum_tree::Bias;
use text::Point;
pub struct TabMap(Mutex<TabSnapshot>);
@ -332,11 +333,11 @@ impl TabSnapshot {
}
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct TabPoint(pub super::Point);
pub struct TabPoint(pub Point);
impl TabPoint {
pub fn new(row: u32, column: u32) -> Self {
Self(super::Point::new(row, column))
Self(Point::new(row, column))
}
pub fn zero() -> Self {
@ -352,8 +353,8 @@ impl TabPoint {
}
}
impl From<super::Point> for TabPoint {
fn from(point: super::Point) -> Self {
impl From<Point> for TabPoint {
fn from(point: Point) -> Self {
Self(point)
}
}
@ -362,7 +363,7 @@ pub type TabEdit = text::Edit<TabPoint>;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct TextSummary {
pub lines: super::Point,
pub lines: Point,
pub first_line_chars: u32,
pub last_line_chars: u32,
pub longest_row: u32,
@ -485,7 +486,6 @@ mod tests {
use super::*;
use crate::{display_map::fold_map::FoldMap, MultiBuffer};
use rand::{prelude::StdRng, Rng};
use text::{RandomCharIter, Rope};
#[test]
fn test_expand_tabs() {
@ -508,7 +508,9 @@ mod tests {
let tab_size = NonZeroU32::new(rng.gen_range(1..=4)).unwrap();
let len = rng.gen_range(0..30);
let buffer = if rng.gen() {
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
let text = util::RandomCharIter::new(&mut rng)
.take(len)
.collect::<String>();
MultiBuffer::build_simple(&text, cx)
} else {
MultiBuffer::build_random(&mut rng, cx)
@ -522,7 +524,7 @@ mod tests {
log::info!("FoldMap text: {:?}", folds_snapshot.text());
let (_, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), tab_size);
let text = Rope::from(tabs_snapshot.text().as_str());
let text = rope::Rope::from(tabs_snapshot.text().as_str());
log::info!(
"TabMap text (tab size: {}): {:?}",
tab_size,

View file

@ -3,13 +3,14 @@ use super::{
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
TextHighlights,
};
use crate::{MultiBufferSnapshot, Point};
use crate::MultiBufferSnapshot;
use gpui::{
fonts::FontId, text_layout::LineWrapper, Entity, ModelContext, ModelHandle, MutableAppContext,
Task,
};
use language::Chunk;
use lazy_static::lazy_static;
use rope::point::Point;
use smol::future::yield_now;
use std::{cmp, collections::VecDeque, mem, ops::Range, time::Duration};
use sum_tree::{Bias, Cursor, SumTree};
@ -52,7 +53,7 @@ struct TransformSummary {
}
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct WrapPoint(pub super::Point);
pub struct WrapPoint(pub Point);
pub struct WrapChunks<'a> {
input_chunks: tab_map::TabChunks<'a>,
@ -959,7 +960,7 @@ impl SumTreeExt for SumTree<Transform> {
impl WrapPoint {
pub fn new(row: u32, column: u32) -> Self {
Self(super::Point::new(row, column))
Self(Point::new(row, column))
}
pub fn row(self) -> u32 {
@ -1029,7 +1030,6 @@ mod tests {
MultiBuffer,
};
use gpui::test::observe;
use language::RandomCharIter;
use rand::prelude::*;
use settings::Settings;
use smol::stream::StreamExt;
@ -1067,7 +1067,9 @@ mod tests {
MultiBuffer::build_random(&mut rng, cx)
} else {
let len = rng.gen_range(0..10);
let text = RandomCharIter::new(&mut rng).take(len).collect::<String>();
let text = util::RandomCharIter::new(&mut rng)
.take(len)
.collect::<String>();
MultiBuffer::build_simple(&text, cx)
}
});

View file

@ -43,8 +43,8 @@ pub use items::MAX_TAB_TITLE_LEN;
pub use language::{char_kind, CharKind};
use language::{
AutoindentMode, BracketPair, Buffer, CodeAction, CodeLabel, Completion, Diagnostic,
DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, OffsetUtf16, Point,
Selection, SelectionGoal, TransactionId,
DiagnosticSeverity, IndentKind, IndentSize, Language, OffsetRangeExt, Selection, SelectionGoal,
TransactionId,
};
use link_go_to_definition::{hide_link_definition, LinkGoToDefinitionState};
pub use multi_buffer::{
@ -54,6 +54,7 @@ pub use multi_buffer::{
use multi_buffer::{MultiBufferChunks, ToOffsetUtf16};
use ordered_float::OrderedFloat;
use project::{FormatTrigger, LocationLink, Project, ProjectPath, ProjectTransaction};
use rope::{offset_utf16::OffsetUtf16, point::Point};
use selections_collection::{resolve_multiple, MutableSelectionsCollection, SelectionsCollection};
use serde::{Deserialize, Serialize};
use settings::Settings;

View file

@ -11,9 +11,9 @@ use gpui::{
use indoc::indoc;
use language::{FakeLspAdapter, LanguageConfig, LanguageRegistry};
use project::FakeFs;
use rope::point::Point;
use settings::EditorSettings;
use std::{cell::RefCell, rc::Rc, time::Instant};
use text::Point;
use unindent::Unindent;
use util::{
assert_set_eq,

View file

@ -35,8 +35,9 @@ use gpui::{
WeakViewHandle,
};
use json::json;
use language::{Bias, DiagnosticSeverity, OffsetUtf16, Selection};
use language::{Bias, DiagnosticSeverity, Selection};
use project::ProjectPath;
use rope::offset_utf16::OffsetUtf16;
use settings::{GitGutter, Settings};
use smallvec::SmallVec;
use std::{

View file

@ -11,6 +11,7 @@ use gpui::{
};
use language::{Bias, Buffer, File as _, OffsetRangeExt, SelectionGoal};
use project::{File, FormatTrigger, Project, ProjectEntryId, ProjectPath};
use rope::point::Point;
use rpc::proto::{self, update_view};
use settings::Settings;
use smallvec::SmallVec;
@ -21,7 +22,7 @@ use std::{
ops::Range,
path::{Path, PathBuf},
};
use text::{Point, Selection};
use text::Selection;
use util::TryFutureExt;
use workspace::{
searchable::{Direction, SearchEvent, SearchableItem, SearchableItemHandle},

View file

@ -1,6 +1,7 @@
use rope::point::Point;
use super::{Bias, DisplayPoint, DisplaySnapshot, SelectionGoal, ToDisplayPoint};
use crate::{char_kind, CharKind, ToPoint};
use language::Point;
use std::ops::Range;
pub fn left(map: &DisplaySnapshot, mut point: DisplayPoint) -> DisplayPoint {
@ -273,7 +274,7 @@ pub fn surrounding_word(map: &DisplaySnapshot, position: DisplayPoint) -> Range<
mod tests {
use super::*;
use crate::{test::marked_display_snapshot, Buffer, DisplayMap, ExcerptRange, MultiBuffer};
use language::Point;
use rope::point::Point;
use settings::Settings;
#[gpui::test]

View file

@ -12,6 +12,7 @@ use language::{
DiagnosticEntry, Event, File, IndentSize, Language, OffsetRangeExt, Outline, OutlineItem,
Selection, ToOffset as _, ToOffsetUtf16 as _, ToPoint as _, ToPointUtf16 as _, TransactionId,
};
use rope::{offset_utf16::OffsetUtf16, point::Point, point_utf16::PointUtf16, TextDimension};
use smallvec::SmallVec;
use std::{
borrow::Cow,
@ -27,9 +28,8 @@ use std::{
use sum_tree::{Bias, Cursor, SumTree};
use text::{
locator::Locator,
rope::TextDimension,
subscription::{Subscription, Topic},
Edit, OffsetUtf16, Point, PointUtf16, TextSummary,
Edit, TextSummary,
};
use theme::SyntaxTheme;
use util::post_inc;
@ -168,7 +168,7 @@ struct ExcerptChunks<'a> {
}
struct ExcerptBytes<'a> {
content_bytes: language::rope::Bytes<'a>,
content_bytes: rope::Bytes<'a>,
footer_height: usize,
}
@ -1412,7 +1412,7 @@ impl MultiBuffer {
edit_count: usize,
cx: &mut ModelContext<Self>,
) {
use text::RandomCharIter;
use util::RandomCharIter;
let snapshot = self.read(cx);
let mut edits: Vec<(Range<usize>, Arc<str>)> = Vec::new();
@ -1451,7 +1451,7 @@ impl MultiBuffer {
) {
use rand::prelude::*;
use std::env;
use text::RandomCharIter;
use util::RandomCharIter;
let max_excerpts = env::var("MAX_EXCERPTS")
.map(|i| i.parse().expect("invalid `MAX_EXCERPTS` variable"))
@ -3337,7 +3337,7 @@ mod tests {
use rand::prelude::*;
use settings::Settings;
use std::{env, rc::Rc};
use text::{Point, RandomCharIter};
use util::test::sample_text;
#[gpui::test]
@ -3955,7 +3955,9 @@ mod tests {
}
_ => {
let buffer_handle = if buffers.is_empty() || rng.gen_bool(0.4) {
let base_text = RandomCharIter::new(&mut rng).take(10).collect::<String>();
let base_text = util::RandomCharIter::new(&mut rng)
.take(10)
.collect::<String>();
buffers.push(cx.add_model(|cx| Buffer::new(0, base_text, cx)));
buffers.last().unwrap()
} else {

View file

@ -1,10 +1,10 @@
use super::{ExcerptId, MultiBufferSnapshot, ToOffset, ToOffsetUtf16, ToPoint};
use rope::{offset_utf16::OffsetUtf16, point::Point, TextDimension};
use std::{
cmp::Ordering,
ops::{Range, Sub},
};
use sum_tree::Bias;
use text::{rope::TextDimension, OffsetUtf16, Point};
#[derive(Clone, Eq, PartialEq, Debug, Hash)]
pub struct Anchor {

View file

@ -8,7 +8,8 @@ use std::{
use collections::HashMap;
use gpui::{AppContext, ModelHandle, MutableAppContext};
use itertools::Itertools;
use language::{rope::TextDimension, Bias, Point, Selection, SelectionGoal, ToPoint};
use language::{Bias, Selection, SelectionGoal, ToPoint};
use rope::{point::Point, TextDimension};
use util::post_inc;
use crate::{