From 52b8e3d1a283ecdf4cd73911992461d9ba6eecec Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 13 Dec 2021 11:34:56 -0800 Subject: [PATCH] Get tests passing after diagnostic + selection changes Co-Authored-By: Nathan Sobo --- crates/editor/src/editor.rs | 5 +++++ crates/editor/src/multi_buffer.rs | 22 ++++++++++++++++++---- crates/language/src/tests.rs | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 52bc739d0709ca9b787b8c63e1235ea182ab78ca..0eecd17ce65eae20c873ef9dbef42f8c03b300e0 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -5948,6 +5948,11 @@ mod tests { .update(cx, |display_map, cx| display_map.snapshot(cx)); self.selections .iter() + .chain( + self.pending_selection + .as_ref() + .map(|pending| &pending.selection), + ) .map(|s| { if s.reversed { s.end.to_display_point(&display_map)..s.start.to_display_point(&display_map) diff --git a/crates/editor/src/multi_buffer.rs b/crates/editor/src/multi_buffer.rs index 503707e848f51168cc41555edc22aeb312d171ef..d79c0749061291fd4a19f052948d1d865ee6b928 100644 --- a/crates/editor/src/multi_buffer.rs +++ b/crates/editor/src/multi_buffer.rs @@ -163,18 +163,18 @@ impl MultiBuffer { self.subscriptions.subscribe() } - pub fn edit(&mut self, ranges_iter: I, new_text: T, cx: &mut ModelContext) + pub fn edit(&mut self, ranges: I, new_text: T, cx: &mut ModelContext) where I: IntoIterator>, S: ToOffset, T: Into, { - self.edit_internal(ranges_iter, new_text, false, cx) + self.edit_internal(ranges, new_text, false, cx) } pub fn edit_with_autoindent( &mut self, - ranges_iter: I, + ranges: I, new_text: T, cx: &mut ModelContext, ) where @@ -182,7 +182,7 @@ impl MultiBuffer { S: ToOffset, T: Into, { - self.edit_internal(ranges_iter, new_text, true, cx) + self.edit_internal(ranges, new_text, true, cx) } pub fn edit_internal( @@ -196,6 +196,20 @@ impl MultiBuffer { S: ToOffset, T: Into, { + if let Some(buffer) = self.as_singleton() { + let snapshot = self.read(cx); + let ranges = ranges_iter + .into_iter() + .map(|range| range.start.to_offset(&snapshot)..range.end.to_offset(&snapshot)); + return buffer.update(cx, |buffer, cx| { + if autoindent { + buffer.edit_with_autoindent(ranges, new_text, cx) + } else { + buffer.edit(ranges, new_text, cx) + } + }); + } + let snapshot = self.read(cx); let mut buffer_edits: HashMap, bool)>> = Default::default(); let mut cursor = snapshot.excerpts.cursor::(); diff --git a/crates/language/src/tests.rs b/crates/language/src/tests.rs index 93c2f99c98d8cdfbec1b38d4582e42594c71144a..e18589cbc949c0b2e266b854b0fceee998e8bd2c 100644 --- a/crates/language/src/tests.rs +++ b/crates/language/src/tests.rs @@ -518,6 +518,8 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'A'".to_string(), + group_id: 0, + is_primary: true, ..Default::default() }, }, @@ -526,6 +528,8 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'BB'".to_string(), + group_id: 1, + is_primary: true, ..Default::default() }, }, @@ -534,6 +538,8 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'CCC'".to_string(), + group_id: 2, + is_primary: true, ..Default::default() }, }, @@ -602,6 +608,8 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'A'".to_string(), + group_id: 0, + is_primary: true, ..Default::default() }, }, @@ -610,6 +618,8 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::WARNING, message: "unreachable statement".to_string(), + group_id: 1, + is_primary: true, ..Default::default() }, }, @@ -687,6 +697,8 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'BB'".to_string(), source: Some("disk".to_string()), + group_id: 1, + is_primary: true, ..Default::default() }, }, @@ -696,6 +708,8 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'A'".to_string(), source: Some("disk".to_string()), + group_id: 0, + is_primary: true, ..Default::default() }, }, @@ -714,6 +728,7 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'A'".to_string(), + source: Some("disk".to_string()), group_id: 0, is_primary: true, ..Default::default() @@ -724,6 +739,7 @@ async fn test_diagnostics(mut cx: gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::ERROR, message: "undefined variable 'BB'".to_string(), + source: Some("disk".to_string()), group_id: 1, is_primary: true, ..Default::default()