diff options
author | Philipp Mildenberger | 2022-07-22 01:28:32 +0000 |
---|---|---|
committer | GitHub | 2022-07-22 01:28:32 +0000 |
commit | b6c700fce9c13d883578f9cc5e81d624e9fbd9f8 (patch) | |
tree | b5660b461dedf95de41232390abc8ea8844a5a90 /helix-core | |
parent | 52bb1103f8137e5f7c42de6f79c13e2bfbcf7490 (diff) |
Replace '; inherits <language>' in treesitter queries with <language> queries instead of appending them (#2470)
Co-authored-by: Blaž Hrastnik <blaz@mxxn.io>
Diffstat (limited to 'helix-core')
-rw-r--r-- | helix-core/src/syntax.rs | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 8d7520c3..9011f835 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -328,29 +328,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 <language>(,<language>)*" with the queries of the given language(s) + INHERITS_REGEX + .replace_all(&query, |captures: ®ex::Captures| { captures[1] .split(',') - .map(str::to_owned) - .collect::<Vec<_>>() + .map(|language| format!("\n{}\n", read_query(language, filename))) + .collect::<String>() }) - .collect::<Vec<_>>(); - - if inherits.is_empty() { - return query; - } - - let mut queries = inherits - .iter() - .map(|language| read_query(language, filename)) - .collect::<Vec<_>>(); - - queries.push(query); - - queries.concat() + .to_string() } impl LanguageConfiguration { |