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

@ -1,7 +1,10 @@
/// What the compiler offers to write, from a file's last check: the clauses a
/// match lacks, and what could fill a hole. The compiler hands them to
/// `Exhaustiveness.observe` and `Holes.observe` as it refuses the code, so
/// they cost nothing beyond the check.
/// match lacks, what could fill a hole, and the signature of a function that
/// has none. The compiler hands them to `Exhaustiveness.observe`,
/// `Holes.observe` and `CheckDecl.observeMissingSignature` as it refuses the
/// code. The first two cost nothing beyond the check. For the third, the
/// compiler checks the body of each function that has no signature, which it
/// does not do with no observer.
module BjolangLsp.Fixes
open System.IO
@ -10,9 +13,10 @@ open Bjolang.Lexer
type Facts =
{ Missing: Exhaustiveness.MissingClauses list
Holes: Holes.Fillers list }
Holes: Holes.Fillers list
Signatures: CheckDecl.MissingSignature list }
let private none = { Missing = []; Holes = [] }
let private none = { Missing = []; Holes = []; Signatures = [] }
let private byFile = System.Collections.Generic.Dictionary<string, Facts>()
@ -23,18 +27,22 @@ let recording (path: string) (check: unit -> 'a) : 'a =
let inFile (r: Range) = r.File <> "" && Path.GetFullPath r.File = full
let missing = ResizeArray<Exhaustiveness.MissingClauses>()
let holes = ResizeArray<Holes.Fillers>()
let signatures = ResizeArray<CheckDecl.MissingSignature>()
Exhaustiveness.observe <- Some(fun m -> if inFile m.Range then missing.Add m)
Holes.observe <- Some(fun h -> if inFile h.Range then holes.Add h)
CheckDecl.observeMissingSignature <- Some(fun s -> if inFile s.Range then signatures.Add s)
try
check ()
finally
Exhaustiveness.observe <- None
Holes.observe <- None
CheckDecl.observeMissingSignature <- None
byFile[full] <-
{ Missing = missing |> Seq.distinctBy (fun m -> m.Range) |> List.ofSeq
Holes = holes |> Seq.distinctBy (fun h -> h.Range) |> List.ofSeq }
Holes = holes |> Seq.distinctBy (fun h -> h.Range) |> List.ofSeq
Signatures = signatures |> Seq.distinctBy (fun s -> s.Range) |> List.ofSeq }
/// The facts of `path`'s last check.
let ofFile (path: string) : Facts =