Skip to content

feat(extensions): support custom syntax grammars - #683

Open
benvinegar wants to merge 2 commits into
mainfrom
feat/extension-syntax-languages
Open

feat(extensions): support custom syntax grammars#683
benvinegar wants to merge 2 commits into
mainfrom
feat/extension-syntax-languages

Conversation

@benvinegar

@benvinegar benvinegar commented Aug 8, 2026

Copy link
Copy Markdown
Member

Summary

  • add API v3 hunk.registerSyntaxLanguage(language, loader) for lazy Shiki/TextMate grammar modules
  • keep file associations in registerFileLanguage, reconcile them across reloads, and invalidate cached highlights when the detected language changes
  • bound stalled grammar loaders, recover Pierre's shared highlighter safely, and retry transient plaintext fallbacks without poisoning other languages
  • document the extension contract and add a minor changeset

This extracts the reusable extension capability needed by #530 so Odin support can remain a separate language contribution.

Validation

  • bun run typecheck
  • bun run test — 1,959 passed, 9 skipped
  • bun run test:integration — 97 passed
  • bun run test:tty-smoke — 9 passed
  • real PTY smoke run on a TypeScript file-pair diff
  • bun run lint
  • bun run format:check
  • bun run check:docs
  • bun run website:check
  • bun run build:npm
  • bun run check:pack
  • bun run changeset:status

This PR description was generated by Pi using gpt-5.6-sol

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hunk-web Ready Ready Preview Aug 8, 2026 6:41am

Request Review

@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR adds extension API v3 support for lazily registered Shiki/TextMate syntax grammars and reconciles extension-provided file-language mappings across reloads.

  • Adds syntax-language registration, validation, ownership, conflict handling, and attributed failure reporting.
  • Serializes shared-highlighter lifecycle work and restores plaintext highlighting after grammar failures.
  • Includes detected language in highlight cache identity.
  • Updates extension declarations, package validation, tests, documentation, and release metadata.

Confidence Score: 5/5

The 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

Filename Overview
src/extensions/apply.ts Applies lazy syntax-language registrations with ownership checks, validation, idempotent reload behavior, and attributed errors.
src/core/fileLanguage.ts Integrates Pierre’s custom grammar and replaceable extension-mapping registries while preserving Hunk’s built-in mappings.
src/extensions/runExtension.ts Adds validated syntax registration to the extension API and includes it in factory rollback and sealing behavior.
src/ui/diff/pierre.ts Serializes complete highlighter lifecycles and resets the shared highlighter before falling back to plaintext after failures.
src/ui/diff/useHighlightedDiff.ts Adds the detected file language to highlight cache keys so language changes produce fresh results.
src/extension-api/types.ts Advances the public contract to API v3 and exposes import-free grammar and loader types.
scripts/check-pack.ts Exercises the new public API in package checks and guards declarations against both static and dynamic imports.

Sequence Diagram

sequenceDiagram
  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
Loading

Reviews (1): Last reviewed commit: "feat(extensions): support custom syntax ..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant