Signature help, formatting, and a fix that writes a missing signature

- textDocument/signatureHelp: the function whose call the cursor is in,
  with the parameter that is being written marked. A definition shows its
  head as written; an import, a trait's method and a builtin show their
  type. It reads tokens as far as the cursor, so a call that is not closed
  has help.
- textDocument/formatting: the whole text as bjo fmt lays it out. The
  server runs bjo -q fmt - on the buffer's text.
- A quick fix at a function with no signature writes the one its body
  gives it, on a line above the definition
  (CheckDecl.observeMissingSignature, in the compiler).
- The server says version 0.8.0.

Needs the compiler at its commit "CheckDecl.observeMissingSignature".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-11-25 08:01:34 +01:00
parent d421ec9363
commit ce426b94df
8 changed files with 695 additions and 11 deletions

View file

@ -57,6 +57,22 @@ their own below; besides those, it does these:
so `string->` is one. Its doc is the hover's, sent along for a local and
when the client asks for anything else (`completionItem/resolve`).
Nothing is offered in a comment or a string.
- Signature help (`textDocument/signatureHelp`): the function whose call
the cursor is in, with the parameter that is being written marked. A
definition shows its head as written, `(area width height #:scale 1)`,
with its declaration and doc under it; an import of a .NET member, a
method of a trait and a builtin show their type. A keyword argument marks
its own parameter, at the keyword and at its value, and an argument past
the positional ones marks a `#:rest` parameter. The function is the
innermost form around the cursor whose head is a function the file sees,
so an argument written inside an `if` or a `let` has the help of the call
around it. It reads the text as tokens as far as the cursor, so a call
that is not closed has help.
- Formatting (`textDocument/formatting`): the whole text as `bjo fmt` lays
it out, which is as `bjo-mode` indents it. The server runs `bjo fmt -` on
the buffer's text. A text that does not read is refused, with what
`bjo fmt` says of it. The editor's tab size and other options are not
read: the layout is the one layout.
And one request of its own, `bjolang/expandMacro`: the expansion of the
macro call at a position, one step or all the way down, from the last check
@ -152,9 +168,10 @@ special form.
## Code actions
`textDocument/codeAction` offers two kinds of quick fix, both worked out by
the compiler while it checks and handed over through
`Exhaustiveness.observe` and `Holes.observe` (`Fixes.fs`):
`textDocument/codeAction` offers three kinds of quick fix, each worked out
by the compiler while it checks and handed over through
`Exhaustiveness.observe`, `Holes.observe` and
`CheckDecl.observeMissingSignature` (`Fixes.fs`):
- At a match that does not cover every value: add the clauses it lacks,
after its last clause and lined up with it, each with a hole for its
@ -168,6 +185,15 @@ the compiler while it checks and handed over through
type, with holes for what it takes, `(Circle _)`, or a record with each of
its fields; or, for a function type, with `(fun (x y) _)`.
- At a function of the module that has no signature, on the line its
definition starts: write the signature that its body gives it, on a line
of its own above the definition, `(: (-> int (#:prefix string) string))`.
A type variable that inference made is written `%a`, `%b`. The compiler
refuses such a function before it checks its body; for the server it
checks the body too, so a body that does not check has no signature to
offer, and a check of a file with such functions does that much more
work.
A hole in what was written is a new hole for the next check, so a fix is a
step: the clauses' bodies are holes, and each says what it has to be. The
actions are of the file's last check, which a check that is due replaces
@ -281,6 +307,8 @@ With eglot instead:
- Hover for a special form (`record-ref`, `loop`, `match`), which has no
definition to find and no doc.
- The type of an expression that is not a name.
- Signature help for a local function, a constructor or a macro.
- Formatting of a part of a file (`textDocument/rangeFormatting`).
- Completion of record fields after `record-ref`, of module paths in an
`import`, or of keyword arguments. A string that began on an earlier line
is not seen as one, so a multi-line string gets completions.