]> git.lizzy.rs Git - rust.git/commitdiff
Fix incorrect order of syntax highlight ranges
authorLeander Tentrup <leander.tentrup@gmail.com>
Fri, 17 Apr 2020 20:23:23 +0000 (22:23 +0200)
committerLeander Tentrup <leander.tentrup@gmail.com>
Fri, 17 Apr 2020 20:50:30 +0000 (22:50 +0200)
crates/ra_ide/src/syntax_highlighting.rs
crates/ra_ide/src/syntax_highlighting/tests.rs

index 83d161f45ac4d03617e1caf890932effe4b72753..7b15b82bdb6d4bb7333b15f4811673dcb69753db 100644 (file)
@@ -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()
index 110887c2ac4230aa21eec5b056788eae676f8323..73611e23a5a50c397a2dc3762e1015aba6be5c9e 100644 (file)
@@ -156,3 +156,15 @@ fn foo() {
     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();
+}