From 70495c1c95476a872b259b93a0766053f049a88b Mon Sep 17 00:00:00 2001 From: Philipp Mildenberger Date: Sat, 14 May 2022 14:29:51 +0200 Subject: [PATCH] Replace '; inherits ' in treesitter queries with queries instead of appending them --- helix-core/src/syntax.rs | 26 ++++++-------------------- runtime/queries/tsq/highlights.scm | 2 +- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index b20d9092fae0..cffc58047d97 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -331,29 +331,15 @@ fn read_query(language: &str, filename: &str) -> String { let query = load_runtime_file(language, filename).unwrap_or_default(); - // TODO: the collect() is not ideal - let inherits = INHERITS_REGEX - .captures_iter(&query) - .flat_map(|captures| { + // replaces all "; inherits (,)*" with the queries of the given language(s) + INHERITS_REGEX + .replace_all(&query, |captures: ®ex::Captures| { captures[1] .split(',') - .map(str::to_owned) - .collect::>() + .map(|language| format!("\n{}\n", read_query(language, filename))) + .collect::() }) - .collect::>(); - - if inherits.is_empty() { - return query; - } - - let mut queries = inherits - .iter() - .map(|language| read_query(language, filename)) - .collect::>(); - - queries.push(query); - - queries.concat() + .to_string() } impl LanguageConfiguration { diff --git a/runtime/queries/tsq/highlights.scm b/runtime/queries/tsq/highlights.scm index 549895c15598..f7920d858b5a 100644 --- a/runtime/queries/tsq/highlights.scm +++ b/runtime/queries/tsq/highlights.scm @@ -5,7 +5,7 @@ (#eq? @function "#match?")) ; highlight inheritance comments -((query . (comment) @keyword.directive) +(((comment) @keyword.directive) (#match? @keyword.directive "^;\ +inherits *:")) [