CodeEditApp / CodeEditSourceEditor

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

[chore]: Refactor to use binary framework for `tree-sitter` language grammars #86

Closed lukepistrol closed 2 years ago

lukepistrol commented 2 years ago

I finally got it working! Huge thanks to @mattmassicotte for helping me out!

This PR outsources the bundling of tree-sitter grammars to CodeEditLanguages. This hugely benefits package resolution times both in Xcode and in our CI.

What's different in CodeEditTextView?

Not much. The classes/structs TreeSitterModel & CodeLanguage now live in CodeEditLanguages. Apart from that the package works the same as before.

Background

Since we currently load each tree-sitter language as a SPM Package, and their repositories often are huge with a long git history, the resolution process for some packages takes a couple of minutes. Also all sources have to be built every time as well. Since those grammars usually don't change all that often, we can easily get away with putting them into a binary framework which eliminates both drawbacks of the current solution.

We only need to fetch the framework itself which is less than 30MB compared to ~1.4GB when fetching all the language packages on their own. Also all the C code in the language packages will be built already.

Technical Details

In CodeEditLanguages are both a SPM Package and a Xcode project. The project (CodeLanguages-Container) is only used for building a binary framework CodeLanguagesContainer.xcframework. The SPM Package CodeEditLanguages then embeds this binary and provides the classes/structs TreeSitterModel & CodeLanguage for the use in CodeEditTextView.

There are a few additional steps that need to be done when adding a new language:

After that the usual steps apply.

Related Issue