Skip to content

Commit 5c0fd31

Browse files
committed
Add a debug assertion for active_highlights ordering
1 parent 6128c5a commit 5c0fd31

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

highlighter/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edition = "2021"
1010
license = "MPL-2.0"
1111
repository = "https://github.com/helix-editor/tree-house"
1212
readme = "../README.md"
13-
rust-version = "1.76.0"
13+
rust-version = "1.82.0"
1414

1515
[features]
1616
default = ["fixtures"]

highlighter/src/highlighter.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,29 @@ impl<'a, 'tree: 'a, Loader: LanguageLoader> Highlighter<'a, 'tree, Loader> {
389389
});
390390
*first_highlight = false;
391391
}
392+
393+
// `active_highlights` must be a stack of highlight events the highlights stack on the
394+
// prior highlights in the Vec. Each highlight's range must be a subset of the highlight's
395+
// range before it.
396+
debug_assert!(
397+
{
398+
// The assertion is actually true for the entire stack but combined injections
399+
// throw a wrench in things: the highlight can end after the current injection.
400+
// The highlight is removed from `active_highlights` as the injection layer ends
401+
// so the wider assertion would be true in practice. We don't track the injection
402+
// end right here though so we can't assert on it.
403+
let layer_start = self
404+
.layer_states
405+
.get(&self.current_layer)
406+
.map(|layer| layer.parent_highlights)
407+
.unwrap_or_default();
408+
409+
self.active_highlights[layer_start..].is_sorted_by_key(|h| std::cmp::Reverse(h.end))
410+
},
411+
"unsorted highlights on layer {:?}: {:?}\nall active highlights must be sorted by `end` descending",
412+
self.current_layer,
413+
self.active_highlights,
414+
);
392415
}
393416
}
394417

0 commit comments

Comments
 (0)