From 5ab1ae1521be69c704afbf39e8ad6fce0abf7698 Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 18 May 2023 11:59:59 -0400 Subject: [PATCH] Avoid panic in `get_injections` --- crates/language/src/syntax_map.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rs index 88de8e690a..ce1196e946 100644 --- a/crates/language/src/syntax_map.rs +++ b/crates/language/src/syntax_map.rs @@ -1114,6 +1114,8 @@ fn get_injections( let mut query_cursor = QueryCursorHandle::new(); let mut prev_match = None; + // Ensure that a `ParseStep` is created for every combined injection language, even + // if there currently no matches for that injection. combined_injection_ranges.clear(); for pattern in &config.patterns { if let (Some(language_name), true) = (pattern.language.as_ref(), pattern.combined) { @@ -1174,8 +1176,8 @@ fn get_injections( if let Some(language) = language { if combined { combined_injection_ranges - .get_mut(&language.clone()) - .unwrap() + .entry(language.clone()) + .or_default() .extend(content_ranges); } else { queue.push(ParseStep {