Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
When navigating diagnostics, skip diagnostic containing cursor
Juliabfdff4e2e0b7
diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 380cf1a5e60..caee3189777 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -7202,6 +7202,7 @@ impl Editor {&& entry.diagnostic.severity <= DiagnosticSeverity::WARNING&& !entry.range.is_empty()&& Some(entry.range.end) != active_primary_range.as_ref().map(|r| *r.end())+ && !entry.range.contains(&search_start){Some((entry.range, entry.diagnostic.group_id))} else {@@ -8946,6 +8947,16 @@ impl Editor {telemetry.report_clickhouse_event(event, telemetry_settings);}+ #[cfg(any(test, feature = "test-support"))]+ fn report_editor_event(+ &self,+ _operation: &'static str,+ _file_extension: Option<String>,+ _cx: &AppContext,+ ) {+ }++ #[cfg(not(any(test, feature = "test-support")))]fn report_editor_event(&self,operation: &'static str,diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rsindex a847e33c1a1..f6b36bc8a67 100644--- a/crates/editor/src/editor_tests.rs+++ b/crates/editor/src/editor_tests.rs@@ -6718,6 +6718,102 @@ fn test_combine_syntax_and_fuzzy_match_highlights() {);}+#[gpui::test]+async fn go_to_prev_overlapping_diagnostic(+ deterministic: Arc<Deterministic>,+ cx: &mut gpui::TestAppContext,+) {+ init_test(cx, |_| {});++ let mut cx = EditorTestContext::new(cx).await;+ let project = cx.update_editor(|editor, _| editor.project.clone().unwrap());++ cx.set_state(indoc! {"+ ˇfn func(abc def: i32) -> u32 {+ }+ "});++ cx.update(|cx| {+ project.update(cx, |project, cx| {+ project+ .update_diagnostics(+ LanguageServerId(0),+ lsp::PublishDiagnosticsParams {+ uri: lsp::Url::from_file_path("/root/file").unwrap(),+ version: None,+ diagnostics: vec![+ lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 11),+ lsp::Position::new(0, 12),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 12),+ lsp::Position::new(0, 15),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ ..Default::default()+ },+ lsp::Diagnostic {+ range: lsp::Range::new(+ lsp::Position::new(0, 25),+ lsp::Position::new(0, 28),+ ),+ severity: Some(lsp::DiagnosticSeverity::ERROR),+ ..Default::default()+ },+ ],+ },+ &[],+ cx,+ )+ .unwrap()+ });+ });++ deterministic.run_until_parked();++ cx.update_editor(|editor, cx| {+ editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, cx);+ });++ cx.assert_editor_state(indoc! {"+ fn func(abc def: i32) -> ˇu32 {+ }+ "});++ cx.update_editor(|editor, cx| {+ editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, cx);+ });++ cx.assert_editor_state(indoc! {"+ fn func(abc ˇdef: i32) -> u32 {+ }+ "});++ cx.update_editor(|editor, cx| {+ editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, cx);+ });++ cx.assert_editor_state(indoc! {"+ fn func(abcˇ def: i32) -> u32 {+ }+ "});++ cx.update_editor(|editor, cx| {+ editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, cx);+ });++ cx.assert_editor_state(indoc! {"+ fn func(abc def: i32) -> ˇu32 {+ }+ "});+}+#[gpui::test]async fn go_to_hunk(deterministic: Arc<Deterministic>, cx: &mut gpui::TestAppContext) {init_test(cx, |_| {});diff --git a/crates/editor/src/test.rs b/crates/editor/src/test.rsindex 9b568e4a4fe..08cc533d62c 100644--- a/crates/editor/src/test.rs+++ b/crates/editor/src/test.rs@@ -8,6 +8,7 @@ use crate::{use gpui::{ModelHandle, ViewContext};+use project::Project;use util::test::{marked_text_offsets, marked_text_ranges};#[cfg(test)]@@ -63,9 +64,20 @@ pub fn assert_text_with_selections(assert_eq!(editor.selections.ranges(cx), text_ranges);}+// RA thinks this is dead code even though it is used in a whole lot of tests+#[allow(dead_code)]+#[cfg(any(test, feature = "test-support"))]pub(crate) fn build_editor(buffer: ModelHandle<MultiBuffer>,cx: &mut ViewContext<Editor>,) -> Editor {Editor::new(EditorMode::Full, buffer, None, None, cx)}++pub(crate) fn build_editor_with_project(+ project: ModelHandle<Project>,+ buffer: ModelHandle<MultiBuffer>,+ cx: &mut ViewContext<Editor>,+) -> Editor {+ Editor::new(EditorMode::Full, buffer, Some(project), None, cx)+}diff --git a/crates/editor/src/test/editor_test_context.rs b/crates/editor/src/test/editor_test_context.rsindex 0ef54dc3d55..c083ce0e682 100644--- a/crates/editor/src/test/editor_test_context.rs+++ b/crates/editor/src/test/editor_test_context.rs@@ -18,7 +18,7 @@ use util::{test::{generate_marked_text, marked_text_ranges},};-use super::build_editor;+use super::build_editor_with_project;pub struct EditorTestContext<'a> {pub cx: &'a mut gpui::TestAppContext,@@ -29,13 +29,24 @@ pub struct EditorTestContext<'a> {impl<'a> EditorTestContext<'a> {pub async fn new(cx: &'a mut gpui::TestAppContext) -> EditorTestContext<'a> {let fs = FakeFs::new(cx.background());- let project = Project::test(fs, [], cx).await;+ // fs.insert_file("/file", "".to_owned()).await;+ fs.insert_tree(+ "/root",+ gpui::serde_json::json!({+ "file": "",+ }),+ )+ .await;+ let project = Project::test(fs, ["/root".as_ref()], cx).await;let buffer = project- .update(cx, |project, cx| project.create_buffer("", None, cx))+ .update(cx, |project, cx| {+ project.open_local_buffer("/root/file", cx)+ })+ .await.unwrap();let window = cx.add_window(|cx| {cx.focus_self();- build_editor(MultiBuffer::build_from_buffer(buffer, cx), cx)+ build_editor_with_project(project, MultiBuffer::build_from_buffer(buffer, cx), cx)});let editor = window.root(cx);Self {