From 209b1d19313a01db9a0a79d4bc644a80f1e22b7b Mon Sep 17 00:00:00 2001 From: Gilles Peiffer Date: Thu, 27 Jun 2024 08:40:48 +0200 Subject: [PATCH] Code maintenance in the `editor` crate (#13565) Release Notes: - N/A --- crates/editor/src/display_map.rs | 25 +++++++++++++------------ crates/editor/src/editor.rs | 30 +++++++++--------------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index 3eb9b28e6a..1da5201237 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -720,8 +720,7 @@ impl DisplaySnapshot { 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_color = - super::diagnostic_style(severity, true, &editor_style.status); + let diagnostic_color = super::diagnostic_style(severity, &editor_style.status); diagnostic_highlight.underline = Some(UnderlineStyle { color: Some(diagnostic_color), thickness: 1.0.into(), @@ -957,16 +956,18 @@ impl DisplaySnapshot { return false; } - for next_row in (buffer_row.0 + 1)..=max_row.0 { - let next_line_indent = self.line_indent_for_buffer_row(MultiBufferRow(next_row)); - if next_line_indent.raw_len() > line_indent.raw_len() { - return true; - } else if !next_line_indent.is_line_blank() { - break; - } - } - - false + (buffer_row.0 + 1..=max_row.0) + .find_map(|next_row| { + let next_line_indent = self.line_indent_for_buffer_row(MultiBufferRow(next_row)); + if next_line_indent.raw_len() > line_indent.raw_len() { + Some(true) + } else if !next_line_indent.is_line_blank() { + Some(false) + } else { + None + } + }) + .unwrap_or(false) } pub fn foldable_range( diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c23daf2296..c3cf05a8f0 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -8816,13 +8816,7 @@ impl Editor { let display_point = initial_point.to_display_point(snapshot); let mut hunks = hunks .map(|hunk| diff_hunk_to_display(&hunk, &snapshot)) - .filter(|hunk| { - if is_wrapped { - true - } else { - !hunk.contains_display_row(display_point.row()) - } - }) + .filter(|hunk| is_wrapped || !hunk.contains_display_row(display_point.row())) .dedup(); if let Some(hunk) = hunks.next() { @@ -12521,7 +12515,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, _is_valid: bool) -> Ren let group_id: SharedString = cx.block_id.to_string().into(); let mut text_style = cx.text_style().clone(); - text_style.color = diagnostic_style(diagnostic.severity, true, cx.theme().status()); + text_style.color = diagnostic_style(diagnostic.severity, cx.theme().status()); let theme_settings = ThemeSettings::get_global(cx); text_style.font_family = theme_settings.buffer_font.family.clone(); text_style.font_style = theme_settings.buffer_font.style; @@ -12617,25 +12611,19 @@ pub fn highlight_diagnostic_message(diagnostic: &Diagnostic) -> (SharedString, V prev_offset = ix + 1; if in_code_block { code_ranges.push(prev_len..text_without_backticks.len()); - in_code_block = false; - } else { - in_code_block = true; } + in_code_block = !in_code_block; } (text_without_backticks.into(), code_ranges) } -fn diagnostic_style(severity: DiagnosticSeverity, valid: bool, colors: &StatusColors) -> Hsla { - match (severity, valid) { - (DiagnosticSeverity::ERROR, true) => colors.error, - (DiagnosticSeverity::ERROR, false) => colors.error, - (DiagnosticSeverity::WARNING, true) => colors.warning, - (DiagnosticSeverity::WARNING, false) => colors.warning, - (DiagnosticSeverity::INFORMATION, true) => colors.info, - (DiagnosticSeverity::INFORMATION, false) => colors.info, - (DiagnosticSeverity::HINT, true) => colors.info, - (DiagnosticSeverity::HINT, false) => colors.info, +fn diagnostic_style(severity: DiagnosticSeverity, colors: &StatusColors) -> Hsla { + match severity { + DiagnosticSeverity::ERROR => colors.error, + DiagnosticSeverity::WARNING => colors.warning, + DiagnosticSeverity::INFORMATION => colors.info, + DiagnosticSeverity::HINT => colors.info, _ => colors.ignored, } }