Skip to content
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

Find brackets to highlight using the Tree-sitter syntax tree #367

merged 5 commits into from Nov 20, 2018


Copy link

@maxbrunsfeld maxbrunsfeld commented Nov 16, 2018

Description of the Change

Currently, this package finds matching brackets by performing a regex search and keeping track of the nesting level of bracket characters. The code for finding matching HTML tags is even more complicated.

In this PR, I've updated the package to find matching tokens using syntax trees provided by Tree-sitter, when they are available.


The performance of bracket matching is vastly improved. Here's a flame graph that I recorded in the current version of Atom when moving the cursor across this opening parenthesis in Atom's text-editor-component-spec.js.

screen shot 2018-11-16 at 2 46 03 pm

This operation took 300ms.

Here's a flame graph that I recorded of the same operation with this fix:

screen shot 2018-11-16 at 3 08 30 pm

The operation now takes 0.75ms; the syntax tree makes the operation basically free.

Possible Drawbacks

This improvement only takes effect for languages with Tree-sitter parsers.

Applicable Issues

Fixes #348
Fixes #355

@maxbrunsfeld maxbrunsfeld force-pushed the mb-use-syntax-tree branch from 65e1dd1 to a38dc3f Nov 16, 2018
if (startRange && endRange) return {startRange, endRange}

This comment has been minimized.


maxbrunsfeld Nov 17, 2018
Author Contributor

This one method takes the place of the the TagFinder class.

@maxbrunsfeld maxbrunsfeld merged commit f29f0ef into master Nov 20, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
@maxbrunsfeld maxbrunsfeld deleted the mb-use-syntax-tree branch Nov 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.