New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Tree-sitter grammars' contentRegExp work as intended #17468

merged 1 commit into from Jun 5, 2018


None yet
1 participant

maxbrunsfeld commented Jun 4, 2018

Previously, when the Use Tree Sitter Parsers setting was enabled, CoffeeScript files were accidentally highlighted as C++ because of the C++ grammar's contentRegExp.

In this PR, I have made the following adjustments to the way Tree-sitter grammar selection works:

  1. Tree-sitter grammars are never used unless the Tree-sitter setting is enabled.
  2. A grammar that matches more path components is always preferred over a grammar that matches fewer path components (or no path components). This way, .coffee files will always use CoffeeScript rather than C++.
  3. If two grammars have comparable score otherwise, contentRegExp comes into play. If a grammar's contentRegExp does match, the grammar is preferred, and if it does not match, the grammar is dispreferred. This way, .h files that do not contain 'class', 'namespace', etc, then the C grammar is explicitly preferred over the C++ grammar.
  4. Finally, if two grammars are still tied (and the Tree-sitter setting is enabled), then Tree-sitter grammars are preferred.

/cc @thomasjo

@maxbrunsfeld maxbrunsfeld merged commit ebf15ef into master Jun 5, 2018

2 of 3 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
ci/circleci Your tests passed on CircleCI!
continuous-integration/travis-ci/pr The Travis CI build passed

@maxbrunsfeld maxbrunsfeld deleted the mb-fix-content-regexes branch Jun 5, 2018

maxbrunsfeld added a commit that referenced this pull request Jun 7, 2018

Grammar scoring, weigh grammar type higher than content regex match
This fixes another regression introduces in #17468
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment