From ca5c96b98261b79eddf81598f0b24c798f374209 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:54:12 +0000 Subject: [PATCH] refactor: use let else statement --- helix-term/src/commands/lsp.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index fdd17d0e..cc585e82 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -1439,9 +1439,9 @@ fn compute_color_swatches_for_view( // Don't recompute the color swatches in case nothing has changed about the view if !doc.color_swatches_outdated - && doc - .color_swatches(view_id) - .map_or(false, |dih| dih.id == new_doc_color_swatches_id) + && doc.color_swatches(view_id).map_or(false, |color_swatches| { + color_swatches.id == new_doc_color_swatches_id + }) { return None; } @@ -1475,27 +1475,24 @@ fn compute_color_swatches_for_view( } }; - // Most language servers will already send them sorted but ensure this is the case to - // avoid errors on our end. + // Most language servers will already send them sorted but ensure this is the case to avoid errors on our end. swatches.sort_by_key(|inlay_hint| inlay_hint.range.start); let mut color_swatches = Vec::with_capacity(swatches.len()); + // let mut color_swatches_padding = Vec::with_capacity(swatches.len()); let mut colors = Vec::with_capacity(swatches.len()); let doc_text = doc.text(); for swatch in swatches { - let char_idx = match helix_lsp::util::lsp_pos_to_pos( - doc_text, - swatch.range.start, - offset_encoding, - ) { - Some(pos) => pos, + let Some(swatch_index) = + helix_lsp::util::lsp_pos_to_pos(doc_text, swatch.range.start, offset_encoding) + else { // Skip color swatches that have no "real" position - None => continue, + continue; }; - color_swatches.push(InlineAnnotation::new(char_idx, "■ ")); + color_swatches.push(InlineAnnotation::new(swatch_index, "■ ")); colors.push(Color::Rgb( (swatch.color.red * 255.) as u8, (swatch.color.green * 255.) as u8,