🏡 index : ~doyle/rgit.git

author Jordan Doyle <jordan@doyle.la> 2024-09-30 4:55:59.0 +04:00:00
committer Jordan Doyle <jordan@doyle.la> 2024-09-30 4:55:59.0 +04:00:00
commit
2f4b3fa3fbe2863d1113856158be648a693b1790 [patch]
tree
30229ed215810c2f5e1bb0552e8a863cb7f607b1
parent
50523442c15afc9d0b459eef243dcd1630287063
download
2f4b3fa3fbe2863d1113856158be648a693b1790.tar.gz

Fix incorrectly anchored matches on highlighter injection



Diff

 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<Self> {
                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]);
                        }
                    }
                });