fix(theme/#1933): Scope matching precedence #2301
Merged
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.
Issue: Our scope-selection strategy was not correct in some cases - particularly, the precedence in which we would apply the scopes.
For example, in #1933 - with the dracula theme - there'd be a case where a token would have the following textmate scopes:
support.function.console.js
meta.function-call.js
source.js
For the dracula theme, there is a
source
selector that is intended to be a fallback - however, it was taking precedence over some of the other theme selectors that should've been applied, likemeta.function-call
.This would cause the entire source file to be highlighted with the
source
scope selector, instead of the more specific ones.Defect: We apply selectors in reverse order (first, we apply any selectors matching
source.js
, and thenmeta.function-call.js source.js
, etc...) - this gives us right precedence. However, if we had a match, we were failing to 'fall-back' to a more specific selector.Fix: Add a test case to reproduce, and fall back to override with more specific scopes.
This looks to fix a couple of related issues:
tsx
files #2006 - incorrect syntax highlighting for tsx filesThanks @CrossR for the helpful tool improvements in #2255 and @thismat for the investigation to narrow down the issue in #1933 !
dracula
theme - before:dracula
theme - after: