From bd4d7551a5157f44b580b2493ef018f1bc72650e Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Fri, 3 Mar 2023 16:35:12 -0800 Subject: [PATCH 1/2] Make diagnostic processing order independent Co-authored-by: max --- crates/project/src/project.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 0325d07ce6a38991b31f27ff31895c6d4cb0061a..0ec2d92d57a5fde039d9e4bcf7de265f641ccd34 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -2557,7 +2557,7 @@ impl Project { pub fn update_diagnostics( &mut self, language_server_id: usize, - params: lsp::PublishDiagnosticsParams, + mut params: lsp::PublishDiagnosticsParams, disk_based_sources: &[String], cx: &mut ModelContext, ) -> Result<()> { @@ -2569,6 +2569,10 @@ impl Project { let mut primary_diagnostic_group_ids = HashMap::default(); let mut sources_by_group_id = HashMap::default(); let mut supporting_diagnostics = HashMap::default(); + + // Ensure that primary diagnostics are always the most severe + params.diagnostics.sort_by_key(|item| item.severity); + for diagnostic in ¶ms.diagnostics { let source = diagnostic.source.as_ref(); let code = diagnostic.code.as_ref().map(|code| match code { From ddf2f2cb0af85f54c7eb24ed63811edb9681d269 Mon Sep 17 00:00:00 2001 From: Mikayla Maki Date: Sat, 4 Mar 2023 02:21:55 -0800 Subject: [PATCH 2/2] Update test to use new group ids and new ordering of diagnostics. --- Cargo.lock | 1 + crates/project/Cargo.toml | 1 + crates/project/src/project_tests.rs | 56 +++++++++++++++-------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 615825bd757f5897d6c11970307ffe77799c39eb..2e7997458ed00185d5d1b48f2943eb0e657a1b41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4592,6 +4592,7 @@ dependencies = [ "lsp", "parking_lot 0.11.2", "postage", + "pretty_assertions", "pulldown-cmark", "rand 0.8.5", "regex", diff --git a/crates/project/Cargo.toml b/crates/project/Cargo.toml index 949dbdf9164adc0436b919889d46462f305dd32e..68dc57f61459bd5aaf3cfe242319ff538d96b9f1 100644 --- a/crates/project/Cargo.toml +++ b/crates/project/Cargo.toml @@ -57,6 +57,7 @@ thiserror = "1.0.29" toml = "0.5" [dev-dependencies] +pretty_assertions = "1.3.0" client = { path = "../client", features = ["test-support"] } collections = { path = "../collections", features = ["test-support"] } db = { path = "../db", features = ["test-support"] } diff --git a/crates/project/src/project_tests.rs b/crates/project/src/project_tests.rs index 2f9f92af4e1e0d3415a2c52ffd401e41fd2005ea..ddcfed9dac548f3c03c14e61f23c9d0c9e474964 100644 --- a/crates/project/src/project_tests.rs +++ b/crates/project/src/project_tests.rs @@ -8,6 +8,7 @@ use language::{ OffsetRangeExt, Point, ToPoint, }; use lsp::Url; +use pretty_assertions::assert_eq; use serde_json::json; use std::{cell::RefCell, os::unix, rc::Rc, task::Poll}; use unindent::Unindent as _; @@ -2846,7 +2847,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::WARNING, message: "error 1".to_string(), - group_id: 0, + group_id: 1, is_primary: true, ..Default::default() } @@ -2856,7 +2857,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::HINT, message: "error 1 hint 1".to_string(), - group_id: 0, + group_id: 1, is_primary: false, ..Default::default() } @@ -2866,7 +2867,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::HINT, message: "error 2 hint 1".to_string(), - group_id: 1, + group_id: 0, is_primary: false, ..Default::default() } @@ -2876,7 +2877,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::HINT, message: "error 2 hint 2".to_string(), - group_id: 1, + group_id: 0, is_primary: false, ..Default::default() } @@ -2886,7 +2887,7 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) { diagnostic: Diagnostic { severity: DiagnosticSeverity::ERROR, message: "error 2".to_string(), - group_id: 1, + group_id: 0, is_primary: true, ..Default::default() } @@ -2898,60 +2899,61 @@ async fn test_grouped_diagnostics(cx: &mut gpui::TestAppContext) { buffer.diagnostic_group::(0).collect::>(), &[ DiagnosticEntry { - range: Point::new(1, 8)..Point::new(1, 9), + range: Point::new(1, 13)..Point::new(1, 15), diagnostic: Diagnostic { - severity: DiagnosticSeverity::WARNING, - message: "error 1".to_string(), + severity: DiagnosticSeverity::HINT, + message: "error 2 hint 1".to_string(), group_id: 0, - is_primary: true, + is_primary: false, ..Default::default() } }, DiagnosticEntry { - range: Point::new(1, 8)..Point::new(1, 9), + range: Point::new(1, 13)..Point::new(1, 15), diagnostic: Diagnostic { severity: DiagnosticSeverity::HINT, - message: "error 1 hint 1".to_string(), + message: "error 2 hint 2".to_string(), group_id: 0, is_primary: false, ..Default::default() } }, + DiagnosticEntry { + range: Point::new(2, 8)..Point::new(2, 17), + diagnostic: Diagnostic { + severity: DiagnosticSeverity::ERROR, + message: "error 2".to_string(), + group_id: 0, + is_primary: true, + ..Default::default() + } + } ] ); + assert_eq!( buffer.diagnostic_group::(1).collect::>(), &[ DiagnosticEntry { - range: Point::new(1, 13)..Point::new(1, 15), + range: Point::new(1, 8)..Point::new(1, 9), diagnostic: Diagnostic { - severity: DiagnosticSeverity::HINT, - message: "error 2 hint 1".to_string(), + severity: DiagnosticSeverity::WARNING, + message: "error 1".to_string(), group_id: 1, - is_primary: false, + is_primary: true, ..Default::default() } }, DiagnosticEntry { - range: Point::new(1, 13)..Point::new(1, 15), + range: Point::new(1, 8)..Point::new(1, 9), diagnostic: Diagnostic { severity: DiagnosticSeverity::HINT, - message: "error 2 hint 2".to_string(), + message: "error 1 hint 1".to_string(), group_id: 1, is_primary: false, ..Default::default() } }, - DiagnosticEntry { - range: Point::new(2, 8)..Point::new(2, 17), - diagnostic: Diagnostic { - severity: DiagnosticSeverity::ERROR, - message: "error 2".to_string(), - group_id: 1, - is_primary: true, - ..Default::default() - } - } ] ); }