Repository: helix-editor/helix
File: helix-term/src/ui/completion.rs (Rust)

Code before:
                        None => None,
                    };

                    let content = maybe_hex_color.map_or(Span::raw("color"), |hex_color| {
                        let maybe_color = match (
                            hex_color
                                .get(1..=2)
                                .and_then(|r| u8::from_str_radix(r, 16).ok()),
                            hex_color
                                .get(3..=4)
                                .and_then(|g| u8::from_str_radix(g, 16).ok()),
                            hex_color
                                .get(5..=6)
                                .and_then(|b| u8::from_str_radix(b, 16).ok()),
                        ) {
                            (Some(r), Some(g), Some(b)) => Some(Color::Rgb(r, g, b)),
                            _ => None,
                        };

                        match maybe_color {
                            Some(color) => Span::styled("        ", Style::default().bg(color)),
                            None => Span::raw("color"),
                        }
                    });

                    return menu::Row::new([first_cell, menu::Cell::from(content)]);
                }
                Some(lsp::CompletionItemKind::FILE) => "file",
                Some(lsp::CompletionItemKind::REFERENCE) => "reference",
                Some(lsp::CompletionItemKind::FOLDER) => "folder",
                Some(lsp::CompletionItemKind::ENUM_MEMBER) => "enum_member",
                Some(lsp::CompletionItemKind::CONSTANT) => "constant",
                Some(lsp::CompletionItemKind::STRUCT) => "struct",
                Some(lsp::CompletionItemKind::EVENT) => "event",
                Some(lsp::CompletionItemKind::OPERATOR) => "operator",
                Some(lsp::CompletionItemKind::TYPE_PARAMETER) => "type_param",
                Some(kind) => {
                    log::error!("Received unknown completion item kind: {:?}", kind);
                    ""
                }
                None => "",
            },
            CompletionItem::Other(core::CompletionItem { kind, .. }) => kind,
        };

        menu::Row::new([first_cell, menu::Cell::from(kind)])
    }
}

/// Wraps a Menu.
pub struct Completion {

Review comment (refactor):
I prefered the `.into()` from earlier in the PR. Returning here makes the change smaller but this block becomes harder to follow and we duplicate the definition of the row

Code after:
                        ])
                    }),
                Some(lsp::CompletionItemKind::FILE) => "file".into(),
                Some(lsp::CompletionItemKind::REFERENCE) => "reference".into(),
                Some(lsp::CompletionItemKind::FOLDER) => "folder".into(),
                Some(lsp::CompletionItemKind::ENUM_MEMBER) => "enum_member".into(),
                Some(lsp::CompletionItemKind::CONSTANT) => "constant".into(),
                Some(lsp::CompletionItemKind::STRUCT) => "struct".into(),
                Some(lsp::CompletionItemKind::EVENT) => "event".into(),
                Some(lsp::CompletionItemKind::OPERATOR) => "operator".into(),
                Some(lsp::CompletionItemKind::TYPE_PARAMETER) => "type_param".into(),
                Some(kind) => {
                    log::error!("Received unknown completion item kind: {:?}", kind);
                    "".into()
                }
                None => "".into(),
            },
            CompletionItem::Other(core::CompletionItem { kind, .. }) => kind.as_ref().into(),
        };

        let label = Span::styled(
            label,
            if deprecated {
                Style::default().add_modifier(Modifier::CROSSED_OUT)
            } else if kind.0[0].content == "folder" {
                *dir_style
            } else {
                Style::default()
            },
        );

        menu::Row::new([menu::Cell::from(label), menu::Cell::from(kind)])
    }
}

/// Wraps a Menu.
pub struct Completion {
    popup: Popup<Menu<CompletionItem>>,
    #[allow(dead_code)]
    trigger_offset: usize,
    filter: String,
    resolve_handler: ResolveHandler,
}

impl Completion {
    pub const ID: &'static str = "completion";

    pub fn new(
        editor: &Editor,
        savepoint: Arc<SavePoint>,
        mut items: Vec<CompletionItem>,