fix: unable to detect Color completion item hex code for some LSPs (#12501)

Co-authored-by: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com>
This commit is contained in:
Nikita Revenco 2025-01-12 15:40:19 +00:00 committed by GitHub
parent 0f2ce303c5
commit e01775a667
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -92,8 +92,11 @@ impl menu::Item for CompletionItem {
value, ..
}) => value,
};
Color::from_hex(text)
// Language servers which send Color completion items tend to include a 6
// digit hex code at the end for the color. The extra 1 digit is for the '#'
text.get(text.len().checked_sub(7)?..)
})
.and_then(Color::from_hex)
.map_or("color".into(), |color| {
Spans::from(vec![
Span::raw("color "),