From 2f4b3fa3fbe2863d1113856158be648a693b1790 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Mon, 30 Sep 2024 04:55:59 +0400 Subject: [PATCH] Fix incorrectly anchored matches on highlighter injection --- tree-sitter-grammar-repository/build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tree-sitter-grammar-repository/build.rs b/tree-sitter-grammar-repository/build.rs index 8ef7664..c535cf1 100644 --- a/tree-sitter-grammar-repository/build.rs +++ a/tree-sitter-grammar-repository/build.rs @@ -125,6 +125,7 @@ let mut injection_regex = Vec::new(); let mut injection_regex_str_len = Vec::new(); + let mut regex_to_camel = Vec::new(); for language in &language_definition { if BLACKLISTED_MODULES.contains(&language.name.as_str()) { @@ -150,8 +151,9 @@ } if let Some(regex) = language.injection_regex.as_deref() { - injection_regex.push(regex); + injection_regex.push(format!("^{regex}$")); injection_regex_str_len.push(regex.len()); + regex_to_camel.push(camel_cased_name.clone()); } } @@ -208,6 +210,7 @@ pub fn from_injection(name: &str) -> Option { const LENGTHS: [usize; #injection_regex_len] = [#(#injection_regex_str_len),*]; + const REGEX_TO_VARIANT: [Language; #injection_regex_len] = [#(Language::#regex_to_camel),*]; thread_local! { static REGEX: ::std::cell::LazyCell<::regex::RegexSet> = ::std::cell::LazyCell::new(|| { @@ -227,7 +230,7 @@ if curr_length < max { max = curr_length; - curr = Some(Self::VARIANTS[m]); + curr = Some(REGEX_TO_VARIANT[m]); } } }); -- rgit 0.1.3