feat: add child combinator ">" (and fix a specificity bug)#233
Merged
Conversation
Bug: Just because a trie element exists for a more specific scope doesn‘t mean its parent scopes will match, so we need to collect the trie elements with less specific scopes too. Bug: If the number of scope names in both rules‘ scope paths are not equal, the parent scope names won‘t be compared at all. Instead, the rule with the longest scope path is preferred. This goes against the TextMate manual (https://macromates.com/manual/en/scope_selectors). In particular, the following line in “Ranking Matches”: > Rules 1 and 2 applied again to the scope selector when removing the deepest element (in the case of a tie) Feature: Add support for the child combinator (the `>` operator). This allows for styling a parent-child relationship specifically.
Contributor
Author
|
@hediet Excuse me if it's rude to tag, but I saw you're the only person to touch Test cases incoming... |
23e9193 to
0e71e37
Compare
- One for the new child combinator
- One for bug 1 ("Theme resolving falls back to less specific rules")
- One for bug 2 ("Theme resolving should give deeper scopes higher specificity")
After trying to reproduce the alleged bug, I realized it‘s not a bug. When a ThemeTrieElement is created, it inherits the `_rulesWithParentScopes` array of its parent element, which is guaranteed to be populated due to the lexicographical sorting of the theme rules in `resolveParsedThemeRules`.
…and update the other bug‘s test case to actually fail on the main branch
Contributor
Author
|
Okay tests have been added! Both fail on main branch. |
alexdima
approved these changes
Jul 6, 2024
Member
alexdima
left a comment
There was a problem hiding this comment.
This looks very good! Thank you! ❤️
bpasero
approved these changes
Jul 6, 2024
sebthom
added a commit
to sebthom/tm4e
that referenced
this pull request
Jul 6, 2024
This is ported from upstream vscode-textmate PR microsoft/vscode-textmate#233
sebthom
added a commit
to sebthom/tm4e
that referenced
this pull request
Jul 7, 2024
This is ported from upstream vscode-textmate PR microsoft/vscode-textmate#233
sebthom
added a commit
to eclipse-tm4e/tm4e
that referenced
this pull request
Jul 8, 2024
This is ported from upstream vscode-textmate PR microsoft/vscode-textmate#233
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #123
Feature: Add support for the child combinator (the
>operator). This allows for styling a parent-child relationship specifically.vscode-textmate/src/theme.ts
Lines 173 to 180 in d63ed16
vscode-textmate/src/theme.ts
Lines 526 to 532 in d63ed16
Bug: If the number of scope names in both rules‘ scope paths are not equal, the parent scope names won‘t be compared at all. Instead, the rule with the longest scope path is preferred. This goes against the TextMate manual (https://macromates.com/manual/en/scope_selectors). In particular, the following line in “Ranking Matches”:
vscode-textmate/src/theme.ts
Lines 506 to 515 in 09effd8
How did I fix it?
Do a depth-first, scope-by-scope comparison of the parent scopes, even if one of the rules has a longer scope path.
vscode-textmate/src/theme.ts
Lines 539 to 553 in 7c14889
Tests
vscode-textmate/src/tests/themes.test.ts
Line 609 in 7c14889
vscode-textmate/src/tests/themes.test.ts
Line 635 in 7c14889