From 2e2c03ee2d7ef20fd6e20151507d26a4407c835e Mon Sep 17 00:00:00 2001 From: Leander Tentrup Date: Fri, 17 Apr 2020 22:23:23 +0200 Subject: Fix incorrect order of syntax highlight ranges --- crates/ra_ide/src/syntax_highlighting.rs | 3 ++- crates/ra_ide/src/syntax_highlighting/tests.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 83d161f45..7b15b82bd 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -174,7 +174,8 @@ pub(crate) fn highlight( } assert_eq!(res.len(), 1, "after DFS traversal, the stack should only contain a single element"); - let res = res.pop().unwrap(); + let mut res = res.pop().unwrap(); + res.sort_by_key(|range| range.range.start()); // Check that ranges are sorted and disjoint assert!(res .iter() diff --git a/crates/ra_ide/src/syntax_highlighting/tests.rs b/crates/ra_ide/src/syntax_highlighting/tests.rs index 110887c2a..73611e23a 100644 --- a/crates/ra_ide/src/syntax_highlighting/tests.rs +++ b/crates/ra_ide/src/syntax_highlighting/tests.rs @@ -156,3 +156,15 @@ fn main() { fs::write(dst_file, &actual_html).unwrap(); assert_eq_text!(expected_html, actual_html); } + +#[test] +fn ranges_sorted() { + let (analysis, file_id) = single_file( + r#" +#[foo(bar = "bar")] +macro_rules! test {} +}"# + .trim(), + ); + let _ = analysis.highlight(file_id).unwrap(); +} -- cgit v1.2.3