From ab4f90a20a4f7f6adcff20ddcd0d3336285a3ae6 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 25 Oct 2021 09:26:36 -0600 Subject: [PATCH] Get language and project compiling --- crates/buffer/src/lib.rs | 6 ++++++ crates/language/src/lib.rs | 32 ++++++++++++++------------------ crates/language/src/tests.rs | 15 +++++++-------- crates/project/src/worktree.rs | 22 +++++++++------------- 4 files changed, 36 insertions(+), 39 deletions(-) diff --git a/crates/buffer/src/lib.rs b/crates/buffer/src/lib.rs index a5dd062570..a3d841db3f 100644 --- a/crates/buffer/src/lib.rs +++ b/crates/buffer/src/lib.rs @@ -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>) -> Point { + *self + } +} diff --git a/crates/language/src/lib.rs b/crates/language/src/lib.rs index b80eed7e33..8d0f06a648 100644 --- a/crates/language/src/lib.rs +++ b/crates/language/src/lib.rs @@ -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::>(); let mut old_suggestions = HashMap::::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::>(); - self.update_selection_set(*selection_set_id, new_selections, cx) + .collect::>(); + 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( &mut self, - selections: impl Into>, + selections: &[Selection], cx: &mut ModelContext, ) -> 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( &mut self, set_id: SelectionSetId, - selections: impl Into>, + selections: &[Selection], cx: &mut ModelContext, ) -> Result<()> { let operation = self.text.update_selection_set(set_id, selections)?; diff --git a/crates/language/src/tests.rs b/crates/language/src/tests.rs index 23cdced4c7..7237fd3b80 100644 --- a/crates/language/src/tests.rs +++ b/crates/language/src/tests.rs @@ -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::(&[], 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::>(); diff --git a/crates/project/src/worktree.rs b/crates/project/src/worktree.rs index 0ef60a7408..f763a57699 100644 --- a/crates/project/src/worktree.rs +++ b/crates/project/src/worktree.rs @@ -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::>(), 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::>(); assert_eq!(