1use crate::Theme;
2use crate::font;
3use crate::text::highlighter;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum Code {
8 Comment,
10 String,
12 Keyword,
14 Constant,
16 Function,
18 Type,
20 Variable,
22 Support,
24 Punctuation,
26 Path,
28 Invalid,
30 Other,
32}
33
34impl Code {
35 pub fn highlight(self, theme: &Theme) -> highlighter::Style {
37 let palette = theme.palette();
38
39 let color = match self {
40 Code::Keyword => Some(palette.primary.base.color),
41 Code::Type | Code::Path | Code::Function => Some(palette.warning.base.color),
42
43 Code::Variable => Some(palette.danger.base.color),
44 Code::Constant => Some(palette.danger.base.color),
45 Code::String => Some(palette.success.base.color),
46 Code::Support => Some(palette.primary.base.color),
47
48 Code::Punctuation => Some(palette.secondary.strong.color),
49 Code::Comment => Some(palette.secondary.base.color),
50
51 Code::Invalid => Some(palette.danger.base.color),
52 Code::Other => None,
53 };
54
55 highlighter::Style {
56 color,
57 style: (self == Code::Comment).then_some(font::Style::Italic),
58 }
59 }
60}