Improve rescript-ts-mode grammar installation and font-locking#19
Open
mvaled wants to merge 7 commits intojjlee:masterfrom
Open
Improve rescript-ts-mode grammar installation and font-locking#19mvaled wants to merge 7 commits intojjlee:masterfrom
mvaled wants to merge 7 commits intojjlee:masterfrom
Conversation
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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves the experimental tree-sitter-based
rescript-ts-modein a few practical areas, and also tightens a couple of classic/tree-sitter font-lock gaps.What’s included
rescript-ts-modeis enabled and the grammar is missingrescript-ts-install-grammarandrescript-ts-diagnose-grammarhelper commandstreesit-install-language-grammarrescript-ts-modefor:list/dictbuiltins in type positions, literals, and patternsunitin type positions viaunit_typerescript-modefont-lock so:dictis highlighted likelistpromiseandresultare highlighted as builtin typesCustomization
rescript-ts-prompt-to-install-grammarrescript-ts-grammar-source-urlrescript-ts-grammar-install-directoryMotivation
Getting
rescript-ts-moderunning 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-modefeel more complete and also keeps classicrescript-modeandrescript-ts-modecloser in common builtin/type cases.Notes
rescript-ts-moderemains experimental and is still not auto-enabled by default.https://github.com/rescript-lang/tree-sitter-rescript.