mirror of https://github.com/helix-editor/helix
Fix nondeterministic highlighting (#3275)
* Fix nondeterministic highlighting This is done by prefering matches in the begining, ie for `keyword.function`, `keyword` is a better match than `function`. * Use all positions and not just leftmost Fixes possible edgecase with something like `function.method.builtin` and the queries `function.builtin` and `function.method` * Switch to bitmask for slightly better performance * Make matches from the start of string Also change comments to match new behaviourpull/3340/head
parent
f32c05db85
commit
cfa882557e
|
@ -1356,8 +1356,8 @@ impl HighlightConfiguration {
|
||||||
/// Tree-sitter syntax-highlighting queries specify highlights in the form of dot-separated
|
/// Tree-sitter syntax-highlighting queries specify highlights in the form of dot-separated
|
||||||
/// highlight names like `punctuation.bracket` and `function.method.builtin`. Consumers of
|
/// highlight names like `punctuation.bracket` and `function.method.builtin`. Consumers of
|
||||||
/// these queries can choose to recognize highlights with different levels of specificity.
|
/// these queries can choose to recognize highlights with different levels of specificity.
|
||||||
/// For example, the string `function.builtin` will match against `function.method.builtin`
|
/// For example, the string `function.builtin` will match against `function.builtin.constructor`
|
||||||
/// and `function.builtin.constructor`, but will not match `function.method`.
|
/// but will not match `function.method.builtin` and `function.method`.
|
||||||
///
|
///
|
||||||
/// When highlighting, results are returned as `Highlight` values, which contain the index
|
/// When highlighting, results are returned as `Highlight` values, which contain the index
|
||||||
/// of the matched highlight this list of highlight names.
|
/// of the matched highlight this list of highlight names.
|
||||||
|
@ -1377,13 +1377,15 @@ impl HighlightConfiguration {
|
||||||
let recognized_name = recognized_name;
|
let recognized_name = recognized_name;
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
let mut matches = true;
|
let mut matches = true;
|
||||||
for part in recognized_name.split('.') {
|
for (i, part) in recognized_name.split('.').enumerate() {
|
||||||
len += 1;
|
match capture_parts.get(i) {
|
||||||
if !capture_parts.contains(&part) {
|
Some(capture_part) if *capture_part == part => len += 1,
|
||||||
|
_ => {
|
||||||
matches = false;
|
matches = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if matches && len > best_match_len {
|
if matches && len > best_match_len {
|
||||||
best_index = Some(i);
|
best_index = Some(i);
|
||||||
best_match_len = len;
|
best_match_len = len;
|
||||||
|
|
Loading…
Reference in New Issue