on master help sign in
Replace '; inherits <language>' in treesitter queries with <language> queries instead of appending them (#2470)

Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>

commitb6c700fce9c13d883578f9cc5e81d624e9fbd9f8 authorPhilipp Mildenberger <philipp@mildenberger.me> dateFri 22 Jul 2022, 03:28 (4 years ago) parent52bb110
2 files changed+7−21
helix-core/src/syntax.rs+6−20 runtime/queries/tsq/highlights.scm+1−1
helix-core/src/syntax.rs+6−20
@@ -328,29 +328,15 @@ fn read_query(language: &str, filename: &str) -> String {
328328
329329 let query = load_runtime_file(language, filename).unwrap_or_default();
330330
331− // TODO: the collect() is not ideal
332− let inherits = INHERITS_REGEX
333− .captures_iter(&query)
334− .flat_map(|captures| {
331+ // replaces all "; inherits <language>(,<language>)*" with the queries of the given language(s)
332+ INHERITS_REGEX
333+ .replace_all(&query, |captures: &regex::Captures| {
335334 captures[1]
336335 .split(',')
337− .map(str::to_owned)
338− .collect::<Vec<_>>()
336+ .map(|language| format!("\n{}\n", read_query(language, filename)))
337+ .collect::<String>()
339338 })
340− .collect::<Vec<_>>();
341−
342− if inherits.is_empty() {
343− return query;
344− }
345−
346− let mut queries = inherits
347− .iter()
348− .map(|language| read_query(language, filename))
349− .collect::<Vec<_>>();
350−
351− queries.push(query);
352−
353− queries.concat()
339+ .to_string()
354340}
355341
356342impl LanguageConfiguration {
runtime/queries/tsq/highlights.scm+1−1
@@ -5,7 +5,7 @@
55 (#eq? @function "#match?"))
66
77; highlight inheritance comments
8−((query . (comment) @keyword.directive)
8+(((comment) @keyword.directive)
99 (#match? @keyword.directive "^; +inherits *:"))
1010
1111[