feat: gate language grammars behind SwiftPM package traits#7
Conversation
Each tree-sitter grammar is now an opt-in package trait instead of an unconditional dependency. Consumers who only render a few languages can disable the rest, pruning those grammar packages from resolution and compilation entirely. - Bump swift-tools-version to 6.1 (required for traits). - Add 18 traits (one per grammar package) with a default set enabling all of them, so existing consumers see no change. - Gate each tree-sitter product with `condition: .when(traits: [...])` and wrap the matching imports/registrations in CodeHighlighter with `#if`. Unregistered languages fall through to plain text via the existing `languageConfiguration(for:)` nil path. - Pin `swiftLanguageModes: [.v5]` so the tools bump doesn't also flip the package into the Swift 6 language mode. Verified: default build + full test suite pass; a `--traits Swift,JSON` build succeeds and prunes the other 16 grammar packages from the graph. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed41be8376
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @@ -1,4 +1,4 @@ | |||
| // swift-tools-version: 5.9 | |||
| // swift-tools-version: 6.1 | |||
There was a problem hiding this comment.
Update the advertised Swift requirement
Because this tools-version line makes SwiftPM 6.1 the minimum, the README Requirements section still saying Swift 5.9+ is now wrong; users on Swift 5.9 or 5.10 following the published install docs will fail while loading the manifest before they can build. Update the documented minimum/toolchain compatibility along with this manifest change.
Useful? React with 👍 / 👎.
The package now requires Swift tools 6.1 (for traits); the README still advertised 5.9+, which would fail at manifest load for users on 5.9/5.10. Also document how to select languages via package traits. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
What
Makes each tree-sitter language grammar an opt-in SwiftPM package trait instead of an unconditional dependency. Consumers who only render a handful of languages can disable the rest, pruning those grammar packages from resolution and compilation entirely.
Implements the approach from Swift package traits (SE-0450).
Why
Today every consumer of
MarkdownViewfetches, compiles, and links all 18 tree-sitter grammar packages even if they only ever highlight, say, Swift and JSON. Traits let consumers pay only for the languages they use.Changes
Package.swiftswift-tools-versionto6.1(required for traits)..defaultset enabling all of them, so existing consumers are unaffected..product(...)withcondition: .when(traits: [...]).swiftLanguageModes: [.v5]so the tools-version bump doesn't also migrate the package into the Swift 6 language mode (which would turn pre-existingLitextconcurrency warnings into hard errors — out of scope here).CodeHighlighter.swiftimport TreeSitterXand itsregister(...)block in#if <Trait>. Disabled languages are simply never registered; the existinglanguageConfiguration(for:)nil path already degrades unknown languages to plain text, so no call sites change.Consumer usage
Reviewer notes
TreeSitterTSXis not a separate product — it ships inside theTreeSitterTypeScriptproduct, so TypeScript + TSX share oneTypeScripttrait.Verification
Build complete✓, full test suite passes ✓swift build --disable-default-traits --traits Swift,JSON:Build complete✓, andshow-dependenciesconfirms onlytree-sitter-swift+tree-sitter-jsonremain — the other 16 grammar packages are pruned from the graph.🤖 Generated with Claude Code