Get language and project compiling

This commit is contained in:
Nathan Sobo 2021-10-25 09:26:36 -06:00
parent 60a8e74430
commit ab4f90a20a
4 changed files with 36 additions and 39 deletions

View File

@ -2466,3 +2466,9 @@ impl ToPoint for usize {
content.into().visible_text.to_point(*self)
}
}
impl ToPoint for Point {
fn to_point<'a>(&self, _: impl Into<Content<'a>>) -> Point {
*self
}
}

View File

@ -522,9 +522,9 @@ impl Buffer {
for request in autoindent_requests {
let old_to_new_rows = request
.edited
.to_points(&request.before_edit)
.points(&request.before_edit)
.map(|point| point.row)
.zip(request.edited.to_points(&snapshot).map(|point| point.row))
.zip(request.edited.points(&snapshot).map(|point| point.row))
.collect::<BTreeMap<u32, u32>>();
let mut old_suggestions = HashMap::<u32, u32>::default();
@ -633,31 +633,27 @@ impl Buffer {
for selection_set_id in &selection_set_ids {
if let Ok(set) = self.selection_set(*selection_set_id) {
let new_selections = set
.selections
.iter()
.point_selections(&*self)
.map(|selection| {
let start_point = selection.start.to_point(&self.text);
if start_point.column == 0 {
let end_point = selection.end.to_point(&self.text);
if selection.start.column == 0 {
let delta = Point::new(
0,
indent_columns.get(&start_point.row).copied().unwrap_or(0),
indent_columns.get(&selection.start.row).copied().unwrap_or(0),
);
if delta.column > 0 {
return Selection {
id: selection.id,
goal: selection.goal,
reversed: selection.reversed,
start: self
.anchor_at(start_point + delta, selection.start.bias),
end: self.anchor_at(end_point + delta, selection.end.bias),
start: selection.start + delta,
end: selection.end + delta,
};
}
}
selection.clone()
selection
})
.collect::<Arc<[_]>>();
self.update_selection_set(*selection_set_id, new_selections, cx)
.collect::<Vec<_>>();
self.update_selection_set(*selection_set_id, &new_selections, cx)
.unwrap();
}
}
@ -936,9 +932,9 @@ impl Buffer {
}
}
pub fn add_selection_set(
pub fn add_selection_set<T: ToOffset>(
&mut self,
selections: impl Into<Arc<[Selection]>>,
selections: &[Selection<T>],
cx: &mut ModelContext<Self>,
) -> SelectionSetId {
let operation = self.text.add_selection_set(selections);
@ -952,10 +948,10 @@ impl Buffer {
}
}
pub fn update_selection_set(
pub fn update_selection_set<T: ToOffset>(
&mut self,
set_id: SelectionSetId,
selections: impl Into<Arc<[Selection]>>,
selections: &[Selection<T>],
cx: &mut ModelContext<Self>,
) -> Result<()> {
let operation = self.text.update_selection_set(set_id, selections)?;

View File

@ -275,24 +275,24 @@ fn test_autoindent_moves_selections(cx: &mut MutableAppContext) {
let text = History::new("fn a() {}".into());
let mut buffer = Buffer::from_history(0, text, None, Some(rust_lang()), cx);
let selection_set_id = buffer.add_selection_set(Vec::new(), cx);
let selection_set_id = buffer.add_selection_set::<usize>(&[], cx);
buffer.start_transaction(Some(selection_set_id)).unwrap();
buffer.edit_with_autoindent([5..5, 9..9], "\n\n", cx);
buffer
.update_selection_set(
selection_set_id,
vec![
&[
Selection {
id: 0,
start: buffer.anchor_before(Point::new(1, 0)),
end: buffer.anchor_before(Point::new(1, 0)),
start: Point::new(1, 0),
end: Point::new(1, 0),
reversed: false,
goal: SelectionGoal::None,
},
Selection {
id: 1,
start: buffer.anchor_before(Point::new(4, 0)),
end: buffer.anchor_before(Point::new(4, 0)),
start: Point::new(4, 0),
end: Point::new(4, 0),
reversed: false,
goal: SelectionGoal::None,
},
@ -309,8 +309,7 @@ fn test_autoindent_moves_selections(cx: &mut MutableAppContext) {
let selection_ranges = buffer
.selection_set(selection_set_id)
.unwrap()
.selections
.iter()
.point_selections(&buffer)
.map(|selection| selection.point_range(&buffer))
.collect::<Vec<_>>();

View File

@ -3352,16 +3352,13 @@ mod tests {
let selection_set_id = buffer.update(&mut cx, |buffer, cx| {
assert!(!buffer.is_dirty());
buffer.add_selection_set(
(0..3)
.map(|row| {
let anchor = buffer.anchor_at(Point::new(row, 0), Bias::Right);
Selection {
id: row as usize,
start: anchor.clone(),
end: anchor,
reversed: false,
goal: SelectionGoal::None,
}
&(0..3)
.map(|row| Selection {
id: row as usize,
start: Point::new(row, 0),
end: Point::new(row, 0),
reversed: false,
goal: SelectionGoal::None,
})
.collect::<Vec<_>>(),
cx,
@ -3391,11 +3388,10 @@ mod tests {
let set = buffer.selection_set(selection_set_id).unwrap();
let cursor_positions = set
.selections
.iter()
.point_selections(&*buffer)
.map(|selection| {
assert_eq!(selection.start, selection.end);
selection.start.to_point(&*buffer)
selection.start
})
.collect::<Vec<_>>();
assert_eq!(