on master help sign in
Fix nondeterministic highlighting (#3275)
cfa8825A-Walrus
helix-core/src/syntax.rs+9−7
@@ -1356,8 +1356,8 @@ impl HighlightConfiguration {
1356 /// Tree-sitter syntax-highlighting queries specify highlights in the form of dot-separated
1356 /// Tree-sitter syntax-highlighting queries specify highlights in the form of dot-separated
1357 /// highlight names like `punctuation.bracket` and `function.method.builtin`. Consumers of
1357 /// highlight names like `punctuation.bracket` and `function.method.builtin`. Consumers of
1358 /// these queries can choose to recognize highlights with different levels of specificity.
1358 /// these queries can choose to recognize highlights with different levels of specificity.
1359− /// For example, the string `function.builtin` will match against `function.method.builtin`
1359+ /// For example, the string `function.builtin` will match against `function.builtin.constructor`
1360− /// and `function.builtin.constructor`, but will not match `function.method`.
1360+ /// but will not match `function.method.builtin` and `function.method`.
1361 ///
1361 ///
1362 /// When highlighting, results are returned as `Highlight` values, which contain the index
1362 /// When highlighting, results are returned as `Highlight` values, which contain the index
1363 /// of the matched highlight this list of highlight names.
1363 /// of the matched highlight this list of highlight names.
@@ -1377,11 +1377,13 @@ impl HighlightConfiguration {
1377 let recognized_name = recognized_name;
1377 let recognized_name = recognized_name;
1378 let mut len = 0;
1378 let mut len = 0;
1379 let mut matches = true;
1379 let mut matches = true;
1380− for part in recognized_name.split('.') {
1380+ for (i, part) in recognized_name.split('.').enumerate() {
1381− len += 1;
1381+ match capture_parts.get(i) {
1382− if !capture_parts.contains(&part) {
1382+ Some(capture_part) if *capture_part == part => len += 1,
1383+ _ => {
1383− matches = false;
1384+ matches = false;
1384− break;
1385+ break;
1386+ }
1385 }
1387 }
1386 }
1388 }
1387 if matches && len > best_match_len {
1389 if matches && len > best_match_len {