feat(extensions): register custom syntax grammars - #683
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThe PR adds extension API v3 support for lazily registered Shiki/TextMate syntax grammars and reconciles extension-provided file-language mappings across reloads.
Confidence Score: 5/5The PR appears safe to merge; no concrete, changed-code-triggered defect remains. The registration, application, fallback, cache invalidation, packaging, and public API paths are coordinated and covered by focused tests, with no established blocking or non-blocking failure. Important Files Changed
Sequence DiagramsequenceDiagram
participant E as Extension
participant R as Extension Registry
participant A as Apply Boundary
participant P as Pierre
participant U as Diff UI
E->>R: registerSyntaxLanguage(id, loader)
E->>R: registerFileLanguage(extension, id)
A->>P: register lazy grammar loader
A->>P: replace file-language mappings
U->>P: prepare shared highlighter
P->>E: invoke loader on first use
alt grammar succeeds
P-->>U: highlighted diff
else grammar fails
U->>P: dispose shared highlighter
U->>P: prepare plaintext highlighter
P-->>U: plaintext diff
end
Reviews (1): Last reviewed commit: "feat(extensions): support custom syntax ..." | Re-trigger Greptile |
52d7e21 to
8b3e979
Compare
8b3e979 to
926bebb
Compare
|
Archlang is a made-up language that usefully dogfoods the API, but it only proves that a small grammar we authored alongside the feature works. Before merge, we should also exercise an established third-party TextMate grammar against a representative source file. That would test compatibility with real grammar shapes, repositories, captures, and regex patterns rather than only our controlled fixture. I suggest keeping the self-contained Archlang example for documentation, while adding a test fixture based on a real non-bundled language grammar with its license/provenance recorded. The test should verify registration, TextMate grammars being regex-driven is normal for Shiki: they conventionally use This comment was generated by Pi using gpt-5.6-sol |
Problem
Extensions can associate files with languages that Hunk already knows, but cannot provide a grammar for a new DSL or proprietary language. Mapping
.archtoarchlang, for example, currently leaves the highlighter with an unknown language.Approach
hunk.registerSyntaxGrammar(...)for bounded, data-only TextMate grammarsregisterFileLanguageImportant boundaries
Why TextMate grammar data
Pierre uses Shiki for lexical syntax highlighting, and Shiki consumes TextMate grammars evaluated with Oniguruma-compatible regex semantics. This API exposes a bounded, data-only subset of that existing format rather than introducing a Hunk-specific grammar system. Token scopes remain compatible with existing Shiki themes through hierarchical names such as
keyword.control.archlang.Benefits
Costs and limitations
For existing bundled languages and themes, tokenization and theme resolution are unchanged. The expected steady-state overhead is limited to the precomputed digest in cache identity; no benchmark has yet quantified the one-time first-worker handshake against
main.Validation
bun run typecheckbun run test— 2,134 passed, 3 skippedbun run test:integration— 139 passed, 1 skippedbun run test:tty-smoke— 9 passedbun run lintbun run deps:checkbun run check:docsbun run website:checkbun run build:npmbun run check:packbun run changeset:statusgit diff --check origin/main...HEADReview
An independent code review found and drove fixes for worker incompatibility, current API drift, retired-loader authority, reload rollback, generator idempotence, and prototype-inherited local includes. Final review accepted the updated implementation with no blockers.
Platforms directly tested: Linux. Windows compiled fallback behavior is covered by predicates/tests but was not exercised on a real Windows standalone binary in this pass.
This PR description was generated by Pi using gpt-5.6-sol