Skip to content

Commit

Permalink
Replace '; inherits <language>' in treesitter queries with <language>…
Browse files Browse the repository at this point in the history
… queries instead of appending them (helix-editor#2470)

Co-authored-by: Blaž Hrastnik <[email protected]>
  • Loading branch information
2 people authored and thomasskk committed Sep 9, 2022
1 parent 0a02849 commit fd6717f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
26 changes: 6 additions & 20 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: &regex::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 {
Expand Down
2 changes: 1 addition & 1 deletion runtime/queries/tsq/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(#eq? @function "#match?"))

; highlight inheritance comments
((query . (comment) @keyword.directive)
(((comment) @keyword.directive)
(#match? @keyword.directive "^; +inherits *:"))

[
Expand Down

0 comments on commit fd6717f

Please sign in to comment.