Skip to content

Commit 878e9a3

Browse files
committed
Support #rgb format in document color
1 parent 9e68126 commit 878e9a3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/emmylua_ls/src/handlers/document_color/build_color.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ fn try_build_color_information(
5151
let color_text = &text[i..j];
5252
if let Some(color) = parse_hex_color(color_text) {
5353
let source_text_range = token.text_range();
54+
let start = if bytes[i - 1] == b'#' { i - 1 } else { i };
5455
let text_range = TextRange::new(
55-
source_text_range.start() + TextSize::new(i as u32),
56+
source_text_range.start() + TextSize::new(start as u32),
5657
source_text_range.start() + TextSize::new(j as u32),
5758
);
5859
let lsp_range = document.to_lsp_range(text_range)?;
@@ -110,10 +111,15 @@ pub fn convert_color_to_hex(color: Color, len: usize) -> String {
110111
let b = (color.blue * 255.0).round() as u8;
111112
match len {
112113
6 => format!("{:02X}{:02X}{:02X}", r, g, b),
114+
7 => format!("#{:02X}{:02X}{:02X}", r, g, b),
113115
8 => {
114116
let a = (color.alpha * 255.0).round() as u8;
115117
format!("{:02X}{:02X}{:02X}{:02X}", r, g, b, a)
116118
}
119+
9 => {
120+
let a = (color.alpha * 255.0).round() as u8;
121+
format!("#{:02X}{:02X}{:02X}{:02X}", r, g, b, a)
122+
}
117123
_ => "".to_string(),
118124
}
119125
}

0 commit comments

Comments
 (0)