Hover on fields, and on locals of record types

A field read shows the field's type and its declaration; a local of a
record, struct or union type shows the type. Structs and opaque types get
their symbols, and the file's own types drop their module qualifier.
This commit is contained in:
Linus Björnstam 2026-11-03 14:45:55 +01:00
parent 29977ca301
commit 78d18c9854
6 changed files with 166 additions and 11 deletions

View file

@ -313,6 +313,31 @@ let builtin (name: string) : string option =
yield "*Built into the compiler.*" ]
|> String.concat "\n\n")
/// The hover for a field read, `(.x r)`: the field's type at this read, the
/// field as its type declares it, with its doc, and whose field it is.
/// `declared` is the record's or struct's definition, if it is found.
let field (name: string) (t: string) (record: string) (declared: Found option) : string =
let declaredField =
declared
|> Option.bind (fun d ->
d.Symbol.Children
|> List.tryFind (fun c -> c.Name = name)
|> Option.map (fun c -> { d with Symbol = c }))
let file =
declared
|> Option.map (fun d -> $", in %s{IO.Path.GetFileName d.Symbol.NameRange.File}")
|> Option.defaultValue ""
[ yield fence $"(: .%s{name} %s{t})"
match declaredField with
| Some f ->
yield fence (clip (f.Module.Slice f.Symbol.Signature))
yield! Option.toList (doc f)
| None -> ()
yield $"*A field of `%s{record}`%s{file}.*" ]
|> String.concat "\n\n"
/// The hover for `found`: its signature, where it is, and its doc.
let text (found: Found) (inferred: string option) : string =
let where =