Repository navigation
Fix type region ending early after ranges and missing -nominal - #20
Merged
Merged
Conversation
The type-directive end pattern `(\)?)\s*+(\.)` matched the first dot of
a range such as `1..10`, closing the meta.type.erlang region early. A
fun type after the range was then no longer covered by the function
type injection, fell through to the fun expression rules and scoped
the rest of the file as the body of a fun:
-type t() :: 1..10 | fun(() -> ok).
Only end the directive at a dot followed by whitespace, a comment or
the end of the line, which is how Erlang itself terminates a form.
Nominal types (OTP 28) were handled by the generic directive rule, so
they never got the meta.type.erlang scope. A fun type in one fell
through to the fun expression rules and scoped the rest of the file as
the body of a fun:
-nominal n() :: fun(() -> ok).
Add nominal to the directives matched by type-directive.
Member
Author
|
cc @pgourlain |
michalmuskala
approved these changes
Sep 30, 2026
meta-codesync Bot
pushed a commit
to WhatsApp/erlang-language-platform
that referenced
this pull request
Sep 30, 2026
Summary: Sync both copies of the Erlang TextMate grammar (the ELP extension and the internal `nuclide.erlang` extension) with https://github.com/erlang-ls/grammar at `49f7a9a`. Both copies now match upstream byte for byte. Changes since the last sync: - erlang-ls/grammar#19: named fun expressions (`fun Name(...) -> ... end`) are highlighted correctly, and no longer scope the rest of the file as an implicit fun. Zero-arity fun expressions such as `fun() -> ok end` are keywords instead of function types. The function type rule now only applies inside types (`-type`, `-opaque`, `-spec`, `-callback`, typed record fields), via a new `meta.type.erlang` scope. Fixes pgourlain/vscode_erlang#316 and #317. - erlang-ls/grammar#20: a fun type after a top-level range (`-type t() :: 1..10 | fun(() -> ok).`) or in a `-nominal` type no longer scopes the rest of the file as a fun expression. - erlang-ls/grammar#21: upstreams the fix for Markdown leaking out of `-doc`/`-moduledoc` attributes (D98300495), which only lived in these copies. No behaviour change here. - erlang-ls/grammar#22: follow-ups from the review of this diff. Named funs called `_` (`fun _(A) -> A end`) are highlighted as named funs. `README.md` typos fixed (`ignode`, `./test/snap`) and the snapshot update command loads the Markdown test grammar. Upstream also adds tests showing that a comma nested in a record field type does not end the `meta.type.erlang` region, and that a default value stays an expression. `README.md` is synced too (test instructions and references); `LICENSE` is unchanged. Reviewed By: jcpetruzza Differential Revision: D122532634 fbshipit-source-id: cabfee7809fcd0e0977d700bc71b8b50db8cd02f
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.
Follow-up to #19. In two cases, a fun type in a type directive falls outside the
meta.type.erlangregion, so the function type injection doesn't apply. The fun is then highlighted as a fun expression, and everything after it is highlighted as the inside of a fun, down to the end of the file:Do not end type directives at the dot of a range
The
type-directiveend pattern(\)?)\s*+(\.)matched the first.of.., which closed the region before thefun(. The directive now only ends at a dot followed by whitespace, a%comment or the end of the line, the same way Erlang ends a form. Ranges inside(),[]or{}were never affected.Treat
-nominalas a type directiveNominal types (OTP 28) went to the generic
#directiverule and never gotmeta.type.erlang.nominalis now in the list of directives thattype-directivematches.Tests
Each commit adds cases to
tests/fun_expression.erl, and each case failed before its fix. The cases check that the fun is scoped as a function type, that the directive ends at the real dot, and that the next function head is still highlighted correctly. No existing snapshot changed.