vscode-textmate
vscode-textmate copied to clipboard
feat: add child combinator ">" (and fix a specificity bug)
Closes #123
-
Feature: Add support for the child combinator (the
>
operator). This allows for styling a parent-child relationship specifically.https://github.com/microsoft/vscode-textmate/blob/d63ed169dfa50fe337d6985b658103cb47829abe/src/theme.ts#L173-L180
https://github.com/microsoft/vscode-textmate/blob/d63ed169dfa50fe337d6985b658103cb47829abe/src/theme.ts#L526-L532
-
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)
https://github.com/microsoft/vscode-textmate/blob/09effd8b7429b71010e0fa34ea2e16e622692946/src/theme.ts#L506-L515
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.https://github.com/microsoft/vscode-textmate/blob/7c14889ce5b178313f13bc0ef1d1e06d3541ffcc/src/theme.ts#L539-L553
Tests
- Child combinators https://github.com/microsoft/vscode-textmate/blob/7c14889ce5b178313f13bc0ef1d1e06d3541ffcc/src/tests/themes.test.ts#L609
- Bug https://github.com/microsoft/vscode-textmate/blob/7c14889ce5b178313f13bc0ef1d1e06d3541ffcc/src/tests/themes.test.ts#L635