Skip to content

Support OCaml, Erlang and F# properly - #2138

Merged
bbatsov merged 1 commit into
masterfrom
feature/ocaml-erlang-fsharp
Jul 28, 2026
Merged

Support OCaml, Erlang and F# properly#2138
bbatsov merged 1 commit into
masterfrom
feature/ocaml-erlang-fsharp

Conversation

@bbatsov

@bbatsov bbatsov commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Test-at-point rules for erlang-ts-mode and fsharp-ts-mode, plus fuller
project types for all three languages.

Both rules are written against the real grammars, not inferred: the F#
grammar was already installed here, and I installed the Erlang one and parsed
sample sources for both. That's how the F# rule got right that attributes is a
positional sibling of the definition under the enclosing
declaration_expression, rather than a field of it - my first attempt used
treesit-node-child-by-field-name and silently matched nothing.

It also turned up a latent trap in the Rust and Java rules from #2136. Both
tested for their attribute with \_</\_>, which consult the buffer's syntax
table - and under it the < and > of F#'s [<Fact>] count as part of the
symbol, so the boundary never matches. It happened to work for #[test] and
@Test. All three now share one syntax-independent check, with specs for the
bracket forms and for not matching [<Factory>] when looking for Fact.

Erlang addresses a test as module:function and an Erlang module is named after
its file, so the module comes from the file name. F# unwraps a name written
between double backticks, which is how F# tests usually get readable names, and
filters with FullyQualifiedName~ so the filter works without the namespace.

OCaml gets no test-at-point rule, deliberately. Its tests are ordinary values
handed to Alcotest or OUnit - nothing in the syntax marks one out, and dune runtest runs the lot - so any rule would be guesswork dressed up as support.
The effort went into its project type instead: dune exec, dune install,
dune build @install and the source/test directories. rebar gained the same
treatment, and erlang-mk is a new type for the other common Erlang build tool.

Erlang and F# get test-at-point rules, both written against the real
grammars rather than guessed at: I installed the Erlang grammar and
parsed sample sources for both, which is how the F# rule got right that
the attributes are a positional sibling of the definition rather than a
field of it.

That also turned up a latent trap in the Rust and Java rules I added
earlier: they tested for an attribute with the symbol-boundary
operators, which consult the syntax table. Under it the angle brackets
of F#'s [<Fact>] count as part of the symbol, so the boundary never
matches. All three now share one syntax-independent check.

OCaml gets no test-at-point rule on purpose. Its tests are ordinary
values handed to Alcotest or OUnit, with nothing in the syntax marking
one out, so any rule would be guesswork. Its project type gets the
attention instead - as do Erlang's, plus a new erlang-mk type.
@bbatsov
bbatsov merged commit 54a3d85 into master Jul 28, 2026
10 checks passed
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