Skip to content

Commit 746b2e0

Browse files
bors[bot]ltentrup
andauthored
Merge #4022
4022: Fix incorrect order of syntax highlight ranges r=ltentrup a=ltentrup A fix for the bug #4013 which is caused by a difference between tree traversal order and text representation order. In the case of #4013, the attributes of a macro were visited after the macro definition which caused the syntax highlight ranges to be in wrong order. The fix is to sort the ranges before returning. Co-authored-by: Leander Tentrup <[email protected]>
2 parents 8a4ceba + 2e2c03e commit 746b2e0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crates/ra_ide/src/syntax_highlighting.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ pub(crate) fn highlight(
174174
}
175175

176176
assert_eq!(res.len(), 1, "after DFS traversal, the stack should only contain a single element");
177-
let res = res.pop().unwrap();
177+
let mut res = res.pop().unwrap();
178+
res.sort_by_key(|range| range.range.start());
178179
// Check that ranges are sorted and disjoint
179180
assert!(res
180181
.iter()

crates/ra_ide/src/syntax_highlighting/tests.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,15 @@ fn main() {
156156
fs::write(dst_file, &actual_html).unwrap();
157157
assert_eq_text!(expected_html, actual_html);
158158
}
159+
160+
#[test]
161+
fn ranges_sorted() {
162+
let (analysis, file_id) = single_file(
163+
r#"
164+
#[foo(bar = "bar")]
165+
macro_rules! test {}
166+
}"#
167+
.trim(),
168+
);
169+
let _ = analysis.highlight(file_id).unwrap();
170+
}

0 commit comments

Comments
 (0)