CodeEditApp / CodeEditSourceEditor

A code editor view written in Swift powered by tree-sitter.
https://codeeditapp.github.io/CodeEditSourceEditor/documentation/codeeditsourceeditor
MIT License
510 stars 78 forks source link

🐞 `tree-sitter` Parsing Inefficiency #143

Closed thecoolwinter closed 1 year ago

thecoolwinter commented 1 year ago

Description

SwiftTreeSitter provides a includedRanges array binding to the tree-sitter parser that would allow us to set what ranges tree-sitter acts on. Right now, tree-sitter parses the entire document when initialized. This isn't a huge problem, as it's very fast and by a quick tests parses very large files in only a few milliseconds. However, this is still a large inefficiency and something that should be implemented.

What would need to be done:

thecoolwinter commented 1 year ago

Closing this because the includedRanges parameter doesn't apply to this problem well. If we were to use it to try and make editing faster, the syntax tree tree-sitter creates will be incomplete and buggy. It will also not shrink if the includedRanges shrink, so the editing time improvement will be nonexistent for larger files where it matters.

Instead, we should look into backgrounding long edit times using the timeout parameter on parsers. Swift's async/await would be perfect here.