Skip to content

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

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

feat(extensions): support custom syntax grammars#683
benvinegar wants to merge 5 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
  • resolve extension-owned package imports from folder node_modules in both source and compiled Hunk builds
  • 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,962 passed, 9 skipped
  • bun run test:integration — 97 passed
  • bun run test:tty-smoke — 9 passed
  • real tmux run of the compiled binary with a folder extension dynamically importing Odin through package exports and #imports; verified package and if rendered in the extension's #ff00ff scope color
  • 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 2:02pm

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

@socket-security

socket-security Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedimport-meta-resolve@​4.2.010010010081100
Addedes-module-lexer@​1.7.010010010089100
Addedacorn@​8.15.010010010090100

View full report

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant