Get tests passing and project diagnostics view working w/ new excerpt headers

This commit is contained in:
Max Brunsfeld
2022-02-09 13:51:52 -08:00
parent 3d9c39d0eb
commit 5b4c0d64bc
6 changed files with 160 additions and 122 deletions
+12 -8
View File
@@ -43,6 +43,7 @@ impl DisplayMap {
font_id: FontId,
font_size: f32,
wrap_width: Option<f32>,
buffer_header_height: u8,
excerpt_header_height: u8,
cx: &mut ModelContext<Self>,
) -> Self {
@@ -50,7 +51,7 @@ impl DisplayMap {
let (fold_map, snapshot) = FoldMap::new(buffer.read(cx).snapshot(cx));
let (tab_map, snapshot) = TabMap::new(snapshot, tab_size);
let (wrap_map, snapshot) = WrapMap::new(snapshot, font_id, font_size, wrap_width, cx);
let block_map = BlockMap::new(snapshot, excerpt_header_height);
let block_map = BlockMap::new(snapshot, buffer_header_height, excerpt_header_height);
cx.observe(&wrap_map, |_, _, cx| cx.notify()).detach();
DisplayMap {
buffer,
@@ -472,6 +473,7 @@ mod tests {
let font_cache = cx.font_cache().clone();
let tab_size = rng.gen_range(1..=4);
let buffer_start_excerpt_header_height = rng.gen_range(1..=5);
let excerpt_header_height = rng.gen_range(1..=5);
let family_id = font_cache.load_family(&["Helvetica"]).unwrap();
let font_id = font_cache
@@ -505,6 +507,7 @@ mod tests {
font_id,
font_size,
wrap_width,
buffer_start_excerpt_header_height,
excerpt_header_height,
cx,
)
@@ -728,6 +731,7 @@ mod tests {
font_size,
wrap_width,
1,
1,
cx,
)
});
@@ -809,7 +813,7 @@ mod tests {
.unwrap();
let font_size = 14.0;
let map = cx.add_model(|cx| {
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, cx)
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, 1, cx)
});
buffer.update(cx, |buffer, cx| {
buffer.edit(
@@ -888,8 +892,8 @@ mod tests {
.unwrap();
let font_size = 14.0;
let map =
cx.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, cx));
let map = cx
.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, 1, cx));
assert_eq!(
cx.update(|cx| chunks(0..5, &map, &theme, cx)),
vec![
@@ -977,7 +981,7 @@ mod tests {
let font_size = 16.0;
let map = cx.add_model(|cx| {
DisplayMap::new(buffer, tab_size, font_id, font_size, Some(40.0), 1, cx)
DisplayMap::new(buffer, tab_size, font_id, font_size, Some(40.0), 1, 1, cx)
});
assert_eq!(
cx.update(|cx| chunks(0..5, &map, &theme, cx)),
@@ -1022,7 +1026,7 @@ mod tests {
.unwrap();
let font_size = 14.0;
let map = cx.add_model(|cx| {
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, cx)
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, 1, cx)
});
let map = map.update(cx, |map, cx| map.snapshot(cx));
@@ -1066,7 +1070,7 @@ mod tests {
let font_size = 14.0;
let map = cx.add_model(|cx| {
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, cx)
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, 1, cx)
});
let map = map.update(cx, |map, cx| map.snapshot(cx));
assert_eq!(map.text(), "✅ α\nβ \n🏀β γ");
@@ -1124,7 +1128,7 @@ mod tests {
.unwrap();
let font_size = 14.0;
let map = cx.add_model(|cx| {
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, cx)
DisplayMap::new(buffer.clone(), tab_size, font_id, font_size, None, 1, 1, cx)
});
assert_eq!(
map.update(cx, |map, cx| map.snapshot(cx)).max_point(),
+25 -6
View File
@@ -24,6 +24,7 @@ pub struct BlockMap {
wrap_snapshot: RefCell<WrapSnapshot>,
blocks: Vec<Arc<Block>>,
transforms: RefCell<SumTree<Transform>>,
buffer_header_height: u8,
excerpt_header_height: u8,
}
@@ -150,13 +151,18 @@ pub struct BlockBufferRows<'a> {
}
impl BlockMap {
pub fn new(wrap_snapshot: WrapSnapshot, excerpt_header_height: u8) -> Self {
pub fn new(
wrap_snapshot: WrapSnapshot,
buffer_header_height: u8,
excerpt_header_height: u8,
) -> Self {
let row_count = wrap_snapshot.max_point().row() + 1;
let map = Self {
next_block_id: AtomicUsize::new(0),
blocks: Vec::new(),
transforms: RefCell::new(SumTree::from_item(Transform::isomorphic(row_count), &())),
wrap_snapshot: RefCell::new(wrap_snapshot.clone()),
buffer_header_height,
excerpt_header_height,
};
map.sync(
@@ -352,7 +358,11 @@ impl BlockMap {
TransformBlock::ExcerptHeader {
buffer: excerpt_boundary.buffer,
range: excerpt_boundary.range,
height: self.excerpt_header_height,
height: if excerpt_boundary.starts_new_buffer {
self.buffer_header_height
} else {
self.excerpt_header_height
},
starts_new_buffer: excerpt_boundary.starts_new_buffer,
},
)
@@ -980,7 +990,7 @@ mod tests {
let (fold_map, folds_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), 1);
let (wrap_map, wraps_snapshot) = WrapMap::new(tabs_snapshot, font_id, 14.0, None, cx);
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1);
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1, 1);
let mut writer = block_map.write(wraps_snapshot.clone(), Default::default());
writer.insert(vec![
@@ -1158,7 +1168,7 @@ mod tests {
let (_, folds_snapshot) = FoldMap::new(buffer_snapshot.clone());
let (_, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), 1);
let (_, wraps_snapshot) = WrapMap::new(tabs_snapshot, font_id, 14.0, Some(60.), cx);
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1);
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1, 1);
let mut writer = block_map.write(wraps_snapshot.clone(), Default::default());
writer.insert(vec![
@@ -1203,6 +1213,7 @@ mod tests {
.select_font(family_id, &Default::default())
.unwrap();
let font_size = 14.0;
let buffer_start_header_height = rng.gen_range(1..=5);
let excerpt_header_height = rng.gen_range(1..=5);
log::info!("Wrap width: {:?}", wrap_width);
@@ -1222,7 +1233,11 @@ mod tests {
let (tab_map, tabs_snapshot) = TabMap::new(folds_snapshot.clone(), tab_size);
let (wrap_map, wraps_snapshot) =
WrapMap::new(tabs_snapshot, font_id, font_size, wrap_width, cx);
let mut block_map = BlockMap::new(wraps_snapshot.clone(), excerpt_header_height);
let mut block_map = BlockMap::new(
wraps_snapshot.clone(),
buffer_start_header_height,
excerpt_header_height,
);
let mut custom_blocks = Vec::new();
for _ in 0..operations {
@@ -1350,7 +1365,11 @@ mod tests {
(
position.row(),
ExpectedBlock::ExcerptHeader {
height: excerpt_header_height,
height: if boundary.starts_new_buffer {
buffer_start_header_height
} else {
excerpt_header_height
},
starts_new_buffer: boundary.starts_new_buffer,
},
)
+38 -33
View File
@@ -810,6 +810,7 @@ impl Editor {
settings.style.text.font_size,
None,
2,
1,
cx,
)
});
@@ -7892,21 +7893,23 @@ mod tests {
build_editor(multibuffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0),
DisplayPoint::new(1, 0)..DisplayPoint::new(1, 0),
assert_eq!(view.text(cx), "aaaa\nbbbb");
view.select_ranges(
[
Point::new(0, 0)..Point::new(0, 0),
Point::new(1, 0)..Point::new(1, 0),
],
None,
cx,
);
view.handle_input(&Input("X".to_string()), cx);
assert_eq!(view.text(cx), "Xaaaa\nXbbbb");
assert_eq!(
view.selected_display_ranges(cx),
&[
DisplayPoint::new(0, 1)..DisplayPoint::new(0, 1),
DisplayPoint::new(1, 1)..DisplayPoint::new(1, 1),
view.selected_ranges(cx),
[
Point::new(0, 1)..Point::new(0, 1),
Point::new(1, 1)..Point::new(1, 1),
]
)
});
@@ -7944,31 +7947,32 @@ mod tests {
build_editor(multibuffer, settings, cx)
});
view.update(cx, |view, cx| {
view.select_display_ranges(
&[
DisplayPoint::new(1, 1)..DisplayPoint::new(1, 1),
DisplayPoint::new(2, 3)..DisplayPoint::new(2, 3),
view.select_ranges(
[
Point::new(1, 1)..Point::new(1, 1),
Point::new(2, 3)..Point::new(2, 3),
],
None,
cx,
);
view.handle_input(&Input("X".to_string()), cx);
assert_eq!(view.text(cx), "aaaa\nbXbbXb\nbXbbXb\ncccc");
assert_eq!(
view.selected_display_ranges(cx),
&[
DisplayPoint::new(1, 2)..DisplayPoint::new(1, 2),
DisplayPoint::new(2, 5)..DisplayPoint::new(2, 5),
view.selected_ranges(cx),
[
Point::new(1, 2)..Point::new(1, 2),
Point::new(2, 5)..Point::new(2, 5),
]
);
view.newline(&Newline, cx);
assert_eq!(view.text(cx), "aaaa\nbX\nbbX\nb\nbX\nbbX\nb\ncccc");
assert_eq!(
view.selected_display_ranges(cx),
&[
DisplayPoint::new(2, 0)..DisplayPoint::new(2, 0),
DisplayPoint::new(6, 0)..DisplayPoint::new(6, 0),
view.selected_ranges(cx),
[
Point::new(2, 0)..Point::new(2, 0),
Point::new(6, 0)..Point::new(6, 0),
]
);
});
@@ -8003,11 +8007,12 @@ mod tests {
);
let (_, editor) = cx.add_window(Default::default(), |cx| {
let mut editor = build_editor(multibuffer.clone(), settings, cx);
editor.select_display_ranges(
&[
DisplayPoint::new(1, 3)..DisplayPoint::new(1, 3),
DisplayPoint::new(2, 1)..DisplayPoint::new(2, 1),
editor.select_ranges(
[
Point::new(1, 3)..Point::new(1, 3),
Point::new(2, 1)..Point::new(2, 1),
],
None,
cx,
);
editor
@@ -8017,10 +8022,10 @@ mod tests {
editor.update(cx, |editor, cx| {
editor.refresh_selections(cx);
assert_eq!(
editor.selected_display_ranges(cx),
editor.selected_ranges(cx),
[
DisplayPoint::new(1, 3)..DisplayPoint::new(1, 3),
DisplayPoint::new(2, 1)..DisplayPoint::new(2, 1),
Point::new(1, 3)..Point::new(1, 3),
Point::new(2, 1)..Point::new(2, 1),
]
);
});
@@ -8031,10 +8036,10 @@ mod tests {
editor.update(cx, |editor, cx| {
// Removing an excerpt causes the first selection to become degenerate.
assert_eq!(
editor.selected_display_ranges(cx),
editor.selected_ranges(cx),
[
DisplayPoint::new(0, 0)..DisplayPoint::new(0, 0),
DisplayPoint::new(0, 1)..DisplayPoint::new(0, 1)
Point::new(0, 0)..Point::new(0, 0),
Point::new(0, 1)..Point::new(0, 1)
]
);
@@ -8042,10 +8047,10 @@ mod tests {
// location.
editor.refresh_selections(cx);
assert_eq!(
editor.selected_display_ranges(cx),
editor.selected_ranges(cx),
[
DisplayPoint::new(0, 1)..DisplayPoint::new(0, 1),
DisplayPoint::new(0, 3)..DisplayPoint::new(0, 3)
Point::new(0, 1)..Point::new(0, 1),
Point::new(0, 3)..Point::new(0, 3)
]
);
});
+47 -30
View File
@@ -679,42 +679,59 @@ impl EditorElement {
em_width,
})
}
TransformBlock::ExcerptHeader { buffer, .. } => {
let style = &self.settings.style.diagnostic_path_header;
let font_size =
(style.text_scale_factor * self.settings.style.text.font_size).round();
TransformBlock::ExcerptHeader {
buffer,
starts_new_buffer,
..
} => {
if *starts_new_buffer {
let style = &self.settings.style.diagnostic_path_header;
let font_size = (style.text_scale_factor
* self.settings.style.text.font_size)
.round();
let mut filename = None;
let mut parent_path = None;
if let Some(path) = buffer.path() {
filename = path.file_name().map(|f| f.to_string_lossy().to_string());
parent_path =
path.parent().map(|p| p.to_string_lossy().to_string() + "/");
}
let mut filename = None;
let mut parent_path = None;
if let Some(path) = buffer.path() {
filename =
path.file_name().map(|f| f.to_string_lossy().to_string());
parent_path =
path.parent().map(|p| p.to_string_lossy().to_string() + "/");
}
Flex::row()
.with_child(
Label::new(
filename.unwrap_or_else(|| "untitled".to_string()),
style.filename.text.clone().with_font_size(font_size),
Flex::row()
.with_child(
Label::new(
filename.unwrap_or_else(|| "untitled".to_string()),
style.filename.text.clone().with_font_size(font_size),
)
.contained()
.with_style(style.filename.container)
.boxed(),
)
.contained()
.with_style(style.filename.container)
.boxed(),
)
.with_children(parent_path.map(|path| {
Label::new(path, style.path.text.clone().with_font_size(font_size))
.with_children(parent_path.map(|path| {
Label::new(
path,
style.path.text.clone().with_font_size(font_size),
)
.contained()
.with_style(style.path.container)
.boxed()
}))
.aligned()
.left()
.contained()
.with_style(style.container)
.with_padding_left(gutter_padding + scroll_x * em_width)
.expanded()
.named("path header block")
}))
.aligned()
.left()
.contained()
.with_style(style.container)
.with_padding_left(gutter_padding + scroll_x * em_width)
.expanded()
.named("path header block")
} else {
let text_style = self.settings.style.text.clone();
Label::new("…".to_string(), text_style)
.contained()
.with_padding_left(gutter_padding + scroll_x * em_width)
.named("collapsed context")
}
}
};
+12 -12
View File
@@ -257,10 +257,10 @@ mod tests {
});
let display_map =
cx.add_model(|cx| DisplayMap::new(multibuffer, 2, font_id, 14.0, None, 2, cx));
cx.add_model(|cx| DisplayMap::new(multibuffer, 2, font_id, 14.0, None, 2, 2, cx));
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\n\nhijkl\nmn");
assert_eq!(snapshot.text(), "\n\nabc\ndefg\n\n\nhijkl\nmn");
// Can't move up into the first excerpt's header
assert_eq!(
@@ -284,22 +284,22 @@ mod tests {
// Move up and down across second excerpt's header
assert_eq!(
up(&snapshot, DisplayPoint::new(7, 5), SelectionGoal::Column(5)).unwrap(),
up(&snapshot, DisplayPoint::new(6, 5), SelectionGoal::Column(5)).unwrap(),
(DisplayPoint::new(3, 4), SelectionGoal::Column(5)),
);
assert_eq!(
down(&snapshot, DisplayPoint::new(3, 4), SelectionGoal::Column(5)).unwrap(),
(DisplayPoint::new(7, 5), SelectionGoal::Column(5)),
(DisplayPoint::new(6, 5), SelectionGoal::Column(5)),
);
// Can't move down off the end
assert_eq!(
down(&snapshot, DisplayPoint::new(8, 0), SelectionGoal::Column(0)).unwrap(),
(DisplayPoint::new(8, 2), SelectionGoal::Column(2)),
down(&snapshot, DisplayPoint::new(7, 0), SelectionGoal::Column(0)).unwrap(),
(DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
);
assert_eq!(
down(&snapshot, DisplayPoint::new(8, 2), SelectionGoal::Column(2)).unwrap(),
(DisplayPoint::new(8, 2), SelectionGoal::Column(2)),
down(&snapshot, DisplayPoint::new(7, 2), SelectionGoal::Column(2)).unwrap(),
(DisplayPoint::new(7, 2), SelectionGoal::Column(2)),
);
}
@@ -314,8 +314,8 @@ mod tests {
let font_size = 14.0;
let buffer = MultiBuffer::build_simple("a bcΔ defγ hi—jk", cx);
let display_map =
cx.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, cx));
let display_map = cx
.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, 1, cx));
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
assert_eq!(
prev_word_boundary(&snapshot, DisplayPoint::new(0, 12)),
@@ -370,8 +370,8 @@ mod tests {
.unwrap();
let font_size = 14.0;
let buffer = MultiBuffer::build_simple("lorem ipsum dolor\n sit", cx);
let display_map =
cx.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, cx));
let display_map = cx
.add_model(|cx| DisplayMap::new(buffer, tab_size, font_id, font_size, None, 1, 1, cx));
let snapshot = display_map.update(cx, |map, cx| map.snapshot(cx));
assert_eq!(