on master help sign in
Replace '; inherits <language>' in treesitter queries with <language> queries instead of appending them (#2470)
b6c700fPhilipp Mildenberger
helix-core/src/syntax.rs+6−20
@@ -328,29 +328,15 @@ fn read_query(language: &str, filename: &str) -> String {
328
328
329 let query = load_runtime_file(language, filename).unwrap_or_default();
329 let query = load_runtime_file(language, filename).unwrap_or_default();
330
330
331− // TODO: the collect() is not ideal
331+ // replaces all "; inherits <language>(,<language>)*" with the queries of the given language(s)
332− let inherits = INHERITS_REGEX
332+ INHERITS_REGEX
333− .captures_iter(&query)
333+ .replace_all(&query, |captures: &regex::Captures| {
334− .flat_map(|captures| {
335 captures[1]
334 captures[1]
336 .split(',')
335 .split(',')
337− .map(str::to_owned)
336+ .map(|language| format!("\n{}\n", read_query(language, filename)))
338− .collect::<Vec<_>>()
337+ .collect::<String>()
339 })
338 })
340− .collect::<Vec<_>>();
339+ .to_string()
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()
354}
340}
355
341
356impl LanguageConfiguration {
342impl LanguageConfiguration {
runtime/queries/tsq/highlights.scm+1−1
@@ -5,7 +5,7 @@
5 (#eq? @function "#match?"))
5 (#eq? @function "#match?"))
6
6
7; highlight inheritance comments
7; highlight inheritance comments
8−((query . (comment) @keyword.directive)
8+(((comment) @keyword.directive)
9 (#match? @keyword.directive "^; +inherits *:"))
9 (#match? @keyword.directive "^; +inherits *:"))
10
10
11[
11[