+ <%= yield :five %> +
+ <% elsif Six.seven(8) %> ++ <%= yield :five %> +
+ <% else %> + Ok + <% end %> +diff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rs index 0a8919d6a348631137927cfb9d681bdad70e9f1f..711a65c3e9424e59ce1bad597a1bf85ef2bc9560 100644 --- a/crates/language/src/syntax_map.rs +++ b/crates/language/src/syntax_map.rs @@ -236,12 +236,12 @@ impl SyntaxSnapshot { // Preserve any layers at this depth that precede the first edit. if let Some((_, edit_range)) = edits.get(first_edit_ix_for_depth) { - let position = ChangeStartPosition { + let target = ChangeStartPosition { depth, position: edit_range.start, }; - if position.cmp(&cursor.start(), text).is_gt() { - let slice = cursor.slice(&position, Bias::Left, text); + if target.cmp(&cursor.start(), text).is_gt() { + let slice = cursor.slice(&target, Bias::Left, text); layers.push_tree(slice, text); } } @@ -261,24 +261,17 @@ impl SyntaxSnapshot { continue; }; - let layer = if let Some(layer) = cursor.item() { - layer - } else { - break; - }; + let Some(layer) = cursor.item() else { break }; let (start_byte, start_point) = layer.range.start.summary::<(usize, Point)>(text); // Ignore edits that end before the start of this layer, and don't consider them // for any subsequent layers at this same depth. loop { - if let Some((_, edit_range)) = edits.get(first_edit_ix_for_depth) { - if edit_range.end.cmp(&layer.range.start, text).is_le() { - first_edit_ix_for_depth += 1; - } else { - break; - } + let Some((_, edit_range)) = edits.get(first_edit_ix_for_depth) else { continue 'outer }; + if edit_range.end.cmp(&layer.range.start, text).is_le() { + first_edit_ix_for_depth += 1; } else { - continue 'outer; + break; } } @@ -1895,7 +1888,7 @@ mod tests { ); } - #[gpui::test(iterations = 100)] + #[gpui::test(iterations = 50)] fn test_random_syntax_map_edits(mut rng: StdRng) { let operations = env::var("OPERATIONS") .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) @@ -1975,6 +1968,89 @@ mod tests { } } + #[gpui::test(iterations = 50)] + fn test_random_syntax_map_edits_with_combined_injections(mut rng: StdRng) { + let operations = env::var("OPERATIONS") + .map(|i| i.parse().expect("invalid `OPERATIONS` variable")) + .unwrap_or(10); + + let text = r#" +
+ <%= yield :five %> +
+ <% elsif Six.seven(8) %> ++ <%= yield :five %> +
+ <% else %> + Ok + <% end %> +