From 4f7200527cba08740c9b4d4b56657267c4c82fe2 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Mon, 10 Feb 2025 19:13:12 +0200 Subject: [PATCH] Revert "Fix `editor::GoToDiagnostics` cycle (#24446)" (#24568) This reverts commit 4f65cfa93d183295289a4313e550c434b8ab7fc7. Release Notes: - N/A --- crates/editor/src/editor.rs | 24 ++--- crates/editor/src/editor_tests.rs | 170 ------------------------------ 2 files changed, 6 insertions(+), 188 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 15317e099938422cf2ddc457cfec7ad994faa579..410509139571e74e9caf72d6f156df915af768a0 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -10299,26 +10299,14 @@ impl Editor { if entry.diagnostic.is_primary && entry.diagnostic.severity <= DiagnosticSeverity::WARNING && entry.range.start != entry.range.end + // if we match with the active diagnostic, skip it + && Some(entry.diagnostic.group_id) + != self.active_diagnostics.as_ref().map(|d| d.group_id) { - let entry_group = entry.diagnostic.group_id; - let in_next_group = self.active_diagnostics.as_ref().map_or( - true, - |active| match direction { - Direction::Prev => { - entry_group != active.group_id - && (active.group_id == 0 || entry_group < active.group_id) - } - Direction::Next => { - entry_group != active.group_id - && (entry_group == 0 || entry_group > active.group_id) - } - }, - ); - if in_next_group { - return Some((entry.range, entry.diagnostic.group_id)); - } + Some((entry.range, entry.diagnostic.group_id)) + } else { + None } - None }); if let Some((primary_range, group_id)) = group { diff --git a/crates/editor/src/editor_tests.rs b/crates/editor/src/editor_tests.rs index 5247c629c06919ce503c02545193de7143e7cafc..68bd0514dd9bac55c7032a25d46067dd191b83ba 100644 --- a/crates/editor/src/editor_tests.rs +++ b/crates/editor/src/editor_tests.rs @@ -10653,176 +10653,6 @@ async fn go_to_prev_overlapping_diagnostic( "}); } -#[gpui::test] -async fn cycle_through_same_place_diagnostics( - executor: BackgroundExecutor, - cx: &mut gpui::TestAppContext, -) { - init_test(cx, |_| {}); - - let mut cx = EditorTestContext::new(cx).await; - let lsp_store = - cx.update_editor(|editor, _, cx| editor.project.as_ref().unwrap().read(cx).lsp_store()); - - cx.set_state(indoc! {" - ˇfn func(abc def: i32) -> u32 { - } - "}); - - cx.update(|_, cx| { - lsp_store.update(cx, |lsp_store, cx| { - lsp_store - .update_diagnostics( - LanguageServerId(0), - lsp::PublishDiagnosticsParams { - uri: lsp::Url::from_file_path(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, 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() - }); - }); - executor.run_until_parked(); - - //// Backward - - // Fourth diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abc def: i32) -> ˇu32 { - } - "}); - - // Third diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abc ˇdef: i32) -> u32 { - } - "}); - - // Second diagnostic, same place - cx.update_editor(|editor, window, cx| { - editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abc ˇdef: i32) -> u32 { - } - "}); - - // First diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abcˇ def: i32) -> u32 { - } - "}); - - // Wrapped over, fourth diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_prev_diagnostic(&GoToPrevDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abc def: i32) -> ˇu32 { - } - "}); - - cx.update_editor(|editor, window, cx| { - editor.move_to_beginning(&MoveToBeginning, window, cx); - }); - cx.assert_editor_state(indoc! {" - ˇfn func(abc def: i32) -> u32 { - } - "}); - - //// Forward - - // First diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_diagnostic(&GoToDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abcˇ def: i32) -> u32 { - } - "}); - - // Second diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_diagnostic(&GoToDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abc ˇdef: i32) -> u32 { - } - "}); - - // Third diagnostic, same place - cx.update_editor(|editor, window, cx| { - editor.go_to_diagnostic(&GoToDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abc ˇdef: i32) -> u32 { - } - "}); - - // Fourth diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_diagnostic(&GoToDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abc def: i32) -> ˇu32 { - } - "}); - - // Wrapped around, first diagnostic - cx.update_editor(|editor, window, cx| { - editor.go_to_diagnostic(&GoToDiagnostic, window, cx); - }); - cx.assert_editor_state(indoc! {" - fn func(abcˇ def: i32) -> u32 { - } - "}); -} - #[gpui::test] async fn test_diagnostics_with_links(cx: &mut TestAppContext) { init_test(cx, |_| {});