Skip to content

Improve rescript-ts-mode grammar installation and font-locking#19

Open
mvaled wants to merge 7 commits intojjlee:masterfrom
mvaled:master
Open

Improve rescript-ts-mode grammar installation and font-locking#19
mvaled wants to merge 7 commits intojjlee:masterfrom
mvaled:master

Conversation

@mvaled
Copy link
Copy Markdown
Contributor

@mvaled mvaled commented Apr 10, 2026

This PR improves the experimental tree-sitter-based rescript-ts-mode in a few practical areas, and also tightens a couple of classic/tree-sitter font-lock gaps.

What’s included

  • add built-in support for installing the ReScript tree-sitter grammar
  • prompt interactively to install the grammar when rescript-ts-mode is enabled and the grammar is missing
  • add rescript-ts-install-grammar and rescript-ts-diagnose-grammar helper commands
  • register the grammar source in a more robust way and fix the upstream grammar URL
  • ensure the install directory exists before invoking treesit-install-language-grammar
  • improve font-lock in rescript-ts-mode for:
    • labeled parameters
    • list / dict builtins in type positions, literals, and patterns
    • unit in type positions via unit_type
    • regex nodes as strings
  • align classic rescript-mode font-lock so:
    • dict is highlighted like list
    • promise and result are highlighted as builtin types

Customization

  • rescript-ts-prompt-to-install-grammar
  • rescript-ts-grammar-source-url
  • rescript-ts-grammar-install-directory

Motivation

Getting rescript-ts-mode running currently requires some manual tree-sitter setup, and when the grammar is missing the failure mode is not very friendly. This change makes the mode easier to try out by providing an installation flow directly from Emacs, along with a diagnosis command for troubleshooting.

On the highlighting side, this makes rescript-ts-mode feel more complete and also keeps classic rescript-mode and rescript-ts-mode closer in common builtin/type cases.

Notes

  • rescript-ts-mode remains experimental and is still not auto-enabled by default.
  • This PR fixes the grammar source to use https://github.com/rescript-lang/tree-sitter-rescript.

mvaled added 6 commits April 10, 2026 13:21
Teach rescript-ts-mode to register the upstream ReScript tree-sitter grammar,
prompt to install it when the mode is enabled interactively, and provide
helper commands for installation and diagnosis.

Update the README to document the tree-sitter mode, its installation flow,
and the new customization points. Also highlight regex nodes in the
string font-lock feature.
Teach classic `rescript-mode` to treat `dict` the same way as `list` in
both type annotations and collection literals.

Update `rescript-ts-mode` to apply `font-lock-builtin-face`
consistently to `list` and `dict` in type positions, literals, and
patterns so both modes present the same builtin collection styling.
Add tree-sitter font-lock rules for labeled parameters so argument names
are highlighted consistently in function signatures and function values.
Bring `rescript-ts-mode` closer to the upstream `highlights.scm`
where it improves the editing experience while keeping a
conservative Emacs face mapping.

This updates font-lock for:
- record/dict/object property keys
- parameter coverage, including labeled, no-parens, and destructuring forms
- variant/polyvar constructor coverage
- `%re(...)` and literal regexes
- JSX tags, delimiters, and attributes
- extension syntax highlighting for `%...`

Faces used by `rescript-ts-mode` after this change:

| Face                           | Role |
|--------------------------------|------|
| font-lock-comment-face         | comments |
| font-lock-string-face          | strings, template strings, characters |
| font-lock-regexp-face          | literal regexes and `%re(...)` payloads |
| font-lock-keyword-face         | keywords and extension syntax like `%re` |
| font-lock-builtin-face         | builtin collections and `unit_type` |
| font-lock-number-face          | numbers |
| font-lock-constant-face        | booleans and `unit` |
| font-lock-type-face            | types, constructors, JSX tag names |
| font-lock-function-name-face   | function bindings |
| font-lock-function-call-face   | function calls |
| font-lock-variable-name-face   | parameters and other binding-style names |
| font-lock-property-name-face   | record/dict/object property keys |
| font-lock-preprocessor-face    | decorators |
| font-lock-operator-face        | operators |
| font-lock-escape-face          | escape sequences |
| font-lock-bracket-face         | JSX delimiters |
| rescript-ts-jsx-attribute-face | JSX attribute names |

`rescript-ts-jsx-attribute-face` inherits from
`font-lock-variable-name-face`.
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