From 6fd1efd1c29f4c0dbdab3a82d961fd5456e0cb1c Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 13 Jul 2025 13:10:58 -0400 Subject: [PATCH] Gracefully handle highlighter bugs in the markdown component Since tree-house is young and we've seen a few bugs that make it go backwards, we should handle this case gracefully and just give up on syntax highlighting with an error log. --- helix-term/src/ui/markdown.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index ae58d75e8..6bef59d14 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -90,7 +90,13 @@ pub fn highlighted_code_block<'a>( if pos == start { continue; } - assert!(pos > start); + // The highlighter should always move forward. + // If the highlighter malfunctions, bail on syntax highlighting and log an error. + debug_assert!(pos > start); + if pos < start { + log::error!("Failed to highlight '{language}': {text:?}"); + return styled_multiline_text(text, code_style); + } let style = syntax_highlight_stack .iter()