diff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rs index 03c3eff1a9..7e5664c1bd 100644 --- a/crates/language/src/syntax_map.rs +++ b/crates/language/src/syntax_map.rs @@ -541,6 +541,15 @@ impl SyntaxSnapshot { .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, .. }) = old_layer.map(|layer| &layer.content) { diff --git a/crates/language/src/syntax_map/syntax_map_tests.rs b/crates/language/src/syntax_map/syntax_map_tests.rs index f8d63b2a4f..57b5cd4a8c 100644 --- a/crates/language/src/syntax_map/syntax_map_tests.rs +++ b/crates/language/src/syntax_map/syntax_map_tests.rs @@ -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)] fn test_random_syntax_map_edits(mut rng: StdRng) { let operations = env::var("OPERATIONS")