From 4364ffbdd33095ad72973d4afcf7aac5ab0c88ea Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 8 Dec 2025 15:22:11 +0100 Subject: [PATCH] [ty] Don't create a related diagnostic for the primary annotation of sub-diagnostics (#21845) --- crates/ruff_db/src/diagnostic/mod.rs | 4 ++++ crates/ty_server/src/server/api/diagnostics.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index 33348ddf2e..cf1114b11f 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -888,6 +888,10 @@ impl Annotation { pub fn hide_snippet(&mut self, yes: bool) { self.hide_snippet = yes; } + + pub fn is_primary(&self) -> bool { + self.is_primary + } } /// Tags that can be associated with an annotation. diff --git a/crates/ty_server/src/server/api/diagnostics.rs b/crates/ty_server/src/server/api/diagnostics.rs index d25e6f5243..3344738cbf 100644 --- a/crates/ty_server/src/server/api/diagnostics.rs +++ b/crates/ty_server/src/server/api/diagnostics.rs @@ -349,6 +349,7 @@ pub(super) fn to_lsp_diagnostic( sub_diagnostic .annotations() .iter() + .filter(|annotation| !annotation.is_primary()) .filter_map(|annotation| { annotation_to_related_information(db, annotation, encoding) }),