CodeEditApp / CodeEditSourceEditor

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

Async TreeSitterClient #191

Closed thecoolwinter closed 1 year ago

thecoolwinter commented 1 year ago

Description

Modifies TreeSitterClient to support doing work on a background thread when doing so is beneficial. This allows the editor to display content while languages load, scroll smoothly while highlight queries perform in the background, and on large documents perform edits asynchronously to keep UI responsive.

Edits and highlights are only queued for background work when:

Changes:

Related Issues

Checklist

Screenshots

Async language loading. Swift has a terrible initial loading time and this recording shows that the document now opens instantly but performs the initial work on a background thread. Note that this initial loading time is nearly nonexistent in subsequent document loads due to the queries being cached.

Previously, this would have blocked the main thread for the entire duration of the language load (up to 5s in my testing).

https://github.com/CodeEditApp/CodeEditTextView/assets/35942988/d7feb9ae-0846-4ad3-8598-17f7b6d753e0

Async highlighting means extremely long documents can load and highlight without affecting displaying and scrolling. This is still slightly "hitch"-y due to NSTextStorage performance when applying highlight data to the text view.

https://github.com/CodeEditApp/CodeEditTextView/assets/35942988/affcaf41-d9db-4210-80f1-cb972c5060f2