Skip to content
← Back

src/analysis/signature_doc.ghul

1
namespace Analysis is
2
use IoC
3
use Ghul.Disposable
4
5
use Semantic.Symbols.SignaturePart
6
7
use Syntax.Process.Printer.SIGNATURE_RENDERER
8
9
// Renders a symbol's declaration head against a column budget by
10
// walking the SignaturePart tree that `Symbol.describe(context)`
11
// produces. The layout work lives in SIGNATURE_RENDERER (shared with
12
// the narrowing-inlay type renderer); this adds the hover-specific
13
// step of turning a HOVER_USE into that tree and rendering it relative
14
// to the use's scope.
15
//
16
// Variable uses carry their observed (narrowed) type through the
17
// context so a hover on a narrowed variable shows the narrowed shape.
18
class SIGNATURE_DOC is
19
// Column budget for hover signatures. Narrow enough that a
20
// long-parameter method wraps in a typical VS Code hover
21
// popover; wide enough that short signatures do not break
22
// gratuitously.
23
DEFAULT_WIDTH: int static => 60
24
25
build(hover: Semantic.HOVER_USE) -> string static =>
26
build(hover, DEFAULT_WIDTH)
27
28
build(hover: Semantic.HOVER_USE, width: int) -> string static is
29
let context = hover.context()
30
let s = hover.symbol.collapse_group_if_single_member()
31
let part = s.describe(context)
32
33
// Render names relative to the scope the use was recorded in,
34
// so a type keeps only the qualification it needs from where
35
// the reader's cursor is.
36
let use render_scope = IoC.CONTAINER.instance.name_display.with_scope(hover.scope)
37
38
return SIGNATURE_RENDERER.render(part, width)
39
si
40
41
// Render an arbitrary part directly — used by unit tests to pin
42
// the layout without constructing a Symbol fixture.
43
render(part: SignaturePart, width: int) -> string static =>
44
SIGNATURE_RENDERER.render(part, width)
45
si
46
si