Skip to content

Commit b6c700f

Browse files
Philipp-Marchseer
andauthored
Replace '; inherits <language>' in treesitter queries with <language> queries instead of appending them (#2470)
Co-authored-by: Blaž Hrastnik <[email protected]>
1 parent 52bb110 commit b6c700f

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

helix-core/src/syntax.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

356342
impl LanguageConfiguration {

runtime/queries/tsq/highlights.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
[

0 commit comments

Comments
 (0)