Fix syntax map bug with combined injections inside of other injections

This commit is contained in:
Max Brunsfeld 2023-06-12 17:32:12 -07:00
parent ac1882b99b
commit 01bd5c30fc
2 changed files with 37 additions and 0 deletions

View file

@ -541,6 +541,15 @@ impl SyntaxSnapshot {
.to_ts_point(); .to_ts_point();
} }
if included_ranges.is_empty() {
included_ranges.push(tree_sitter::Range {
start_byte: 0,
end_byte: 0,
start_point: Default::default(),
end_point: Default::default(),
});
}
if let Some(SyntaxLayerContent::Parsed { tree: old_tree, .. }) = if let Some(SyntaxLayerContent::Parsed { tree: old_tree, .. }) =
old_layer.map(|layer| &layer.content) old_layer.map(|layer| &layer.content)
{ {

View file

@ -655,6 +655,34 @@ fn test_combined_injections_inside_injections() {
); );
} }
#[gpui::test]
fn test_empty_combined_injections_inside_injections() {
let (buffer, syntax_map) = test_edit_sequence(
"Markdown",
&[r#"
```erb
hello
```
goodbye
"#],
);
assert_layers_for_range(
&syntax_map,
&buffer,
Point::new(0, 0)..Point::new(5, 0),
&[
"...(paragraph)...",
"(template...",
"(fragment...",
// The ruby syntax tree should be empty, since there are
// no interpolations in the ERB template.
"(program)",
],
);
}
#[gpui::test(iterations = 50)] #[gpui::test(iterations = 50)]
fn test_random_syntax_map_edits(mut rng: StdRng) { fn test_random_syntax_map_edits(mut rng: StdRng) {
let operations = env::var("OPERATIONS") let operations = env::var("OPERATIONS")