From 76fc9c955e773bd28acfbc780937b77d9843c07b Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 15 Mar 2022 13:13:33 -0700 Subject: [PATCH] Restore underline for warnings about unused code --- crates/editor/src/editor.rs | 2 +- crates/editor/src/element.rs | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index a80af9ea5f..8c6904d136 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4211,7 +4211,7 @@ impl Editor { }; let group = diagnostics.find_map(|entry| { if entry.diagnostic.is_primary - && !entry.diagnostic.is_unnecessary + && entry.diagnostic.severity <= DiagnosticSeverity::WARNING && !entry.range.is_empty() && Some(entry.range.end) != active_primary_range.as_ref().map(|r| *r.end()) { diff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rs index 1aed9791c4..ad8057db4e 100644 --- a/crates/editor/src/element.rs +++ b/crates/editor/src/element.rs @@ -21,7 +21,7 @@ use gpui::{ MutableAppContext, PaintContext, Quad, Scene, SizeConstraint, ViewContext, WeakViewHandle, }; use json::json; -use language::Bias; +use language::{Bias, DiagnosticSeverity}; use smallvec::SmallVec; use std::{ cmp::{self, Ordering}, @@ -665,19 +665,22 @@ impl EditorElement { } } - let mut diagnostic_highlight = HighlightStyle { - ..Default::default() - }; + let mut diagnostic_highlight = HighlightStyle::default(); if chunk.is_unnecessary { diagnostic_highlight.fade_out = Some(style.unnecessary_code_fade); - } else if let Some(severity) = chunk.diagnostic_severity { - let diagnostic_style = super::diagnostic_style(severity, true, style); - diagnostic_highlight.underline = Some(Underline { - color: Some(diagnostic_style.message.text.color), - thickness: 1.0.into(), - squiggly: true, - }); + } + + if let Some(severity) = chunk.diagnostic_severity { + // Omit underlines for HINT/INFO diagnostics on 'unnecessary' code. + if severity <= DiagnosticSeverity::WARNING || !chunk.is_unnecessary { + let diagnostic_style = super::diagnostic_style(severity, true, style); + diagnostic_highlight.underline = Some(Underline { + color: Some(diagnostic_style.message.text.color), + thickness: 1.0.into(), + squiggly: true, + }); + } } if let Some(highlight_style) = highlight_style.as_mut() {