From a65dba181bdeb7f6a89a43d54fac55fea8d46d07 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sun, 12 Jan 2025 08:49:19 +0000 Subject: [PATCH 1/4] fix: check for the color pattern against the end --- helix-term/src/ui/completion.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index adacfad330f4..f5b547f09c4d 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -92,8 +92,9 @@ impl menu::Item for CompletionItem { value, .. }) => value, }; - Color::from_hex(text) + text.get(text.len() - 7..) }) + .and_then(Color::from_hex) .map_or("color".into(), |color| { Spans::from(vec![ Span::raw("color "), From ed66e7e104a42e6701ed687115da484bb68564b1 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Sun, 12 Jan 2025 11:57:39 +0000 Subject: [PATCH 2/4] chore: add docs --- helix-term/src/ui/completion.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index f5b547f09c4d..7ec7d434a0f2 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -92,6 +92,7 @@ impl menu::Item for CompletionItem { value, .. }) => value, }; + // LSPs which send Color completion items include a 6 digit hex code at the end for the color. The extra 1 digit is for the '#' text.get(text.len() - 7..) }) .and_then(Color::from_hex) From 49c7844a6e88ae150c9c31d5dd1d8634e449a9e5 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nik-rev@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:21:12 +0000 Subject: [PATCH 3/4] fix: fix potential underflow Co-authored-by: Michael Davis --- helix-term/src/ui/completion.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index 7ec7d434a0f2..e7dedaf590e3 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -93,7 +93,7 @@ impl menu::Item for CompletionItem { }) => value, }; // LSPs which send Color completion items include a 6 digit hex code at the end for the color. The extra 1 digit is for the '#' - text.get(text.len() - 7..) + text.get(text.len().checked_sub(7)?..) }) .and_then(Color::from_hex) .map_or("color".into(), |color| { From 5d9ce3abf2d0487fc358c29685aab79b071ca876 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+nik-rev@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:21:34 +0000 Subject: [PATCH 4/4] chore: improve wording in comment Co-authored-by: Michael Davis --- helix-term/src/ui/completion.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/completion.rs b/helix-term/src/ui/completion.rs index e7dedaf590e3..030085af9a79 100644 --- a/helix-term/src/ui/completion.rs +++ b/helix-term/src/ui/completion.rs @@ -92,7 +92,8 @@ impl menu::Item for CompletionItem { value, .. }) => value, }; - // LSPs which send Color completion items include a 6 digit hex code at the end for the color. The extra 1 digit is for the '#' + // 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)